In Xcode we can easily adapt the app to a variety of localized languages. Apple's framework has helped us separate data from different languages, including images, sounds, videos, documents, user interface text (and even user-interface text written in code), which are built into the same bundle for our management.
The following are descriptions of strings, pictures, how application names are implemented for multilingual localization, and how to switch languages for testing.
as follows:
1, localized string(1) project configuration, "Info", "localizations" area, you can see the project by default only supports English, we can add the Chinese language. (When you choose to add a language, the localized files to select will appear, which we choose by default)
(2) In the project, right-click Add Files (New file ... ), select the strings file type under Resource, and the file name is defined as "localizable.strings"
(3) Select the "localicable.strings" file you just created and click "Localize ..." in the right-side properties panel to create a localized resource
(4) under the English and Chinese resources, enter the following key value pairs
| 12345 |
//英文资源里"Welcome"= "Welcome to hangge.com"; //中文资源里"Welcome"= "欢迎来到hangge.com"; |
(5) Use the Nslocalizedstring function to access the Localizable.strings resource file.
The first parameter of the Nslocalizedstring function is the corresponding key name, and the second is a custom description for the developer or translator to see.
| 1 |
myLabel.text = NSLocalizedString("Welcome", comment: "Welcome") |
2, localized image
(1) Select the image you want to localize, and click "Localize ..." as above to create a localized picture resource.
(2) Open the project directory, you can see in the Chinese language resources and English resources have this picture, the need to replace the picture replaced.
(3) Image use same as usual
| 1 |
myImage.image = UIImage(named: "logo.png") |
3. Localization of the application name
(1) To implement an app name to display a different name depending on the locale, simply create the infoplist.strings file and implement the localized resource as above:
(2) Define cfbundledisplayname values in English and Chinese infoplist.strings files respectively.
| 12345 |
//英文资源里"CFBundleDisplayName"= "hangge"; //中文资源里"CFBundleDisplayName"= "航歌"; |
4. Switch languages in Xcode
In order to debug internationalization, we can switch the system language in addition to the simulator or the real machine. You can also configure related items in Xcode so that the debug runtime previews the interface effects for different languages and locales. (1) Select "Product", "scheme", "Edit scheme ..." (2) running the project after switching languages
Internationalization and localization of Swift-ios applications