IOS app internationalization learning records

Source: Internet
Author: User

Sometimes there are multiple languages involved in the product, so you need to set up internationalization. Now, record it. First, if you want to internationalize the product, select Localizations in info under the PROJECT, and click the + number, in this way, the international language version can be added.

After the settings are complete, there will be two more files under your InfoPlist. strings.

 

Then, you can set some relevant information here.

For example, the program name

 

// Simplified: CFBundleDisplayName = Chinese app; // English: CFBundleDisplayName = en-app;

In the simulator, you can change the language by setting-universal-multi-language environment-language.

 

 

Localized content:

New File... --> Resource --> Strings File. In many tutorials, the File name must be Localizable. strings. Otherwise, it cannot be identified. Actually, it is not. Here we use another method to set the name to MyLocalization. strings.

 

Then, set the desired field in the corresponding MyLocalization. strings Chinese and English environment, and use NSLocalizedStringFromTable to retrieve the desired text.

 

// Chinakey = Chinese content; // enkey = en;


 

 

UILabel * label = [[UILabel alloc] init]; label. frame = CGRectMake (20, 40,250, 60); label. text = NSLocalizedStringFromTable (@ key, @ MyLocalization, nil); [self. view addSubview: label]; UIView * view = [[UIView alloc] initWithFrame: CGRectMake (20,100,250, 60)]; // judge the current language type NSArray * ages = [NSLocale preferredLanguages]; // obtain the language type NSString * currentLanguage = [ages objectAtIndex: 0]; if ([currentLanguage is1_tostring: @ en]) {view. backgroundColor = [UIColor yellowColor];} else {view. backgroundColor = [UIColor redColor];} [self. view addSubview: view];

If you want different language Environments to correspond to different images, you can also set them. For details, see

 

If you want to change the image, you just need to right-click showFinder and replace it with an image with the same name. Haha ~~

 

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.