First, the internationalization of the preparation of the process:
1, first we have to create a project, we give him the name Internationalization-demo, and then add the language.
To detach text from your code:
Currently, all the text shown in the app is in Main.storyboard and viewcontroller with hard-coded strings. In order to localize these strings, you need to put them in a separate file. Instead of hard-coding in your method, he will simply refer to these strings in the package.
Xcode uses files with the. strings extension to store and retrieve all the strings used in the app to support each language. Depending on the language currently used by the iOS device, a simple method call in the code will find and return the required string.
2. Create a file with a. strings extension
Open File > New > File, select Strings Fils in Resource,
Click Next, name the file infoplist.strings, and then click Save.
3. After creation, you can see the project directory structure file as follows, click Infoplist.strings, view the properties on the right, and add the language in the localizable bar.
4. After adding, open the corresponding language files, such as
Add to 中文版:
Cfbundledisplayname = "Hello World";
Additions to the Chinese:
Cfbundledisplayname = "Hello World";
5, run, if your simulator is in Chinese, you will see your program name into the world hello in the settings to set the language into English, you will see your program name into the Hello Worlds
Ii. Internationalization of content
1. Create a new Localizable.strings file (Localizable.strings is the system default name)
2. Add language Ibid.
3. Add language content
In Localization.strings, follow the format of "key" = "value" and then use Nslocalizedstring (@ "key", @ "") to read the contents; If it is not used with the system default name
Localization.strings 中文版 File added
"Key" = "Hello World"
Localization.strings Chinese file added
"Key" = "Hello World"
Internationalization of iOS Apps