Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
376 views
in Technique[技术] by (71.8m points)

ios - How to set language other than English as the development language and Base localization?

When an Xcode project of iOS app is newly created, in the project (not target) setting we can see that it has Use Base internationalization enabled by default, and there are 2 files localized for the Development Language which is English by default (one for Main.storyboard and one for LaunchScreen.storyboard, both of which reside in the Base.lproj directory). See below the screenshot:

Xcode default project localization setting

(For simplicity, I will only mention Main.storyboard from now on.)

And in the localization section of Main.storyboard's right-side panel, we can see that the Base localization is checked by default and there is also an English localization which is unchecked by default. See below the screenshot:

storyboard default localization setting

And in the target's Info.plist, there is a key named Localization native development region (i.e. CFBundleDevelopmentRegion), and its default value is en. See below the screen shot:

Localization native development region

If I understand it correctly, with these default settings, developer can just write English in the Base localization of Main.storyboard and leave the English localization as unchecked. If the app needs to adapt to some other language, developer can add a localization in the project localization setting, and select Main.storyboard in the popped up dialog. See below the screenshot:

add localization

Take Chinese (Simplified) as an example, this will result in a newly created directory zh-Hans.lproj with a Main.strings file inside it. (For simplicity, I will refer to it as Chinese instead of Chinese (Simplified).) Developer just needs to translate the English strings inside this file into Chinese (the newly created Main.strings in the zh-Hans.lproj directory by default has all the English texts duplicated from the Main.storyboard in Base.lproj). With these settings, the Language field in the description of this app on AppStore will list English (from the Base localization, because English is the development language) and Chinese (from the Chinese localization). On end-user's device, if the system language is English/Chinese (or English/Chinese is among the preferred language), the app will use the corresponding language resource (for English, use the Base localization; for Chinese, use the Chinese localization). For all other language preference, English will act as the fallback language because CFBundleDevelopmentRegion is en, so Base localization is used.

So my first question will be, is the above understanding correct? To summarize, with the development language being English, we don't need to enable English localization for storyboard files. Just use the Base localization and directly write English in the storyboard files. We only need to add localization for languages other than English. (Actually it seems troublesome if we enable the English localization. If English localization is enabled, then we need to maintain both the texts in Base.lproj/Main.storyboard and en.lproj/Main.strings.)

If the above understanding is correct, my second question will be, how to achieve internationalization in a reverse way? That is to say, if I would like to use Chinese as the development language and write Chinese in the Base localization, and only add localization for languages other than Chinese, is it possible and how to do that in Xcode? I can't find a way to change the development language in the project setting in order to claim that the Base localization in the project is Chinese rather than English.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your understanding is mostly correct. One small clarification: if the user is running in some third language, like Russian, it is not necessarily true that the app will run in English. Instead, the app will run in the first language it supports that the user prefers. As of iOS 8 and later, users can have a list of preferred languages, such as "Russian, French, Chinese, English". In the case of this hypothetical user, the app would actually run in Chinese, since it is earlier in the list than English.

To answer your question regarding changing the development language, this isn't straightforward to do but can be done. Specifically:

  1. Add the language you want to be your Base language first. Uncheck all of the files that Xcode offers to localize for you.
  2. In the Info.plist (as you observed), change the development region to the language that you want to be your base language. Note that the property is a bit misnamed, because its value should be a language code (with an optional country code), rather than a region or country code.
  3. Close your project in Xcode. In another code editor, open projectname.xcodeproj/project.pbxproj and search for developmentRegion. You should see a line like developmentRegion = English;. Change this to reference the same language you put in your Info.plist file.
  4. Reopen the project in Xcode. Go through all your localizable files and check the boxes next to English to generate the localizable resources. Note that for storyboards and xibs, Xcode might create a storyboard instead of a strings file. If that happens, just change the filetype to strings file.

Here's an example of the result for me using fr as the Base language:

Project info

File info


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.8k users

...