Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 561
goodbyeera Avatar asked Nov 27 '15 07:11

goodbyeera


People also ask

How to add another language in Xcode?

Select your project file in Project Navigator, and select your project in the project and targets list. Open Info tab, and click “+” button under Localizations section. Then choose a language you want to support from the dropdown list shown. XCode opens a dialog showing resources to be added for the new language.

What is base localization?

There is also a concept called a “Base” localization. Xcode will by default add a directory called “/Base. lproj” to your project. The purpose of this directory is to hold the default layouts of your views (i.e. storyboards/XIBs) in your “development language”.

What is use base internationalization?

Using Base Internationalization. Base internationalization separates user-facing strings from .storyboard and .xib files. It relieves localizers of the need to modify .storyboard and .xib files in Interface Builder.


1 Answers

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

like image 92
lensovet Avatar answered Sep 20 '22 17:09

lensovet