What is localization processing?
Localization processing is where our applications are likely to be published in many countries of the world, because the language used in each country is different, so we need to localize the language of our application.
What files do I need to process for localization processing?
(1): Localized application name (my project name)
(2): Localized string processing (strings involved in the project)
(3): Localized image
(4): Xib file localization processing
(5): Other documents
The following localized processing:
1. Set up our engineering support for multiple languages
Why: Because it's only set to support multiple languages, we can toggle the language between displaying the project name and the string in the project.
(1): First create a project, with "Apple" for the project name to do the test
(2): To add a supported language for the project, only the project has the language we want to use, we can tell the project to switch to this language
:
2: Set project name localization processing
(1): Infoplist.strings file is managed by the name of our application
(2): Set Infoplist.strings is actually very simple, is to use the language environment we set up in the previous step, add the language we want to support under the Infoplist.strings file.
(3): Add procedure:
(4) Next we just need to write the Cfbundledisplayname property and its corresponding value separately in the file we created under Infoplist.
For example:
In Infoplist.strings (中文版) We write: Cfbundledisplayname = "Apple";
In Infoplist.strings (Chinese (Simplified)) We write: Cfbundledisplayname = "Apple";
In Infoplist.strings (中文版) We write: Cfbundledisplayname = "リンゴ";
Note: The following "" does not precede the @
(5): Add a property in the Info.plist file application has localized display name and then set the Boolean type to Yes.
(6): Change the language of the emulator in the simulator to see the following three effects:
3: Localized string processing (strings involved in the project)
Tip: Localized string handling and project name localization processing in 2 is basically the same, except that we need to create a file like the Info.plist file to manage our localized strings
is to create a localizable.strings file, and then create multiple support languages under this folder.
(1): The way to create a localizable.strings file is the same as the one created above info.plist, except the file name is not the same
(2): Add supported languages under the Localizable.strings file
:
(3): Then we have to add the following files to each file in localizable.strings similar to this:
For example:
Localizable.strings (中文版) "Login" = "Login";
Localizable.strings (Chinese (Simplified)) "Login" = "Login";
Localizable.strings (Japanese) "Login" = "Deng registration";
Then someone might ask us how the "Login" was determined before each equal sign? : Look Down
And then how do we use it?
Is that every time we use the string we set we don't have to nsstring, we need to use a function instead of it: nslocalizedstring (key, comment)
For example, we're going to set the subject on a button: Button.title = nslocalizedstring (@ "Login", nil);
This @ "Login" will be automatically retrieved in the device in the same language Localizable.strings folder, and then found in the same as @ "login" the same key value, and then output
In fact, we're in localizable.strings. The contents of the folder are like a dictionary, preceded by the key value is the corresponding value, and then through the nslocalizedstring (@ "Login", nil), the function is retrieved, Return the value corresponding to the key.
Some people will nslocalizedstring (key, comment) in the comment is what, it is obvious that according to the meaning of the annotation is a comment
:
Summarize:
In fact, it is very simple, we set the localizable.strings below the language we need, and then we are in the project to use the string used in "three" = "3", the form of the various corresponding files, And then if we use the string we need, we'll go through the nslocalizedstring (key, comment) function to find the value in the form of the key value, and then show the value of the language we set ourselves, which is the localization process
Wen/Mountains (Jane book author)
Original link: http://www.jianshu.com/p/b053bbd8c339
"Self-supplement"
If your own application needs to do a language switch locally, the implementation logic is as follows
1. Language of the configuration
#define LANG_EN @ "en" #define Lang_zh_hans @ "Zh-hans" #define Lang_zh_hant @ "Zh-hant"
The following method Languagecode: This is the value of the other languages do not elaborate
2. Calling the appropriate language string from the currently selected language
/** * Get internationalized String Value * * @param key < #key description#> */-(nsstring*) Localestringwithkey: (nsstring*) key{ //Get The language code. NSString *languagecode = self.language; Get the relevant language bundle. NSString *bundlepath = [[NSBundle mainbundle] Pathforresource:languagecode oftype:@ "Lproj"]; NSBundle *languagebundle = [NSBundle Bundlewithpath:bundlepath]; Get the translated string using the language bundle. NSString *translatedstring = [Languagebundle localizedstringforkey:key value:@ "" Table:nil]; if (Translatedstring.length < 1) { //There is no localizable strings file for the selected language. translatedstring = Nslocalizedstringwithdefaultvalue (key, nil, [NSBundle Mainbundle], key, key); } return translatedstring;}
IOS language switching, localization, internationalization