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.
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