There are two general approaches to multiple languages in an application:
First, the process to provide users with their own choice of opportunity;
Nsarray *languages = [Nslocale preferredlanguages];
NSString *currentuselanguage = [languages objectatindex:0];
Second, according to the current user's current mobile device language automatically switch our app to the corresponding language.
The first approach is relatively simple entirely by their own play, here is mainly about the second approach, the main points of the points:
1. Localizing the application name
2. Localizing strings
3. Localized images
4. Localizing Other files
1. Localizing the application name
(1) Click "New File" and select the iOS resource item on the left side of the popup window, and on the right side you will see the "String File" icon. Create this file, named "Infoplist" (which must be the file name) to generate a infoplist.strings file;
(2) Select Infoplist.strings Click Xcode-> view-> Utilities, File Inspector, in the localization midpoint "+", add Chinese (Zh-hans) type for Simplified Chinese, 中文版 should be added automatically. Then on the left side of the infoplish.strings will be a more triangle, click to expand can see Infoplish.strings (English) and Infoplish.strings (Chinese) Two versions of the file;
(3) in the Infoplish.strings (中文版) file, add:
Cfbundledisplayname = "program";
Where "program" is the English application name, in the same vein in the Infoplish.strings (Chinese) file, add:
Cfbundledisplayname = "Application";
Where "Application" is the Chinese name, note: Cfbundledisplayname plus no double quotation marks are OK
(4) Edit Info.plist, add a new property application has localized display name, set its type to Boolean, and set its value to Yes
2. Localizing strings
(1) Similar to "Localized application name" First step, click "New File" and then on the left side of the pop-up window select the iOS resource item, on the right side you can see the "String File" icon. Create this file, named "Localizable" (must be this file name otherwise the call will have some difference) to generate a localizable.strings file;
(2) Similar to "Localized application name" The second third step, in the Localizable.strings (中文版) file, include:
"Welcome" = "Click on the screen to continue ...";
Similarly, in the Localizable.strings (Chinese) file, add:
"Welcome" = "click on screen to continue ...";
(3) Use Nslocalizedstring (< #key #>, < #comment #>) in the code to read the localized string as follows:
Cclabelttf *label = [Cclabelttf labelwithstring:nslocalizedstring (@ "Welcome", Nil) fontname:@ "Marker Felt" fontsize:18 ];
Cgsize size = [[Ccdirector shareddirector] winsize];
Label.position = CCP (SIZE.WIDTH/2, size.height/2+30);
[Self Addchild:label];
Note: If your strings file name is not localizable but custom, such as Wang.strings, then you will have to use nslocalizedstringfromtable () to read the localized string:
Nslocalizedstringfromtable (@ "Welcome", @ "Wang", nil)
3. Localized images
Here are two methods, the first and the localization of the string method, the name of the Chinese and English images are stored in the corresponding strings file, and then through the nslocalizedstring) to obtain the image name, such as:
Localizable.strings (中文版) file:
"Btncancel" = "btncancelen.png";
Localizable.strings (Chinese) file, add:
"Btncancel" = "btncancelcn.png";
Then use nslocalizedstring in your code to get the picture name:
Ccsprite *btncancel = [Ccsprite spritewithspriteframename:nslocalizedstring (@ "Btncancel", nil)];
BTNCANCEL.POSITION=CCP (S.WIDTH/2,S.HEIGHT/2-40);
[Self addchild:btncancel z:2 tag:104];
4. Localizing Other files
Localize the other files, add the language to the localization first, and then copy the corresponding version to the En.lproj and Zh-hans.lproj folders, and the last reference is OK.
iOS multi-language settings, action