3 minutes for iOS localization/internationalization (graphic)

Source: Internet
Author: User

    • Objective
      • Language localization, also known as language internationalization.
      • is to automatically set the language of the application to a language consistent with the language of the user's operating system, based on the language settings of the user's operating system.
      • Often some applications need to be available to people in multiple countries, or a country with multiple languages, which requires the application to display the text, pictures and other information, can be spoken in different languages of users to read and understand.
      • In turn, it is internationalized to adapt multiple languages for the same application.
      • Language internationalization is also called language localization, which is to stand in the perspective of each user, refers to the user can be local, native people can read the language information, as the name implies, language localization. In fact, language localization = language Internationalization!
1, pre-preparation to configure the need for international language
    • Configuring a language that requires internationalization is also a preparation for internationalization, whether we are internationalized app names, strings in code, pictures, or Storyboard and xib, all of which need to be prepared for this step (one project needs to be configured only once).
    • Select Project->info->localizations, and then click "+" to add a language that requires internationalization/localization, such as (by default, use Base internationalization is checked):
    • Here is an example of adding French, such as:
    • The following dialog box appears, click Finish directly, such as:
    • Similarly, add Simplified Chinese, Traditional Chinese, Korean, the final result such as:
    • Note: "Zh-hans" and "zh-hant" are abbreviations for Simplified Chinese and Traditional Chinese. This is the standard abbreviation. H can be uppercase or lowercase. "EN" is an abbreviation for English. Ko is an abbreviation for Korean, and FR is the abbreviation for French. Other languages please Baidu language abbreviations can be queried.
2. Various internationalization
    • (i) Application name localization/internationalization
    • (ii) Localization of strings in code
    • (iii) string localization in the case of multi-person development
    • (d) Image localization
3. View/Toggle Local language
    • Principle: When the application starts, it will first read the value corresponding to the key applelanguages in Nsuserdefaults, which is a string array, that is, Our visit to this key named Applelanguages returns a string array that stores the list of languages supported by the app, and the first item in the array is the current default language of the app.
   #import "ViewController.h"       @interface ViewController ()       @end       @implementation ViewController       - (void)viewDidLoad {       [super viewDidLoad];           NSArray *languages = [[NSUserDefaults standardUserDefaults] valueForKey:@"AppleLanguages"];       NSString *currentLanguage = languages.firstObject;       NSLog(@"模拟器当前语言:%@",currentLanguage);   }   @end
    • Console Print Results:
    • Similarly, since we can remove the language array from the Nsuserdefaults by applelanguages This key, we can also assign a value to the Applelanguages key to achieve the effect of switching the local language, and thereafter, We do not need to go to the simulator settings---general----language and region to switch languages.
  #import "ViewController.h" @interface Viewcontroller () @end @i             Mplementation Viewcontroller-(void) viewdidload {[Super viewdidload];        Switch language before Nsarray *langarr1 = [[Nsuserdefaults standarduserdefaults] valueforkey:@ "Applelanguages"];        NSString *language1 = Langarr1.firstobject;             NSLog (@ "simulator language before switching:%@", language1);        Toggle language Nsarray *lans = @[@ "en"];             [[Nsuserdefaults Standarduserdefaults] Setobject:lans forkey:@ "Applelanguages"];        After switching the language nsarray *LANGARR2 = [[Nsuserdefaults standarduserdefaults] valueforkey:@ "Applelanguages"];        NSString *language2 = Langarr2.firstobject;    NSLog (@ "simulator language after switching:%@", language2); } @end  
    • Recall that I mentioned in the tips section above: Switching languages does not need to be set in the simulator, just set the following in Xcode: Edit->scheme->run->arguments Passed on Launch->- Applelanguages (language code). In essence, it is assigned to the key named Applelanguages in Nsuserdefaults.

3 minutes for iOS localization/internationalization (graphic)

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.