<span id="Label3"></p><p><p><strong>first, Introduction</strong></p></p><p><p>* Using localization features, You can easily translate applications into multiple languages and even translate them into multiple dialects in the same language</p></p><p><p>* If you want to add localization functionality, you need to create a subdirectory for each supported language, called a "localized folder," usually using The. lproj as an extension</p></p><p><p>* When a localized application needs to load a resource, like, attribute list, nib file, The application examines the User's language and region, and looks for a matching localized folder. If the corresponding folder is found, the resources in this folder will be loaded</p></p><p><p></p></p><p><p><strong>second, the default</strong></p></p><p><p>Project directory Structure</p></p><p><p></p></p><p><p></p></p><p><p>Run (because the localization feature is not used, so the effect is the same regardless of what locale the user chooses)</p></p><p><p></p></p><p><p></p></p><p><p>Now I want to change another set of implementations in the Chinese language environment, including:</p></p><p><p>* Change the text in the nib file (nib Localization)</p></p><p><p>* Change the login button below picture (image Localization)</p></p><p><p>* Change the text in the dialog box (tip and Ok) (string Localization)</p></p><p><p>* Change app name (app name localization, i.e. localized info.plist File)</p></p><p><p></p></p><p><p><strong>Iii. pre-localization Preparation</strong></p></p><p><p>The first is to create a localized folder (zh-hans.lproj) in Chinese to allow the application to support the Chinese language environment</p></p><p><p></p></p><p><p></p></p><p><p>Select the resources that you currently need to localize</p></p><p><p></p></p><p><p></p></p><p><p>After selecting finish, you will find that there is a Chinese localized folder zh-hans.lproj on the hard disk, and the En.lproj folder is a localized folder in english, which is available by default when creating a Project.</p></p><p><p></p></p><p><p></p></p><p><p>The Mjviewcontroller.xib and infoplist.strings files in the project have more than one expandable triangle on the left, and you can find files with 2 versions respectively.</p></p><p><p></p></p><p><p></p></p><p><p>Mjviewcontroller.xib (中文版) for mjviewcontroller.xib files in the En.lproj folder</p></p><p><p>Infoplist.strings (中文版) for infoplist.strings files in the En.lproj folder</p></p><p><p>Mjviewcontroller.xib (chinese) corresponds to mjviewcontroller.xib file in Zh-hans.lproj folder</p></p><p><p>Infoplist.strings (chinese) corresponds to infoplist.strings file in Zh-hans.lproj folder</p></p><p><p></p></p><p><p>Once you're done, You're ready to start localizing.</p></p><p><p></p></p><p><p><strong>Iv. Localization of NIB files</strong></p></p><p><p>Open Mjviewcontroller.xib (chinese) file, Modify the text information inside (this does not modify the Picture)</p></p><p><p></p></p><p><p><strong></strong></p></p><p><p><strong>V. Application name localization (info.plist Localization)</strong></p></p><p><p>Knowledge background: a key called Cfbundledisplayname in Info.plist determines the name of the application</p></p><p><p>1. Add a key-value for info.plist, let the application support name localization, info.plist will go infoplist.strings load cfbundledisplayname corresponding string</p></p><p><p></p></p><p><p></p></p><p><p>2. In the infoplist.strings (中文版) file, add:</p></p><p><p></p></p><strong><strong>[java]</strong></strong>View Plaincopy<object id="ZeroClipboardMovie_1" width="18" height="18" align="middle" bgcolor="#ffffff" data="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" type="application/x-shockwave-flash"><object id="ZeroClipboardMovie_1" width="18" height="18" align="middle" bgcolor="#ffffff" data="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" type="application/x-shockwave-flash"><param name="src" value="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf"><param name="loop" value="loop"><param name="menu" value="false"><param name="quality" value="best"><param name="allowscriptaccess" value="always"><param name="allowfullscreen" value="false"><param name="pluginspage" value="http://www.macromedia.com/go/getflashplayer"><param name="flashvars" value="id=1&width=18&height=18"><param name="wmode" value="transparent"></object></object> <ol class="dp-j" start="1"> <ol class="dp-j" start="1"> <li class="alt">Cfbundledisplayname=<span class="string">"Localization"; </span></li> </ol> </ol><p><p></p></p><p><p></p></p><p><p>3. In the infoplist.strings (chinese) file, add:</p></p><p><p></p></p><strong><strong>[java]</strong></strong>View Plaincopy<object id="ZeroClipboardMovie_2" width="18" height="18" align="middle" bgcolor="#ffffff" data="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" type="application/x-shockwave-flash"><object id="ZeroClipboardMovie_2" width="18" height="18" align="middle" bgcolor="#ffffff" data="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" type="application/x-shockwave-flash"><param name="src" value="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf"><param name="loop" value="loop"><param name="menu" value="false"><param name="quality" value="best"><param name="allowscriptaccess" value="always"><param name="allowfullscreen" value="false"><param name="pluginspage" value="http://www.macromedia.com/go/getflashplayer"><param name="flashvars" value="id=2&width=18&height=18"><param name="wmode" value="transparent"></object></object> <ol class="dp-j" start="1"> <ol class="dp-j" start="1"> <li class="alt">Cfbundledisplayname=<span class="string">"localization"; </span></li> </ol> </ol><p><p></p></p><p><p></p></p><p><p><strong>Vi. Localization of images</strong></p></p><p><p>(here are the pictures of the house under the login button in the localization home.png,nib File)</p></p><p><p>1. Click to select home.png, and then view the view in the upper right corner</p></p><p><p></p></p><p><p></p></p><p><p>2. Select the Localize representative will add home.png to the English localization folder En.lproj</p></p><p><p></p></p><p><p></p></p><p><p>3. Add image Support Chinese language</p></p><p><p></p></p><p><p></p></p><p><p>4. View the home.png in the hard drive</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p>5. and the home.png on the left side of the project is an expandable triangle that expands to discover 2 versions of the file</p></p><p><p></p></p><p><p>Home.png (中文版) for home.png files in the En.lproj folder</p></p><p><p>Home.png (chinese) corresponds to home.png file in Zh-hans.lproj folder</p></p><p><p></p></p><p><p>6. Replace the Home.png in the Zh-hans.lproj folder with another picture that is prepared beforehand</p></p><p><p></p></p><p><p></p></p><p><p>7. View Home.png in the project after replacement</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p>8. Use the picture as usual in your code</p></p><p><p></p></p><strong><strong>[java]</strong></strong>View Plaincopy<object id="ZeroClipboardMovie_3" width="18" height="18" align="middle" bgcolor="#ffffff" data="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" type="application/x-shockwave-flash"><object id="ZeroClipboardMovie_3" width="18" height="18" align="middle" bgcolor="#ffffff" data="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" type="application/x-shockwave-flash"><param name="src" value="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf"><param name="loop" value="loop"><param name="menu" value="false"><param name="quality" value="best"><param name="allowscriptaccess" value="always"><param name="allowfullscreen" value="false"><param name="pluginspage" value="http://www.macromedia.com/go/getflashplayer"><param name="flashvars" value="id=3&width=18&height=18"><param name="wmode" value="transparent"></object></object> <ol class="dp-j" start="1"> <ol class="dp-j" start="1"> <li class="alt">[UIImage imagenamed:@<span class="string">"home.png"]; </span></li> </ol> </ol><p><p>Note: after localizing the picture file, remember to clean the project, and it is best to remove the application before reinstalling</p></p><p><p></p></p><p><p></p></p><p><p><strong>Vii. Localization of strings</strong></p></p><p><p>1. Create a string resource file</p></p><p><p></p></p><p><p></p></p><p><p>2. The file name is preferably localizable.strings, and if you use a different file name, the call to use the string is somewhat different</p></p><p><p></p></p><p><p></p></p><p><p>3. Add multilanguage support for Localizable.strings (similar to the image localization above), check the localizable.strings file to see the view in the upper right corner</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p>4. Select the Localize representative will add localizable.strings to the English localization folder En.lproj</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p>5. Add Support Chinese language</p></p><p><p></p></p><p><p></p></p><p><p>6. View the localizable.strings in the hard drive</p></p><p><p></p></p><p><p></p></p><p><p>7. and the localizable.strings on the left side of the project is an expandable triangle that expands to discover 2 versions of the file</p></p><p><p></p></p><p><p></p></p><p><p>Localizable.strings (中文版) for localizable.strings files in the En.lproj folder</p></p><p><p>Localizable.strings (chinese) corresponds to localizable.strings file in Zh-hans.lproj folder</p></p><p><p></p></p><p><p><span style="font-family: ‘Courier New‘; font-size: medium;">8. in <span style="font-size: medium;"><span style="font-family: ‘Courier New‘;"><span style="font-family: ‘Courier New‘; font-size: medium;"><span style="font-size: medium;">localizable.strings</span></span></span></span> </span> (中文版) to add the File:</p></p><p><p></p></p><strong><strong>[java]</strong></strong>View Plaincopy<object id="ZeroClipboardMovie_4" width="18" height="18" align="middle" bgcolor="#ffffff" data="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" type="application/x-shockwave-flash"><object id="ZeroClipboardMovie_4" width="18" height="18" align="middle" bgcolor="#ffffff" data="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" type="application/x-shockwave-flash"><param name="src" value="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf"><param name="loop" value="loop"><param name="menu" value="false"><param name="quality" value="best"><param name="allowscriptaccess" value="always"><param name="allowfullscreen" value="false"><param name="pluginspage" value="http://www.macromedia.com/go/getflashplayer"><param name="flashvars" value="id=4&width=18&height=18"><param name="wmode" value="transparent"></object></object> <ol class="dp-j" start="1"> <ol class="dp-j" start="1"> <li class="alt">tip=<span class="string">"Tip"; </span></li> <li></li> <li class="alt">ok=<span class="string">"ok"; </span></li> </ol> </ol><p><p></p></p><p><p></p></p><p><p><span style="font-family: ‘Courier New‘; font-size: medium;">9. <span style="font-size: medium;"><span style="font-family: ‘Courier New‘;"><span style="font-family: ‘Courier New‘; font-size: medium;"><span style="font-size: medium;"><span style="font-family: ‘Courier New‘; font-size: medium;"><span style="font-family: ‘Courier New‘; font-size: medium;">in <span style="font-size: medium;"><span style="font-family: ‘Courier New‘;"><span style="font-family: ‘Courier New‘; font-size: medium;"><span style="font-size: medium;">localizable.strings</span></span></span></span> </span></span></span></span></span></span> </span> (chinese) file Join:</p></p><strong><strong>[java]</strong></strong>View Plaincopy<object id="ZeroClipboardMovie_5" width="18" height="18" align="middle" bgcolor="#ffffff" data="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" type="application/x-shockwave-flash"><object id="ZeroClipboardMovie_5" width="18" height="18" align="middle" bgcolor="#ffffff" data="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" type="application/x-shockwave-flash"><param name="src" value="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf"><param name="loop" value="loop"><param name="menu" value="false"><param name="quality" value="best"><param name="allowscriptaccess" value="always"><param name="allowfullscreen" value="false"><param name="pluginspage" value="http://www.macromedia.com/go/getflashplayer"><param name="flashvars" value="id=5&width=18&height=18"><param name="wmode" value="transparent"></object></object> <ol class="dp-j" start="1"> <ol class="dp-j" start="1"> <li class="alt">tip=<span class="string">"hint"; </span></li> <li></li> <li class="alt">ok=<span class="string">"good"; </span></li> </ol> </ol><p><p></p></p><p><span style="font-family: ‘Courier New‘;"><span style="font-family: ' Courier New '; >10. use nslocalizedstring (key, Comment) in your code to read localized strings, key is <span style=" font-size:medium; "><span style="font-family: ' Courier new ';"><span style="font-family: ' Courier New '; font-size:medium;"><span style="font-size:medium;"><span style="font-family: ' Courier new '; font-size:medium;"><span style="font-family: ' Courier New '; font-size: medium; "><span style="font-size:medium;"><span style="font-family: ' Courier New ';"><span style="font-family: ' Courier New '; font-size:medium; "><span style="font-size:medium;"><span style="font-family: ' Courier New '; font-size:medium; ><span style=" font-family: ' courier new '; font-size:medium; "><span style="font-size:medium;"><span style="font-family: ' Courier New ';"><span style="font-family: ' Courier New '; font-size:medium; "><span style="font-size:medium;">localizable.strings </span> </span> </span> </span> </span> </span> </span> </span> </span> </span></span></span></span></span></span></span>The string to the left of the equal sign in the file, comment is purely a comment</p><p><p></p></p><strong><strong>[java]</strong></strong>View Plaincopy<object id="ZeroClipboardMovie_6" width="18" height="18" align="middle" bgcolor="#ffffff" data="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" type="application/x-shockwave-flash"><object id="ZeroClipboardMovie_6" width="18" height="18" align="middle" bgcolor="#ffffff" data="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" type="application/x-shockwave-flash"><param name="src" value="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf"><param name="loop" value="loop"><param name="menu" value="false"><param name="quality" value="best"><param name="allowscriptaccess" value="always"><param name="allowfullscreen" value="false"><param name="pluginspage" value="http://www.macromedia.com/go/getflashplayer"><param name="flashvars" value="id=6&width=18&height=18"><param name="wmode" value="transparent"></object></object> <ol class="dp-j" start="1"> <ol class="dp-j" start="1"> <li class="alt">NSString *tip = nslocalizedstring (@<span class="string">"tip", nil); </span></li> <li>NSString *ok = nslocalizedstring (@<span class="string">"ok", nil); </span></li> </ol> </ol><p><p>If the string is not localized or the key corresponding value is not found, nslocalizedstring will return the key string directly</p></p><p><p></p></p><p><span style="font-family: ‘Courier New‘;"><span style="font-size: medium;"><span style="font-size:medium;"><span style="font-family: ' Courier New ';"> note: If your string resource file name is not <span style=" font-size:medium; "><span style="font-family: ' Courier new ';"><span style="font-family: ' Courier New '; font-size:medium;"><span style="font-size:medium;"><span style="font-family: ' Courier new '; font-size:medium;"><span style="font-family: ' Courier New '; font-size: medium; "><span style="font-size:medium;"><span style="font-family: ' Courier New ';"><span style="font-family: ' Courier New '; font-size:medium; "><span style="font-size:medium;"><span style="font-family: ' Courier New '; font-size:medium; ><span style=" font-family: ' courier new '; font-size:medium; "><span style="font-size:medium;"><span style="font-family: ' Courier New ';"><span style="font-family: ' Courier New '; font-size:medium; "><span style="font-size:medium;">localizable.strings </span> </span> </span> </span> </span> </span> </span> </span> </span> </span></span></span></span></span></span></span></span></span></span>, such as mj.strings, you will have to use nslocalizedstringfromtable () to read the localized string:</p><p><p></p></p><strong><strong>[java]</strong></strong>View Plaincopy<object id="ZeroClipboardMovie_7" width="18" height="18" align="middle" bgcolor="#ffffff" data="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" type="application/x-shockwave-flash"><object id="ZeroClipboardMovie_7" width="18" height="18" align="middle" bgcolor="#ffffff" data="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" type="application/x-shockwave-flash"><param name="src" value="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf"><param name="loop" value="loop"><param name="menu" value="false"><param name="quality" value="best"><param name="allowscriptaccess" value="always"><param name="allowfullscreen" value="false"><param name="pluginspage" value="http://www.macromedia.com/go/getflashplayer"><param name="flashvars" value="id=7&width=18&height=18"><param name="wmode" value="transparent"></object></object> <ol class="dp-j" start="1"> <ol class="dp-j" start="1"> <li class="alt">Nslocalizedstringfromtable (@<span class="string">"Tip", @<span class="string">"mj", nil); </span></span></li> </ol> </ol><p><p></p></p><p><p>Add: another way to generate a string resource file (via terminal Commands)</p></p><p><p>1. First add the code that gets the string, for example, in MJVIEWCONTROLLER.M</p></p><p><p></p></p><strong><strong>[java]</strong></strong>View Plaincopy<object id="ZeroClipboardMovie_8" width="18" height="18" align="middle" bgcolor="#ffffff" data="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" type="application/x-shockwave-flash"><object id="zeroclipboardmovie_8" width="up" height="align=" "middle" bgcolor="#ffffff" data="/http static.blog.csdn.net/scripts/zeroclipboard/zeroclipboard.swf " type=" Application/x-shockwave-flash "><param name=" SRC " value=" http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf "> <param name="loop" value="loop"><param name="menu" value="false"><param name="quality" value="best"><param Name="allowscriptaccess" value="always"><param name="allowfullscreen" value="false"><param name="pluginspage" value=" Http://www.macromedia.com/go/getflashplayer "><param name=" flashvars " value=" id=8&width=18&height=18 ">< param name= "wmode" value= "transparent" > </object></object> <ol class="dp-j" start="1"> <ol class="dp-j" start="1"> <li class="alt">NSString *tip = nslocalizedstring (@<span class="string">"tip" @ "<span class="string">Dialog title"); </span></span></li> <li>NSString *ok = nslocalizedstring (@<span class="string">"ok" @ "<span class="string">Dialog button"); </span></span></li> </ol> </ol><p><p><br>2. Open the terminal, navigate to the folder where the MJVIEWCONTROLLER.M is located, enter the Genstrings command, generate a string resource file</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p>3. Open the folder, the string resource file has been generated</p></p><p><p></p></p><p><p></p></p><p><p>If you use nslocalizedstringfromtable (key, tbl, comment) to get a string, the resource file takes the TBL parameter as the file name, such as</p></p><strong><strong>[java]</strong></strong>View Plaincopy<object id="ZeroClipboardMovie_9" width="18" height="18" align="middle" bgcolor="#ffffff" data="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" type="application/x-shockwave-flash"><object id="zeroclipboardmovie_9" width="up" height="align=" "middle" bgcolor="#ffffff" data="/http static.blog.csdn.net/scripts/zeroclipboard/zeroclipboard.swf " type=" Application/x-shockwave-flash "><param name=" SRC " value=" http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf "> <param name="loop" value="loop"><param name="menu" value="false"><param name="quality" value="best"><param Name="allowscriptaccess" value="always"><param name="allowfullscreen" value="false"><param name="pluginspage" value=" Http://www.macromedia.com/go/getflashplayer "><param name=" flashvars " value=" id=9&width=18&height=18 ">< param name= "wmode" value= "transparent" > </object></object> <ol class="dp-j" start="1"> <ol class="dp-j" start="1"> <li class="alt">NSString *tip = nslocalizedstringfromtable (@<span class="string">"tip", @<span class="string">"mj", @<span class="string">"dialog title"); </span></span></span></li> <li>NSString *ok = nslocalizedstringfromtable (@<span class="string">"ok" @ "<span class="string">mj" @<span class="string">"dialog button"); </span></span></span></li> </ol> </ol><p><p>The generated resource file Is: mj.strings</p></p><p><p></p></p><p><p>4. Import the resource file into the project and open the resource file to discover that the key and comment have been generated</p></p><p><p></p></p><strong><strong>[java]</strong></strong>View Plaincopy<object id="ZeroClipboardMovie_10" width="18" height="18" align="middle" bgcolor="#ffffff" data="http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf" type="application/x-shockwave-flash"><object id="zeroclipboardmovie_10" width="up" height="align=" "middle" bgcolor="#ffffff" data="/http static.blog.csdn.net/scripts/zeroclipboard/zeroclipboard.swf " type=" Application/x-shockwave-flash "><param name=" SRC " value=" http://static.blog.csdn.net/scripts/ZeroClipboard/ZeroClipboard.swf "> <param name="loop" value="loop"><param name="menu" value="false"><param name="quality" value="best"><param Name="allowscriptaccess" value="always"><param name="allowfullscreen" value="false"><param name="pluginspage" value=" Http://www.macromedia.com/go/getflashplayer "><param name=" flashvars " value=" id=10&width=18&height=18 "> <param name="wmode" value="transparent"> </object></object> <ol class="dp-j" start="1"> <ol class="dp-j" start="1"> <li class="alt"><span class="comment">/* Dialog Button */</span></li> <li><span class="string">"ok" = <span class="string">"ok"; </span></span></li> <li class="alt"></li> <li><span class="comment">/* Dialog Title */</span></li> <li class="alt"><span class="string">"tip" = <span class="string">"tip"; </span></span></li> </ol> </ol><p><p></p></p><p><p></p></p><p><p><strong>Viii. Localization of other documents</strong></p></p><p><p>The principle of localization is the same as in six, repeat each of the six steps to</p></p><p><p></p></p><p><p><strong>nine, The final effect demonstration</strong></p></p><p><p>1. In the English environment</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p>2. The Chinese environment</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p>App Localization--backup</p></p></span>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service