Two Solutions for Multilingual Localization of IOS Applications

  • 2021-07-03 00:56:38
  • OfStack

Recently, I want to localize a game in multiple languages. I found some schemes on the Internet, and I sorted out a set of schemes with my own ideas to share!

Multilingualism generally has two approaches in applications:

1. The program provides users with the opportunity to choose by themselves;

2. Automatically switch our app to the corresponding language according to the language of the current user's current mobile device.

The first method is relatively simple and depends entirely on one's own play. Here, we mainly talk about the second method, which is mainly divided into the following points:

Localized application name Localized string Localized picture Localize other files

1. Localize the application name

(1) Click "new file" and select resource item of iOS on the left side of the pop-up window, and the icon of "String File" can be seen on the right side. Create this file and name it "InfoPlist" (1 is the file name) to generate an InfoPlist. strings file;

(2) Select InfoPlist. strings and click XCode- > View- > Utilities - > File Inspector, "+" in the midpoint of Localization, chinese (zh-Hans) is added in simplified Chinese, and english should be added automatically. Then there will be an extra triangle on the left side of InfoPlish. strings. After clicking Expand, you can see the files of InfoPlish. strings (english) and InfoPlish. strings (chinese).

(3) Add in the InfoPlish. strings (english) file:


CFBundleDisplayName ="Program"; 

Where "Program" is the English application name, it is added in the file InfoPlish. strings (chinese) in the same way:


CFBundleDisplayName =" Applications "; 

Where "application" is a Chinese name, note: CFBundleDisplayName with or without double quotation marks will do

(4) Edit Info. plist, add a new attribute Application has localized display name, set its type to boolean, and set its value to YES

2. Localize strings

(1) Similar to step 1 of "Localized application name", click "new file" and select resource item of IOS on the left side of the pop-up window, and you can see the icon of "String File" on the right side. Create this file and name it "Localizable" (1 must be this file name otherwise there will be 1 difference in later calls) to generate an Localizable. strings file;

(2) Similar to "Localizing Application Names," Step 2, Step 3, add in the Localizable. strings (english) file:


"welcome"="Click on the screen to continue..."; 

Similarly, in the Localizable. strings (chinese) file, add:


"welcome"=" Click on the screen to continue ..."; 

(3) Use NSLocalizedString ( < #key# > , < #comment# > ) 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 have to use NSLocalizedStringFromTable () to read the localized string:


NSLocalizedStringFromTable(@"welcome",@"wang", nil) 

3. Localize pictures

There are two methods here. The first method is similar to the localized string method. The names of Chinese and English pictures are stored in the corresponding strings files in Chinese and English, and then the picture names are obtained through NSLocalizedString, such as:

In the document Localizable. strings (english), add:


"BtnCancel"="BtnCancelEn.png"; 

In the Localizable. strings (chinese) file, add:


"BtnCancel"="BtnCancelCn.png"; 

Then use NSLocalizedString) in the 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: click on the picture you want to localize, such as "icon. png", and then XCode- > View- > Utilities - > File Inspector, adding chinese (zh-Hans) at the midpoint "+" of Localization; An inverted 3 corner will appear on the left side of the picture, and two pictures (english) and (chinese) will appear when clicked on, and en. lproj files and zh-Hans. lproj files will appear in the project folder; en. lproj file stores English pictures, zh-Hans. lproj stores Chinese pictures, and the names of Chinese and English pictures are one. We can directly replace the pictures in the folder, and finally use the normal names directly, such as "icon. png".

4. Localize other documents

Localizing other files is similar to localizing pictures. First, add a language to Localization, then copy the corresponding version to the en. lproj and zh-Hans. lproj folders, and finally refer to it.


Related articles: