How to set Base Localization & Development Language in Xcode 12(.5)?
What I wanted to achieve:
Support English but use German as the default language that is also used if the user's language settings don't include English or German.
How I achieved this in Xcode 12.5:
- Add "German (de)" to the "Localizations" list via the little "+" button. In the new
Choose files and reference language to create German localization
pop-up every storyboard file should already be ticked by default. This adds.strings (German)
localization files for all storyboards in the Project Navigator on the left:
- In
Main.storyboard
's File Inspector tick the "English" box in the "Localization" section (this might take a while). This adds an additionalMain.strings (English)
file in the Project Navigator. Repeat this step for each storyboard, including the launch screen.
- To change the "Development Language", which is the language the app uses by default and also if it doesn't support any of the languages the user set in their device's language settings, close Xcode, then open the project's
.xcodeproj
file with a text editor (I used BBEdit, which is free). There should be a list of files, includingproject.pbxproj
. Open it and setdevelopmentRegion
(= development language) to the language code of the language that you added in step 1, so in my case "de". Do not use a different code (e.g. add "German (de)" but set it to "de_CH") because that's going to create an additional localization.
- There are now two ways to finish this part of localization:
- A. Leave it as is. Changes in storyboard aren't going to affect any of the
.strings
files. Advantage: The text can be edited directly (without using storyboard), which is useful if you aren't the person who's working on the translations. Disadvantage: You can't quickly see and test the changes to a translation in storyboard but have to run the app in the simulator or on an actual device.
- B. Use the default language as "Base" language: Untick "German" for every storyboard and hit "Remove" in the pop-up, which removes the localizations in the list. This way changes to the storyboard affect the default language, which makes it easier to test changes.
I used version B:
Important:
These .strings
files are only used for storyboards! If you also want to set localized text at runtime using NSLocalizedString
(e.g. for an error dialog), then you have to add an additional Localizable.strings
file (more details here):
File
-New
-File
-Strings File
- Call itLocalizable.strings
- Click "Localize" in its File Inspector and pick one of the languages you want to use in code.
- Afterwards, also in the File Inspector, you can tick the other languages in the "Localization" section (including the development one).
Bonus infos:
You can change the app language of the simulator through the scheme:
Product
- Scheme
- Edit Scheme
- Run
(left side) - Options
tab (right side) - App Language
You can also show a preview of the currently selected UIViewController
and change its displayed language without starting a simulator:
Editor
- Preview
- In the new preview window on the right there's a button in the bottom right
Disclaimer: I found this solution by testing different things, as there's currently no tutorial for this (using the latest Xcode version). If this is not the "right" way to do localization, please post your own answer and I'll check it out.
How to set language other than English as the development language and Base localization?
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:
- Add the language you want to be your Base language first. Uncheck all of the files that Xcode offers to localize for you.
- 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. - Close your project in Xcode. In another code editor, open
projectname.xcodeproj/project.pbxproj
and search fordevelopmentRegion
. You should see a line likedevelopmentRegion = English;
. Change this to reference the same language you put in yourInfo.plist
file. - 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:
My mac app does not change its language even after changing the Development Region on Xcode
On macOS app, you change the localization language from Edit Scheme -> Run -> App Language, which is located under the app name on the status bar. It is irrelevant to change the content on project.pbxproj.
UPDATE
Hmmm.. this seems to not work in French for some reasons. But it works in Chinese, Japanese, and Korean.
Change localizations of base storyboard to german swift xcode
I was fighting with this for a long time but finally I think I found a solution for Xcode 7.
In general If you're developing language is different than English you have to make 2 things. After you create a new project in Xcode 7 quit Xcode and go to the terminal.
Edit the file in your project folder with your favorite text editor:
vi .xcodeproj/project.pbxproj
Search for the key: knownRegions
.
You should find something similar to:
knownRegions = (
pl,
Base,
);
Put your development language code on the first position. In general position is not important but I prefer that my native language be first. In Your case put there de
. By default the first language in new project is en
.
Next you should look for developmentRegion
(in the same file) and change its value to “Polish" or whatever language you are using. In your case "Germany". What I noticed this makes Xcode to notice that your Development Language changes from English (default) to your language. After those changes save and exit text editor. Start the Xcode and point your eyes to Project -> Info tab. You should see something similar to this with Your native language set as Development Language.
Now open Info.plist
. Edit the CFBundleDevelopmentRegion
key and set its value to pl
or de
in your case.
Thats all. Now Your Base.lproj
can contain resources in your native language. If you want a new Language just add it as usual.
Let me know if it working for you. I don't know how this little trick change your current project with existing translations but this is good point if you're starting new project.
Related Topics
How to Push and Present to Uiviewcontroller Programmatically Without Segue in iOS Swift 3
How to Make Uitextview Height Dynamic According to Text Length
Retrieve Custom Prototype Cell Height from Storyboard
Swift - Problems with Corner Radius and Drop Shadow
Failed to Obtain a Cell from Its Datasource
iOS Perform Action After Period of Inactivity (No User Interaction)
How to Access Own Window Within Swiftui View
Given a View, How to Get Its Viewcontroller
Nsxmlparser on iOS, How to Use It Given a Xml File
Uitableview - Change Section Header Color
Autolayout: Removefromsuperview/Removeconstraints Throws Exception and Crashes Hard
Uiscrollview: Paging Horizontally, Scrolling Vertically
Uisearchbar Increases Navigation Bar Height in iOS 11
iOS - Calling App Delegate Method from Viewcontroller
Changing Navigation Bar Color in Swift
What's the Best Way to Find the User's Documents Directory on an Iphone