IOS Reading notes-internationalization

Source: Internet
Author: User

吐槽一下:国际化-我想说学习的这个工程好痛苦。或许是百度的原因,总是不能找到自己想要东西。找到的内容不是不详细就是时间有点久了。让我这种小白很头痛。

The entire process is documented below.

What is internationalization?
In other words, the app displays different words in different languages, that is, if you are an American system language is English, then the app will display English, if you are Chinese, then the app will display Chinese.

Let's start with international preparation.

To facilitate our presentation below, just add a simplified Chinese to the line.
Jump out of the screen below

Click Finish, as for the two files we selected above we said below.
We can choose or not to choose, but if it is not selected just add the language will not be added.

Well, the following class of instructions how to internationalize.

1. Internationalization of App Name
Our newly-built project is called "Chinese" in the Chinese language environment and the English language is displayed.
New in supporting files file (other places are OK, doesn't matter)

The name of this file must be used infoplist.

Click the new infoplish.strings



Select the language you want to be compatible with
After selecting the good
Add in Infoplist.strings (Chinese (Simplified)) file
Cfbundledisplayname = "Chinese";
Added in Infoplist.strings (中文版) file
Cfbundledisplayname = "中文版";

All right, it's done.
Run it, try it.

2. Internationalization of text information
Follow the above method to add a strings file, this time we are called localizable (must call this name).
Add the language according to the above method. Finally for such

Let's see what I should do.
We want to add a Uilabel to the page in the Chinese context, the text is "Chinese" and the English context is "English".

Let's add the following code to the VIEWCONTROLLER.M Viewdidload method

UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(100100100100)];    label.text = NSLocalizedString(@"Title", @"1");    [self.view addSubview:label];

There is a new method in the code nslocalizedstring, this method is the key, the first method is key, the second method is the default value. We need this key. This method will go to the Localizable.strings file to find the corresponding value.
Now this key is "Title" so we're going to add a value to localizable.strings.
In the Chinese file under Localizable.strings, add:

"Title""中文";

In the English file, add:

"Title""英文";

The two keys here must correspond, or they will not be found.

Run for a try.

3.xib and Storyboard file internationalization

We will encounter this situation in the internationalization process, that is, we dragged to Xib and the storyboard of a lot of controls, the above text is written, we do.

Remember the two files we chose when we first added the language? I said next. That's it.

Let's say it now.
If you had chosen it, it would be like this.

We drag a Uilabel control onto the page and set the text. We want to display different words in different language environments.
Click the control
Do you see the object ID? We'll use it now.
Add the appropriate content under the. strings (language) file for the corresponding xib or story version.
Add under the Chinese file

"aLA-Na-IKQ.text"="中文";

The control will display "Chinese" in Chinese.
Add in English

"aLA-Na-IKQ.text"="English";

English environment will show "Chinese"

All right, run and try.

4. Internationalization of the picture.
Different images may be displayed in different environments.
OK below we drag a picture into the project and then click

Or the same as above, choose a good language.

This will be the case when done.
If you want to Chinese pictures do not use this, for another, then we click on the image of the Chinese version of the right button, select Show in the Finder will be in the folder to delete the image and then will be changed to add the picture, note the name to be the same as the original.
Okay, run and try.

5 The internationalization of sound
As with the internationalization of the image, let's look at how to take the value.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    // Override point for customization after application launch.    NSBundle *thisBundle = [NSBundle mainBundle];    NSString *path = [thisBundle pathForResource:@"蓝莲花" ofType:@".mp3"];    NSLog(@"path=%@",path);    returnYES;}

The files in the corresponding language file are removed.

path=/Users/darknesswz/Library/Developer/CoreSimulator/Devices/20C6C60B-35BC-4C3E-B7E9-6D931EBA2C0F/data/Containers/Bundle/Application/9E28AFA6-5B32-4C65-AA39-883DD3DFFD08/YY.app/zh-Hans.lproj/蓝莲花.mp3

Although the name is still "Blue Lotus" but I in the document content has replaced Xu Wei's "hometown".

Well, it's not easy. It's a little bit more useful.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

IOS Reading notes-internationalization

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.