IOS internationalization. Automatic switching based on different languages of the system.
First of all. Select Project Add new file-->ios-->resource-->strings file. Named Localizable.strings
Open localizable.strings. It's formatted like this.
"KEY" = "CONTENT";
Please write in this format, for example I am here to define
"TestKey" = "qingjoin_english";
And then. We return to the corresponding code.
NSString *str2 =nslocalizedstring (@ "TestKey", nil);
NSLog (@ "%@", str2);
This is the most basic can be. You can run it first.
Then add a new supported language
Select Xxx.xcodeproj. Then click Info. (Note, this is not targets info), find below localizations point + For example I here choose Chinese (Simplified)
Then go back to localizable.strings. Select it. Move to the right navigation. Click Localization. Add the Chinese (Simplified) that you just added in.
Then go back to the left of the localizable.strings will find that there is more than one file. Then. You only need to modify the corresponding value in the corresponding key. The localization is achieved
I add the following code in the Chinese version of the file (localizabli.strings (Simplified))
"TestKey" = "Qingjoin_chinese";
When the language of the system is Chinese. The output of the str2 is Qingjoin_chinese.
If the system language is English str2 output is qingjoin_english
Sometimes you can add something else.
NSString *str1 = [NSString stringwithformat:nslocalizedstring (@ "Testkkk%@", nil), @ (1000000)];
The key in *.strings is
"Testkkk%@" = "chinese%@";