Ios multi-language localization ideas

Source: Internet
Author: User

Ios multi-language localization ideas

Ios programs implement multi-language Localization Methods. Recently, we have to localize a game in multiple languages. I have found some solutions on the internet, and I have compiled a set of solutions with my own thoughts to share with you!

There are two common approaches for multilingual applications:

1. opportunities provided by the Program for the user to choose;

2. automatically switch our app to the corresponding language based on the language of the current mobile device.

The first approach is relatively simple and fully depends on your own. Here we will focus on the second approach, mainly including the following points:

1. localized application name

2. localized strings

3. localized Images

4. localize other files

1. localized application name

(1) Click "new file" and select the IOS resource item on the left side of the pop-up window. The "String File" icon is displayed on the right. Create this file and name it "InfoPlist" (This file name must be used) to generate an InfoPlist. strings file;

(2) Select InfoPlist. for strings, click XCode-> View-> Utilities-> File Inspector and click "+" in Localization to add Simplified chinese (zh-Hans, english should be added automatically. Then there will be an extra triangle on the left of InfoPlish. strings. Click expand to see the InfoPlish. strings (english) and InfoPlish. strings (chinese) files;

(3) add the following to the InfoPlish. strings (english) file:

The Code is as follows:

CFBundleDisplayName = "Program ";

"Program" is the name of the English application. Similarly, it is added to the InfoPlish. strings (chinese) file:

The Code is as follows:

CFBundleDisplayName = "application ";

The "application" is a Chinese name. Note: CFBundleDisplayName can be added without double quotation marks.

(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. localized strings

(1) similar to the "localized application name" Step 1, click "new file" and select the IOS resource item on the left side of the pop-up window, the "String File" icon is displayed on the right. Create this file and name it "Localizable" (it must be the file name; otherwise, there will be some differences in future calls) to generate a Localizable. strings file;

(2) Add the following content to the Localizable. strings (english) file:

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

Similarly, add the following content to the Localizable. strings (chinese) file:

"Welcome" = "click the screen to continue ...";

(3) Use NSLocalizedString (<# key # >,< # comment #>) in the Code to read the local string. The Code is as follows:

The Code is as follows:

CCLabelTTF * label = [CCLabelTTF labelWithString: NSLocalizedString (@ "welcome", nil) fontName: @ "Marker Felt" fontSize: 18];

CGSize size = [[CCDirector shareddire] 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, you must use NSLocalizedStringFromTable () to read the local string:

The Code is as follows:

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

3. localized Images

There are two methods. The first method is similar to the localized string method. Save the names of Chinese and English images to the strings file corresponding to Chinese and English, and then obtain the image name through NSLocalizedString. For example:

Add the following to the Localizable. strings (english) file:

The Code is as follows:

"BtnCancel" = "BtnCancelEn.png ";

Add the following to the Localizable. strings (chinese) file:

The Code is as follows:

"BtnCancel" = "BtnCancelCn.png ";

Then use NSLocalizedString in the Code) to get the image name:

The Code is as follows:

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 method is more formal: Click the image you want to compile, such as “icon.png ", then XCode-> View-> Utilities-> File Inspector, and click" + "in Localization to add chinese (zh-Hans ); there will be an inverted triangle on the left side of the image. When you click it, two pictures of (english) and (chinese) will appear, and en will appear in the project folder. lproj file and zh-Hans.lproj file; en. lproj files are stored in the English version of the image, zh-Hans.lproj is stored in the Chinese version of the image, the same as the English image name, we can directly replace the picture in the folder, at last, you can use the normal name directly, for example, “icon.png ".

4. localize other files

Localization of other files is similar to the second method of Localization images. First add a language in Localization, then copy the corresponding version to the en. lproj and zh-Hans.lproj folders, and finally reference it.

The above is all the content of this article. I hope you will like it.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.