iOS internationalization multi-language settings

Source: Internet
Author: User

I. Create a project, add a language

Separating the text from the code:

Currently, all the text shown in the app is in Main.storyboard and viewcontroller with hard-coded strings. In order to localize these strings, you need to put them in a separate file. Instead of hard-coding in your method, he will simply refer to these strings in the package.
Xcode uses files with the. strings extension to store and retrieve all the strings used in the app to support each language. Depending on the language currently used by the iOS device, a simple method call in the code will find and return the required string.

create a file with a. strings extension, named Localizable.strings

Click the localizable.strings file and set localization in the property bar on the right.

Select a language

Tick the desired language in the Left property bar localization, and the right localizable.strings path will create two language files

Open the corresponding language file to add the code, for example:

中文版:

MessageText = "Hello World";

Or

"MessageText" = "Hello World";

Chinese:

MessageText = "Hello";

Or

"MessageText" = "Hello";

Viewcontroller.m

1- (void) Viewdidload {2 [Super Viewdidload];3UILabel *label = [[UILabel alloc] Initwithframe:cgrectmake ( -, $,214, -)];4     //gets the value of key messagetext from the language file5Label.text = nslocalizedstring (@"MessageText", nil);;6 [Self.view Addsubview:label];7}

The simulator language runs in English:

Operation in Chinese state:

Third, storyboard (xib)

Drag a uilabel,text to Beybey in the Main.storyboard

Write the code in the corresponding main.strings (Chinese (Simplified)):

"Jc2-j5-vy3.text" = "good-bye";

Jc2-j5-vy3 is the objectid of the corresponding Uilabel.

Operating results in English environment:

Chinese environment Operation:

Iv. Name of the app

Create Infoplist.strings

中文版:

Cfbundledisplayname = "中文版";

Chinese:

In the English state:


In the Chinese state:

Five, pictures

The first type:

The picture name exists in the file corresponding to localizable.strings , and the picture name is obtained by nslocalizedstring in code.

The second type:

Select the image, click the localization of the property on the right, and select the language file.

and the En.lproj file and the Zh-hans.lproj file appear in the project folder;

en.lproj files are 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

iOS internationalization multi-language settings

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.