- Summary
- XCode will create a sub folder end with extentions .lproj for a supported language.
- NSLocale
Cocoa Touch provides an interface to get current locale.
- NSLocalizedStrings
If you want to support multiple languages, you must use NSLocalizedStrings to load string instead of static string, ie.
Replace the following statement
NsString *strName = @"Title";
with
NSString *strName = NSLocalizedStrings(@"Title", @"This is window's title");
- How to match localizable items
(Please read reference document in chapter Application Localization section Localization Architecture )
- ...
- Localization Details
- Localizing Nib
- Single click .xib file on Groups & Files
pane of XCode
- Press Command-I to open Info window
- On Info window, press General tab
- Click button that says Make File Localize in lower-left of the window.
Then the window switch to the Targets tab, look at the Groups & Files pane, the .xib file now has a discloure triangle next to it, click the disclosure triangle to expand it, you will find the .xib has a sub item named English, this is development base language; Go to Finder, you will find a new folder called English.lproj under the project folder, Rather than Apple's localization convention of using ISO language/region code, XCode still use legacy project name for the development base language, so you need to change English.lproj to en.lproj.
- Repeat steps 1 ~ 3 to open Info window again
- Click button that says Add Localization, a sheet will drop down and ask you to ener the name of the new localization (Don't select language from drop-down menu, as that will use legacy name, we can input ISO language code instead). ie. enter 'fr' for French. Then XCode will create a new localization project folder end with entensions .lproj in your project folder, such as fr.lproj for French, and copy the .xib file there.
- Now .xib file on Groups & Files
pane in XCode has 2 sub items, English and fr, double click one of them to open the .xib file in Interface Builder, then double click UI elements to enter translated label.
- ...
- Localizing Images
(Similar to Localizing Nib)
- Single click image file (such as icon.png) on Groups & Files
pane of XCode
- Press Command-I to open Info window
- On Info window,
pre General
tab
- Click button that says Make File Localize in lower-left of the
window.
- Repeat steps 1 ~ 3 to open Info window again
- Click button that says Add Localization
- Use Finder to copy localized image to the proper .lproj folder under your project folder
- ...
- Localizing Application Icon
(The same as Localizing Images)
- Localizing Strings File
- Launch Terminal.app in /Applications/Utilities/
- cd to the folder of your project
- run 'genstrings ./Classes/*.m' to generate strings file in development base language called Localizable.strings in current directory
- Import strings file by draggin the it from Finder to Resources folder of your proejct in XCode
- On prompt dialog,
- Uncheck Copy items into destination groups folder (if needed)
- Change text encoding to Unicode (UTF-16), otherwise, the file will look like gibberish when you open it in XCode
- Click button Add
- Then the window switch to the Targets tab, single click strings file Localizable.strings on Groups & Files
pane of XCode
- Press Command-I to open Info window
- On Info window,
pre General
tab
- Click button that says Make File Localize in lower-left of the
window.
- Repeat steps 7 ~ 9 to open Info window again
- Click button that
says Add
Localization
- Back to Groups & Files
pane of XCode, double click sub items (such as fr) of Localizable.strings to translate string items.
- ...
- ...
Reference:- Beginning iPhone Development: Exploring the iPhone SDK
Chapter: Application Localization
Page: P473~490
阅读(1324) | 评论(0) | 转发(0) |