1.1 create a Single View app template project named Localization.
1.2 after the creation, you can see the following working directory structure file. Click InfoPlist. strings to view the properties on the right and add a language in the Localization column.
1.3 open the corresponding language file after adding the language, such as the addition of English
CFBundleDisplayName = "China ";
Add a Chinese File
CFBundleDisplayName = "China ";
Run. If your simulator is in Chinese at this time, you will see that your program name has changed to China:
Set the language to English in settings. The program name is changed to: China
Then, the program name is internationalized. What about the content?
2. International content
2.1 create a Localization. strings File
2.2 Add the same language as the 1.1 link.
2.3 add language content
Add "Key" = "value"; then use NSLocalizedString (@ "key", @ ""); to read the content.
Add Localization. strings English File
"Key" = "english value ";
Add Localization. strings English File
"Key" = "Chinese content ";
Add a UILabel experiment in ViewController. m.
- (void)viewDidLoad{ [super viewDidLoad]; UILabel *label = [[UILabel alloc] init]; label.frame = CGRectMake(20, 40, 250, 60); label.text = NSLocalizedString(@"key", @""); [self.view addSubview:label];}
Run
Switch to English in settings
3. How can I determine the language of the current running environment during running?
3.1 obtain Supported languages
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults]; // set NSArray * languages = [defaults objectForKey: @ "AppleLanguages"]; NSLog (@ "% @", ages );
Run and print the result:
(
En,
"Zh-Hant ",
"Zh-Hans ",
Fr,
De,
Ja,
Nl,
It,
Es,
Pt,
"Pt-PT ",
Da,
Fi,
Nb,
Sv,
Ko,
Ru,
Pl,
Tr,
Uk,
Ar,
Hr,
Cs,
El,
He,
Ro,
Sk,
Th,
Id,
"En-GB ",
Ca,
Hu,
Vi
)
"Zh-Hant" Traditional Chinese
"Zh-Hans", simplified Chinese
This code gets the languages supported by the current system.
3.2 obtain the current language
NSArray *languages = [NSLocale preferredLanguages]; NSString *currentLanguage = [languages objectAtIndex:0]; NSLog ( @"%@" , currentLanguage);
Print result:
En
You can use the obtained current language to compare it with the supported language to understand the language.
if([currentLanguage isEqualToString:@"en"]) { NSLog(@"current Language:en"); }
This article from network: http://www.cnblogs.com/stoic/archive/2012/07/08/2581298.html