IOS Internationalization nslocalizedstring

Source: Internet
Author: User

IOS internationalization. Automatic switching based on different languages of the system.

First of all. Select Project Add new file-->ios-->resource-->strings file. Named Localizable.strings

Open localizable.strings. It's formatted like this.

"KEY" = "CONTENT";

Please write in this format, for example I am here to define

"TestKey" = "qingjoin_english";

And then. We return to the corresponding code.

NSString *str2 =nslocalizedstring (@ "TestKey", nil);

NSLog (@ "%@", str2);

This is the most basic can be. You can run it first.

Then add a new supported language

Select Xxx.xcodeproj. Then click Info. (Note, this is not targets info), find below localizations point + For example I here choose Chinese (Simplified)

Then go back to localizable.strings. Select it. Move to the right navigation. Click Localization. Add the Chinese (Simplified) that you just added in.

Then go back to the left of the localizable.strings will find that there is more than one file. Then. You only need to modify the corresponding value in the corresponding key. The localization is achieved

I add the following code in the Chinese version of the file (localizabli.strings (Simplified))

"TestKey" = "Qingjoin_chinese";

When the language of the system is Chinese. The output of the str2 is Qingjoin_chinese.

If the system language is English str2 output is qingjoin_english

Sometimes you can add something else.

NSString *str1 = [NSString stringwithformat:nslocalizedstring (@ "Testkkk%@", nil), @ (1000000)];

The key in *.strings is

"Testkkk%@" = "chinese%@";

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.