Tags: “iOS localization” “Storyboard” “Xib” “Picture” “App display name” by WYW

A recent project required “localization”, which is the process of making the app support multiple languages. Attachment: Official documents

I will introduce localized content from the following points:
  • IOS localizes Storyboard, Xib, image, app display name, copyright information.
  • Localize non-Interface Builder text.

I used storyboard and code to create the following Demo (QiShareLocalization).

QiShareLocalization

  • QiShareLocalization localization of English and simplified Chinese.
  • QiShareLocalization has a startup page, and the text displayed in the startup picture shows “QiShareLocalization” in The English environment and “odd sharing localization” in the Chinese environment.
  • The pictures displayed on the home page of QiShareLocalization are displayed as ** “Logo picture shared by Qi” in English environment and “QR code picture shared by Qi” in Chinese environment. Including the text “home”, “jump”, “odd share home” ** have done localized processing.
  • QiShareLocalization: Click the page after hopping, and localized ** “odd sharing localized text “**, picture, application name and copyright information displayed.

The Demo:

  • Simplified Chinese environment: The startup page cannot be displayed in simplified Chinese

    The startup page displays as expected (zh-Hans)

  • English Environment:

First, localization preparation

1.1 Add localization language to the project
  • You can add simplified Chinese as follows: SelectPROJECT -> Info -> LocalizationsAdd simplified Chinese (zh-hans stands for simplified Chinese)

Add simplified Chinese:

The Reference Language:

If additional localized languages are added again, note that File Types is optional:

1.2 Use the Base of the Internationalization

Checkbox: Separates text from.storyboard and.xib files

  • If not selectedUse Base InternationalizationWhen adding a localized language, multiple corresponding languages will be createdstoryboard,xib, so we can also adjust the interface layout and display content in different languages.
  • If checked,Use Base Internationalization, then when adding the language, the currentstoryboard,xibThe text is extracted and we only need to add in the corresponding.stringsChange the corresponding text in the file.

1. If “Use Base Internationalization” is not selected, the following steps and the generated file are shown:

Generated files:

  1. The steps and the generated File after “Use Base Internationalization” is selected and the File Types Interface Builder storyboard of launchscreen. storyboard is changed. As follows:

  • Generated files:

And then we can adjust the file in strings or we can adjust the Storyboard in the corresponding language to localize the Storyboard

1.3 the Reference:
  • Reference Language refers to the Language that the new Language file refers to. If the new traditional Chinese file is added, the new traditional Chinese file will be the same as the new simplified Chinese file in the project.

1.4 the File Types
  • You can choose Localizable Strings or you can use Interface Builder Storyboard

So if you do that, you can adjust the file in strings or you can adjust the Storyboard in the corresponding language to localize the Storyboard.

Two, start localization:

2.1 Localization of visible text

But for the Storyboard that started, after I made some adjustments, it didn’t work. You can actually create storyboards for different localization languages by modifying UILaunchStoryboardName = “LaunchScreen_zhHans” in InfoPlist. Strings; You can localize the Storyboard by specifying which Storyboard to start. Refer to the blog

2.2 Display the App name and copyright information of iOS localized Apps
  • Preparation: inInfo.plistAdd application display name and copyright information key-value pair.
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2018-2108 QiShare.</string>
<key>CFBundleDisplayName</key>
<string>$(PRODUCT_NAME)</string>
Copy the code

  • createInfoPlist.strings, the schematic diagram is as follows:

  • Modify the text of InfoPlist. Strings in Simplified Chinese

  • Modify the text of InfoPlist. Strings in English

  • The code in the project uses:

[[[NSBundle mainBundle] localizedInfoDictionary] objectForKey:@"CFBundleDisplayName"]; [[[NSBundle mainBundle] localizedInfoDictionary] objectForKey:@"NSHumanReadableCopyright"];Copy the code

Copyright © 2018-2108 Qishare. QiShare Localization Copyright © 2018-2108 QiShare.

To specify the appropriate locale to start a Storyboard, see the following:

To view the Keys in the info.plist file, run the following Show Raw Keys/Values command:

2.3 Image resource files of iOS localized App
  • Localized image resources:

  • Add QiShareLogo simplified Chinese localization support:

  • Select to support QiShareLogo English localization support:

  • Effect after selection:

Select the corresponding image Show In Finder to change the Localized image In English:

To get the corresponding picture in the project, use:

 [UIImage imageNamed:@"QiShareLogo"];
Copy the code

or

[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"QiShareLogo" ofType:@"png"]].Copy the code

For the localization of pictures, what I share at present does not include the picture resources in assets.xcassets. I have not found a suitable way yet. Taking a look at the posts shared by others, there are ways to specify different images to load in different localised localised non-IB text (shared in the next article). As for the localization of XIB, I will not share the details this time. If the localization is done and the xiB is added later, the localization of XIB can refer to the localization of image, which is the same.

For example: a XIB, before localization

For example, a XIB is localized

Project source: GitHub address

QiShare(Simple book) QiShare(digging gold) QiShare(Zhihu) QiShare(GitHub) QiShare(CocoaChina) QiShare(StackOverflow) QiShare(wechat public account)

Recommended article: iOS file operation introduction iOS keyframe animation iOS small game project — digital quick calculation upgrade version of iOS small game project — you say I guess upgrade version of strange dance weekly