Display of text in different languages using the Localizable.strings adaptation app in iOS

Source: Internet
Author: User

In iOS development, if you use Xib or storyboard to build an interface view, the text content that is fixed in the view can be adapted in localized with a different language. But in reality there will be dynamically loaded text, the adaptation of these words need to nslocalizedstring and other methods

    • Let me give you an example of how

The JSON data obtained from the network are mostly English such as album, Book, Software, etc., which can be displayed in the interface to call the Nslocalizedstring method when setting the text, specifically using

NSString *nslocalizedstring (NSString *key, NSString *comment)

Return NSString, the previous as the key keyword, the latter as a strings file comments for easy viewing, if I want to dynamically display album, you can use this

1 nslocalizedstring (@ "Album"@ "localized kind:album" );

Then, after setting the localized method of the text, call the command line to generate the Localizable.strings file, as follows:

CD ~/desktop/oc_test/storesearch/storesearch into the project catalog

Genstrings *.m-o zh-hans.lproj The last folder for different languages

After that, the. strings file is automatically generated and added to the Xcode project to modify the original English language in the file.

    • Attention

Each time the genstrings command is called, the strings file is re-created to overwrite the original content, so it is best to create the strings file after implementing the Nslocalizedstring method for all dynamically loaded text in the file;

Of course, it is also possible to back up the original content.

Display of text in different languages using the Localizable.strings adaptation app in iOS

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.