1. Right-click the supporting Files folder and choose newfile... -> IOS-> resources-> string files, named localizable. Strings
2. Select localizable. Strings and click xcode-> View-> utilities-> file inspector. In localization, click + add language such as Chinese and English
3. Now modify localizable. Strings (English)
"Test" = "test ";
And localizable. Strings (Chinese ).
"Test" = "test ";
Image: 1.png
Image: 2.png
The following is another detailed operation.
Recently, someone asked me that the get info is gone and there is no way to make localization. The tutorial is as follows:
Select the file for multiple languages and press command + Option + L
The following figure is displayed:
Add a language in Localization
When there are more than one language, you can see the familiar triangle arrow in the vertical bar on the left
At the same time, the number of multiple languages in the project is displayed in the project Info.
Code implementation (the code here is not xcdoe4.2) We cannot find the add get info resource in 4.2. Follow the above method. The following mainly describes the code
Description: automatically switches the appropriate display string based on the language set by the system.
Operation: interface during interface builder Design
If the system is set to English, the English interface is displayed.
If the system is set to Chinese, it is displayed as a Chinese interface
How to create custom language documents:
1. Add a file under the resources category [Right-click/Add/new file...]
2. Select other for the template category and then select strings File
3. Set the archive file name to localizable. Strings
4. Right-click the localizable. Strings file and select get info.
5. Select make file localizable in the lower-left corner.
6. Switch the page tag to General
7. Select Add localization in the lower left corner.
8. Enter the new language family name zh_cn and press add
9. Now you have set the English and zh_cn languages.
10. In the file list, you will see localizable strings (English) and localizable string (zh_cn)
11. After enabling it, edit the language string,
Example: localizable. Strings (English)
"Demotitle" = "this is English version ";
"String1" = "apple ";
"String2" = "banana ";
"String3" = "orange ";
"String4" = "watermelon ";
"String5" = "strawberry ";
Localizable. Strings (zh_cn)
"Demotitle" = "this is a Chinese version ";
"String1" = "apple ";
"String2" = "banana ";
"String3" = "orange ";
"String4" = "watermelon ";
"String5" = "strawberry ";
Code:
Multilanguagedemoviewcontroller. h
# Import <uikit/uikit. h>
@ Interface multilanguagedemoviewcontroller: uiviewcontroller {
Iboutlet uilabel * lbldemotitle;
Iboutlet uilabel * lblstr1;
Iboutlet uilabel * lblstr2;
Iboutlet uilabel * lblstr3;
Iboutlet uilabel * lblstr4;
Iboutlet uilabel * lblstr5;
}
@ Property (nonatomic, retain) uilabel * lbldemotitle;
@ Property (nonatomic, retain) uilabel * lblstr1;
@ Property (nonatomic, retain) uilabel * lblstr2;
@ Property (nonatomic, retain) uilabel * lblstr3;
@ Property (nonatomic, retain) uilabel * lblstr4;
@ Property (nonatomic, retain) uilabel * lblstr5;
@ End
Multilanguagedemoviewcontroller. m
# Import "multilanguagedemoviewcontroller. H"
@ Implementation multi‑agedemoviewcontroller
@ Synthesize lbldemotitle, lblstr1, lblstr2, lblstr3, lblstr4, lblstr5;
-(Void) viewdidload {
[Super viewdidload];
// Obtain the multi-language string set by the System
Lbldemotitle. Text = nslocalizedstring (@ "demotitle", nil );
Lblstr1.text = nslocalizedstring (@ "string1", nil );
Lblstr2.text = nslocalizedstring (@ "string2", nil );
Lblstr3.text = nslocalizedstring (@ "string3", nil );
Lblstr4.text = nslocalizedstring (@ "string4", nil );
Lblstr5.text = nslocalizedstring (@ "string5", nil );
}
2. Internationalization of XIB files
Add a multi-language version of get info to the XIB file to be internationalized,
Modify the text and images of the corresponding language versions.
To test the simulator, remember to restore the original factory settings on the simulator, and clean xcode. Otherwise, errors may occur.
International Code query: http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm
3. program name Internationalization
Create an infoplist. Strings File
And then internationalize it, get info ..
Write cfbundledisplayname = "Chinese name" in the language file generated below ";
Edit info. plist, add a new property application has localized display name, set its type to boolean, and set its value to the selected state.
In a program, you can call nslocalizedstring to retrieve the strings of the corresponding language.
If your strings file is not the standard localizable. Strings file, you can use
Nslocalizedstringfromtable (@ "button", @ "my", nil );