APP string & XIB & image resource localization in xcode4.5

Source: Internet
Author: User

Reference

[1] http://www.raywenderlich.com/2876/how-to-localize-an-iphone-app-tutorial

In addition to app name localization, app localization also includesUse text localization, XIB resource localization (buttons, etc.), and image resource localization, This article introduces the localization of the three

1. Use text Localization

1) Right-click the project file, select "new file", and select string file to create the localizable. Strings file.

1.1) If nslocalizedstring is used, you must use the localizable. Strings file name,

Because # define nslocalizedstring (Key, comment )\

[[Nsbundle mainbundle] localizedstringforkey :( key) value: @ "" table: Nil]

The value passed by table is nil, which is the default table, and the default table is localizable. Strings.

If it is changed to another file name, such as XXX. Strings, use nslocalizedstringfromtable (@ "key", @ "XXX", nil); for localization. XXX has no suffix. Strings

1.2) if you need to use localized files from other directories, you may not want to determine which localization to use based on the language of your mobile phone, but want to use the switch to control it.

You can use nslocalizedstringfromtableinbundle to create nsbundle according to the target directory. In addition, bundle is actually a directory.

# Define nslocalizedstringfromtableinbundle (Key, TBL, bundle, comment )\

[Bundle localizedstringforkey :( key) value: @ "Table :( TBL)]

Nsstring * result = key; static nsbundle * bundle = nil; static dispatch_once_t oncetoken; dispatch_once (& oncetoken, ^ {bundle = [[nsbundle bundlewithpath: bundlepath (path is only a directory)] retain] ;}); If ([key length]> 0 & bundle) {result = nslocalizedstringfromtableinbundle (Key, XXX (no suffix. strings), bundle, nil );}

2) Create Chinese localization for localizable. Strings

3) In localizable. Strings (Chinese), modify the title and key fields and set the language of the device to "Chinese". The result is as follows:

2. Localization of XIB Resources




3Localization of image resources


Then use an image with the same name but different content in EN. lproj and zh-Hans.lproj.


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.