ios -> iOS localization (following system language changes)

 

 

Reprinted from: http://blog.csdn.net/jay6971134/article/details/51384367

 

 

 

1. App name localization

1. Create a new source file, select string files, and name the file InfoPlist (must be this name, otherwise it is invalid, pay attention to the capitalization of the first letter) 
write picture description here

2. Add a localized language type, the steps are as follows, select Simplified Chinese 
write picture description here

3. Select the InfoPlist.string file, then click on the right and select Chinese 
write picture description here

After confirmation, the file will become 2, as shown in the figure 
write picture description here

4. Write the following code in the corresponding file

CFBundleDisplayName = "hello"; //English name
CFBundleDisplayName = "Hello"; //Chinese name

 

 

5. Add a new field in Info.plist and set it to YES 
write picture description here

After this step, the name of the App has been localized

2. Localize the text displayed in the app

1. Similar to 1, create a string file and name it Localizable.string (preferably this name, otherwise the subsequent calls will be different) 
2. Add multiple languages ​​to the file, the steps are the same as above 
write picture description here

3. After completion, write the text you want to localize in the corresponding file, the left side is the key, and the right side is the actual displayed text

"text" = "en_text”;          //英文
"text" = "text"; //Chinese

 

4. Use the key-value method to get the value in the program

UILabel * lab = [[UILabel alloc] initWithFrame:CGRectMake(30, 100, 120, 40)];
lab.text = NSLocalizedString(@"text", nil);     //text是key

 

Note: Because the string name used earlier is Localizable.string, NSLocalizedString(@"text", nil) is used here to get the value. 
If the file name of the string is other, you need to use

 

NSLocalizedStringFromTable(@"text", @"fileName", nil); //fileName is the name of the string file

 

3. Localized images

Two ways: the first one is similar to the localization string, and different Chinese and English pictures are taken according to the key, mainly the second one: 
1. Select the picture to be localized, click on the picture, and then click on the right 
write picture description here

2. After the picture is clicked, 2 pictures will appear, in Chinese and English. In the future, you only need to give the corresponding Chinese and English pictures the same name and put them in the corresponding file.

 
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326152227&siteId=291194637
ios