Internationalization of iOS Development chapter Ii: Internationalization of text information

Source: Internet
Author: User
<span id="Label3"></p><p><p><strong><span style="color: #ff0000;">This article is based on XCode7.2.1 as the development platform</span></strong></p></p><p><p>In the first chapter, we basically understand how internationalization is a matter, introduced to have 3 kinds of internationalization, the next few chapters will introduce these 3 kinds of internationalization, the first one is the text information internationalization</p></p><p><p><strong>The internationalization of text information contains a few points</strong></p></p> <ul> <ul> <li>System buttons and information internationalization</li> <li>Application name Internationalization</li> <li>Static text internationalization of output in program code</li> </ul> </ul><p><p><strong>-system button and information internationalization</strong></p></p><p><p>The system itself will bring some system information, system buttons, and so on, some of the system comes with the information hint, button text is from the cocoa itself, they are unified and system management, such as done in the English environment is done, there are system prompts information, such as, Different language settings will be displayed in different Locales.</p></p><p><p></p></p><p><p>We first look at the effect before the internationalization, we will first pull out a uitoolbar and then put the uitoolbaritem inside of the type set to cancal, after the normal operation, it is what we want, and then we set there change the language environment for korean, again run, The results did not change, or the English display cancal, this is because we do not set the program of Korean support</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p>Now let's add the Korean support at projct->info->locallizations, Press +, then add the languages that need support, we add Korean here, and the chance to get the desired effect after running</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p><strong>-application name Internationalization</strong></p></p><p><p>Application name internationalization is literally easy to understand, is the application in the desktop display in the English and Chinese names, The name is generally determined by the developer, now first look at the system comes with some of the apps such as: settings, calendars, etc., their internationalization effect</p></p><p><p></p></p><p><p>The structure of the file under normal circumstances</p></p><p><p></p></p><p><p>If you add more than one language support, it may be more than a infoplist.string file, the file will be accompanied by the language of the text translation files, if not manually added, remember that the file name must be infoplist, add the way as Follows:</p></p><p><p>Right-click Menu->new File ... In the pop-up window find strings File, and then create, remember the name must be infoplist</p></p><p><p></p></p><p><p></p></p><p><p>After the successful creation, in the file structure to see a file, infoplist.strings, click on the file, will be on the right side of the settings, display, and then click Localize ... button, and then you need to select the language that needs internationalization, here the options will vary depending on the supported language added, such as the addition of Korean support, there is a Korean choice, if there is chinese, there are Chinese options</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p>When you press the localize button, the right-hand property bar changes to make the groove part the internationalized language you just selected, and the file structure there is no change</p></p><p><p></p></p><p><p></p></p><p><p>If you need to add other international languages, just on the right, ditch the language you want to international (if you have to support the internationalization of the language, if you do not know how to add the language of support, you can refer to the previous section of this chapter), ditch selected the corresponding internationalization, Infoplist.strings file will be more than the international text file, file brackets followed by the type of language, such as: Chinese for English</p></p><p><p></p></p><p><p></p></p><p><p>Open the file, you can write in the need for internationalization of the key value pairs, where we want to internationalize the App's display name, the App's display name key is <span class="s1">cfbundledisplayname, respectively, in</span></p></p><p><p><span class="s1">*.strings (simplified) File Write</span> in <span class="s1">cfbundledisplayname=<span class="s2">" <span class="s3">internationalization <span class="s2">"<span class="s1">;</span> </span> </span> </span> </span></p></p><p><p><span class="s1"><span class="s2"><span class="s3"><span class="s2"><span class="s1">*.strings (english) file inside</span></span></span></span></span> <span class="s1">cfbundledisplayname=<span class="s2">"internationalization"<span class="s1">;</span> </span> </span></p></p><p><p><span class="s1"><span class="s2"><span class="s1"></span></span></span></p></p><p><p><span class="s1"><span class="s2"><span class="s1">Then use their own Simplified Chinese and English environment to run the application, on the desktop, you will see the effect</span></span></span></p></p><p><p><span class="s1"><span class="s2"><span class="s1"></span></span></span></p></p><p><p></p></p><p><p><strong>-program Code Internationalization</strong></p></p><p><p>First of all we want to build an international file is used for the internationalization of the code, as in the above tutorial, create a new *.string file, the file name is localizable.strings, must be named after this Name. then, as in the previous tutorial, create its corresponding internationalization support file,</p></p><p><p></p></p><p><p>Then we can write the key value pairs in the file, we use the name as the key, do a test, respectively, in Chinese and English in the internationalization of the file name of the value of this key corresponding</p></p><p><p>English internationalization:<span class="s1">name=<span class="s2">"international Test"<span class="s1">;</span> </span> </span></p></p><p><p><span class="s1"><span class="s2"><span class="s1">Chinese internationalization:</span></span></span> <span class="s1">name=<span class="s2">" <span class="s3">internationalization test <span class="s2">"<span class="s1">;</span> </span> </span> </span> </span></p></p><p><p>Then use the following code where it needs to be internationalized, This example prints a statement on the console</p></p><pre><pre>-(ibaction) buttononclick: (<span style="color: #0000ff;">ID</span><span style="color: #000000;">) sender { </span><span style="color: #800000;">@ "</span><span style="color: #800000;">Name</span><span style="color: #800000;">"</span><span style="color: #000000;">; NSLog (</span><span style="color: #800000;">@ "</span><span style="color: #800000;">%@</span><span style="color: #800000;">"</span><span style="color: #800000;">@ "</span><span style="color: #800000;">Name</span><span style="color: #800000;">"</span><span style="color: #000000;">);}</span></pre></pre><p><p>The main focus is on nslocalizedstring (@ ", @"); Here are two parameters, the first parameter is the key value in the Internationalized file, the second parameter is the default value, when the Internationalized file cannot be found or the corresponding key is not found in the internationalized file, the default value is displayed by default</p></p><p><p>Internationalization of iOS Development chapter Ii: Internationalization of text information</p></p></span>

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.