Multilingual localization solutions for iOS apps
Recently to a game to multi-lingual localization, find some programs on the Internet, plus their own a little bit of ideas to organize a set of programs and share!
There are two general approaches to multiple languages in an application:
First, the process to provide users with their own choice of opportunity;
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:
- < Span style= "margin:0px; padding:0px; Border:none; Background-color:inherit ">cfbundledisplayname = " program " ;&NBSP;&NBSP;&NBSP;&NBSP;
- < Span style= "margin:0px; padding:0px; Border:none; Background-color:inherit ">cfbundledisplayname = " application " ;&NBSP;&NBSP;&NBSP;
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 "in the second third step, add:
in the Localizable.strings (English) file.
- < Span class= "string" style= "margin:0px; padding:0px; Border:none; Color:blue; Background-color:inherit ">" Welcome " = " click on the screen to continue " ;&NBSP;&NBSP;&NBSP;
Similarly, in the Localizable.strings (Chinese) file, add:
- < Span class= "string" style= "margin:0px; padding:0px; Border:none; Color:blue; Background-color:inherit ">" Welcome " = " click on the screen to continue ... " ;&NBSP;&NBSP;&NBSP;
(3) in code using Nslocalizedstring (< #key #>, < #comment #>) to read the localized string, the code is as follows:
- < Span style= "margin:0px; padding:0px; Border:none; Background-color:inherit ">cclabelttf *label = [cclabelttf labelwithstring: Nslocalizedstring (@ " Welcome " , nil) fontName:@ 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:
- < Span style= "margin:0px; padding:0px; Border:none; Background-color:inherit ">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:
- < Span class= "string" style= "margin:0px; padding:0px; Border:none; Color:blue; Background-color:inherit ">" Btncancel " = " btncancelen.png " ;&NBSP;&NBSP;&NBSP;
localizable.strings (Chinese) file:
- < Span class= "string" style= "margin:0px; padding:0px; Border:none; Color:blue; Background-color:inherit ">" Btncancel " = " btncancelcn.png " ;&NBSP;&NBSP;&NBSP;
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];
The second is more formalized: point in the image you want to localize, such as "Icon.png", and then xcode-> view-> Utilities, File Inspector, in the localization midpoint "+" add Chinese (Zh-hans); a inverted triangle appears to the left of the picture, and 2 images of (English) and (Chinese) appear in the project folder. en.lproj files and zh-hans.lproj files; en.lproj file is stored in the English version of the picture, Zh-hans.lproj store is the Chinese version of the picture, in English and Chinese image name, we can directly replace the picture in the folder, The last use of the direct use of the normal name on the line, such as: "Icon.png."
4. Localizing Other files
Localizing other files and localizing images The second method is similar to adding a language in localization and then copying the corresponding version into the en.lproj and Zh-hans.lproj folders, and the last reference is OK.
iOS optimized Memory (iii) multilingual localization solutions for iOS applications