International text commentary under xcode5.0.2

Source: Internet
Author: User
Tags addchild

Have never done an international thing before, the recent project emergency notice: to the fastest speed to make an English version (customers are waiting for use abroad). Dizzy.

Many of the information I have read online is below my version. Some places are inconsistent. Close-up this article is reserved for myself.

According to the information on the Internet, the internationalization is mainly divided into three modules:

1.icon module. Mainly the text changes under the desktop icon.

2. Changes in the text within the program.

3. Changes in the picture within the program.


1.icon Module

First talk about the icon module on the xcode5.0.2 processing.

As is said online, to establish the Chinese version and English version of the Infoplist.strings file. This is directly on the map.

Select the Project menu,


Click the Red box as shown below


This is where project is selected, not targets


Follow the steps to click the Info menu, pull down to the end, and see localizations. Click the + sign.


Click on the Finish button to complete the Chinese generation.


Two files appear in the red box above. This is a different place from the Internet. The rest is just the same.

In the Infoplish.strings (中文版) file, add:

Cfbundledisplayname = "program";

Similarly, in the Infoplish.strings (Chinese) file, add:

Cfbundledisplayname = "Application";

In the Testlocationtests-info.plist file,

Bundle Display name = Cfbundledisplayname completed the internationalization of the icon module in both English and Chinese.


2. Changes in the text in the program

Like the first step of "Localizing Application Name", click "New File" and select the iOS resource item on the left side of the pop-up window, and you will see the "String File" icon on the right. 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: [CPP] view plain copy "Welcome" = "Click on the" in the Localizable.strings (English) file Screen to continue ... ";

Similarly, in the Localizable.strings (Chinese) file, add: [CPP] view plain copy "Welcome" = "click on screen to continue ...";

(3) Use Nslocalizedstring (< #key #>, < #comment #>) in the code to read the localized string, with the following code: [CPP] view plain copy 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: [CPP] View Plain copy nslocalizedstringfromtable (@ "Welcome", @ "Wang", nil)

3. Changes in the picture within the program.

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: [CPP] view plain copy "Btncancel" = "btncancelen.png";

Localizable.strings (Chinese) file: [CPP] view plain copy "Btncancel" = "btncancelcn.png";

Then use nslocalizedstring in your code to get the picture name: [CPP] view plain copy 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) will appear. And in the project folder will appear en.lproj files and zh-hans.lproj files, en.lproj files are stored in the English version of the picture, Zh-hans.lproj store is the Chinese version of the picture, the name of the English image, we can directly replace the picture in the folder, the last use of the direct use of normal Name on the line, such as: "Icon.png"

finally collect some information;

1. Get all the language settings supported by the IPhone

Nsuserdefaults *defaults = [Nsuserdefaults standarduserdefaults];

Nsarray *languages = [defaults objectforkey: @ "Applelanguages"];

NSLog (@ "%@", languages);

2. Get the language version you are currently using and compare

NSString *currentlanguage = [[Nslocale preferredlanguages] objectatindex:0];

if ([Currentlanguage isequaltostring:@ "en"]) {

中文版

}


Here also thanks to http://blog.csdn.net/wangqiuyun/article/details/7875442, who has part of his content.


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.