iOS localization ideas for multiple languages

Source: Internet
Author: User
Tags addchild

Multiple languages in the application generally there are two ways: first, the program 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: 1. Localize the application Name 2. Localize the string 3. Localize the picture 4. localizing other files 1. Localizing the application name (1) Click "New File" Then select the iOS resource item on the left side of the pop-up window and you'll see the icon for "String File" on the right. Create this file, named "Infoplist" (must be the file name) to generate a infoplist.strings file; (2) Select Infoplist.strings Click Xcode-> view-> Utilities- > File Inspector, in localization midpoint "+", add Chinese (zh-hans) type for Simplified Chinese, 中文版 should be added automatically. Then on the left side of the infoplish.strings will have a triangle, click to expand can see Infoplish.strings (English) and Infoplish.strings (Chinese) Two versions of the file ; (3) in the Infoplish.strings (中文版) file: Copy code code as follows:  cfbundledisplayname = "program";   where "program" For the English application name, the same as in the Infoplish.strings (Chinese) file: Copy code code is as follows:  cfbundledisplayname = "Application";   where "application" For Chinese names, note: Cfbundledisplayname plus no double quotes (4) Edit Info.plist, add a new property application has localized display name, set its type to Boolean, and set its value to Yes to  2. Localized string (1) similar to 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 side. Create this file, named "Localizable" (must be this file name otherwise the call will have some areasNO) generates a localizable.strings file; (2) similar to "Localized application name" in the second third step, in the Localizable.strings (English) file, add: "Welcome" = "click on the Screen to continue ... ";   in Localizable.strings (Chinese) file:" Welcome "=" Click to continue ... ";  (3) Use Nslocalizedstring (< #key #>, < #comment #>) in the code to read the localized string as follows: Copy code code 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: Copy the code code as follows:  nslocalizedstringfromtable (@ "Welcome", @ "Wang", nil)   3. Localized images There are two different ways The first is similar to the localization string method, the names of the Chinese and English images are stored in the corresponding strings file in English and Chinese, and then through nslocalizedstring) to obtain the image name, such as: Localizable.strings (中文版) File: Copy code code as follows:  "btncancel" = "btncancelen.png";  localizable.strings (Chinese) file: Copy code code as follows:  " Btncancel "=" BtnCancelcn.png ";  then use nslocalizedstring in the code to get the picture name: Copy the Code code as follows:  ccsprite *btncancel = [Ccsprite Spritewithspriteframename:nslocalizedstring (@ "Btncancel", nil)];&NBSP;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, add Chinese (zh-hans) to the localization midpoint "+"; a inverted triangle appears to the left of the picture, and 2 images of (English) and (Chinese) appear in the Open. 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". 4. Localizing other files   localizing other files and localized 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.

Original address: http://www.jb51.net/article/66818.htm

iOS localization ideas for multiple languages

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.