IOS localization advanced tutorial

In the last introductory tutorial, we covered the most basic localization methods, and now we’re going to look at two specific localization cases.

XIB and storyboard localization

XIB and Storyboard are two different types of UI tools that allow us to get rid of the trouble of code layout. Their localization can be done either by modifying the code using the method in the last article, or by localizing the XIB and Storyboard files directly. Operate Localize operations similar to strings files, as shown in the following figure

Once the file is selected, click the Localize button in the right sidebar and check the language.

So we find that in the Storyboard file, there is a Chinese version of Strings file, which is as follows

/* Class = "UILabel"; Text = "user name "; ObjectID = "8f2-qK-7KS"; */ "8f2-qk-7ks.text" = "username "; /* Class = "UIButton"; NormalTitle = "Login or Register "; ObjectID = "ENI-bN-wSs"; */ "eni-bn-ss. normalTitle" =" Login or register "; /* Class = "UIButton"; NormalTitle = "Last step "; ObjectID = "IGn-o3-iJc"; */ "IGn-o3 -ijc.normalTitle "=" last step "; /* Class = "UILabel"; Text = "user name "; ObjectID = "YHI-In-kPq"; */ "yhi-in-kpq. text" =" user name "; /* Class = "UIButton"; NormalTitle = "Login or Register "; ObjectID = "hzS-mR-s9E"; */ "hzs-mr-s9e. normalTitle" =" Login or Register "; /* Class = "UILabel"; Text = "title "; ObjectID = "rjb-sh-ADV"; */ "rjb-sh-adv.text" = "title "; /* Class = "UILabel"; Text = "title "; ObjectID = "wxc-43-QK7"; */ "wxc-43-qk7.text" = "title "; /* Class = "UIButton"; NormalTitle = "User Usage Agreement "; ObjectID = "xdy-gJ-fv1"; */ "xdy-gj-fv1.normalTitle" = "User Usage Protocol ";

English is the basic language for project setting, and storyboard content is directly used. The localization of Chinese is controlled by this strings file. Is it very simple?

Localization of Info.plist

The second special localization requirement is to localize the Info.plist file. The most common usage scenarios are:

  1. Localization of App Name

  2. Localize the request prompt

We know that the default localization file name is called Localizable. Strings, and the info.plist file also has its own localization file called InfoPlist. Strings

This file needs to be added by the developer. Once we have added it, we will add the ‘CFBundleDisplayName’ key to the Info. plist. This key determines the name of the application to be displayed.

Next, write the localized index in the InfoPlist. Strings file. Note that there are no quotes around the cfBundleDisplayName. This file is designed to localize the info.plist file.

CfBundleDisplayName = "Your software name "; NSLocationAlwaysUsageDescription = "I need to use mobile location services, please authorize";

NSLocationAlwaysUsageDescription key value is the location service authorization when the clues. This localizes the Info. plist file, isn’t it easy?

This is the end of our localization teaching. Please leave a message if you have any other questions.