IOS applications are internationalized in three parts:
Info. plist file Internationalization
Internationalization of. xib files
. M file Internationalization
I will explain it one by one.
Info. plist file Internationalization
We use Xcode 4.5 to create a new project, and an en. lproj directory will be automatically created, which stores the files to be internationalized (English by default ). Next, we also need to create Chinese internationalization support.
1. Create a directory named zh-Hans.lproj
2. Add Localizations in the Info. plist file of the project, and add support for English and Chinese: English, Chinese (simplified)
3. Copy en. lproj/InfoPlist. strings To The zh-Hans.lproj/InfoPlist. strings file.
4. Add the zh-Hans.lproj directory to the project. Select Add to targets.
5. Select File-> Info-> Localization as the corresponding language.
In the InfoPlist. strings file, we can internationalize some application information, such:
CFBundleDisplayName: Application display name. In this way, the application names in different languages can be displayed.
For more information about fields, see
Http://developer.apple.com/library/ios/#documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
.
Internationalization of. xib files
We have created an English xib file under en. lproj. Then, you need to use the command line to operate:
1. Extract the text from the. xib file and save it as the. strings file.
Ibtool -- generate-strings-file MainViewController. strings MainViewController. xib
2. Copy MainViewController. strings To The zh-Hans.lproj directory, and then write the text in the file
3. Execute the command to generate a chinese. xib file based on the English. xib file and. strings Chinese file.
Ibtool -- strings-file zh-Hans.lproj/MainViewController. strings -- write zh-Hans.lproj/MainViewController. xib en. lproj/MainViewController. xib
4. Add the generated. xib file to the zh-Hans.lproj group in the project, be sure to select Add to targets
5. Select File-> Info-> Localization as the corresponding language.
Now, the xib file has been finished in Chinese.
. M file Internationalization
1. In the code, all texts that require internationalization use the NSLocalizedString function, for example
NSLocalizedString (@ "hello_world", @ "Hello world! ");
2. Execute the command to extract all the text to be written in the. m file and put it in the en. lproj folder.
Genstrings-o en. lproj *. m
The Localizable. strings file is automatically generated. Then copy the file to the zh-Hans.lproj folder. This file is the content that needs to be written in Chinese.
3. Add the. strings file to the corresponding Chinese directory in the project. Select Add to targets.
4. Select File-> Info-> Localization as the corresponding language.
Then, we run the program. By modifying the system language, we found that the file display name,. xib file, and. m file can be automatically switched to the display language.