I was wondering if somebody could explain in the details how I can localize an iOS app using only 1 storyboard. I know how to localize by creating several storyboards(one storyboard for each used language), however I'd like to find out another solution.
Thanks.
The tutorial on raywenderlich.com uses two forms of localization together. The reason is he also checks the storyboard when turning on localisation in image 3:
.
So then what?
NSLocalizedString is very useful, any text set programatically can (and should) be localised using this method. Ray's tutorial is still very useful.
However, it's not very desirable to create a clone of the storyboard(s) to do translation, it's just not very maintainable in the long run.
And what about storyboards?
The magic happens using the Base Localization feature. Base localization uses the generated objectId's to 'map' different languages to the storyboard.
Do note that this feature is only available using SDK 6.0 and above. Running the app on a lower iOS version will not cause any errors, it'll simply won't work.
Go to your project, and select Base Localization, then add any other language.
Open your storyboard file and check the new language as well. Note the icon is not a storyboard icon, but a simple text file icon. That's a good thing; it won't copy the whole storyboard this time :).
Note how there is now another file 'under' the storyboard. Xcode automatically generates a file for every language you select.
You can se Localization feature for this. You need to add the Localizable.strings file for each supported language and use it for locaization.
You need to use : NSLocalizedString() for fetcing data corresponding to each key.
Check this tutorial for details.
Related
TLDR: Xcode generated storyboards for each language, however I want the "old"(?) *.strings files. How?
I am currently in the process of localising my storyboards. After I enabled everything, Xcode generated another storyboard alongside the original (english) one for me to localise. I was surprised, I expected a Localizable.strings file, like the apple documentation still states as of April 3, 2021:
For storyboard and XIB interfaces, select the user interface files (files with a .storyboard or .xib filename extension). Xcode adds a strings file to the localization folder that contains the text to translate, as well as comments that describe the user interface components. For example, if you add German to an iOS app that uses storyboards, LaunchScreen.storyboard becomes a group containing a LaunchScreen.storyboard (Base) and LaunchScreen.strings (German) file.
I searched around the internet, in apple developer forums, watched both WWDC18 and 19 talks about localisation in Xcode, but did not find a single mention of translated storyboards.
After the initial translation, which works great due to the simplicity of just filling everything in, it gets frustrating however, since every layout change needs to be repeated for every language. This can't be intended, there must be a better way, right? Sadly, I didn't find anything. Even a hint to a piece of documentation regarding these storyboard copies would be greatly appreciated. Thanks!
There are some screenshots of the possibility to convert these two formats via a dropdown, like the third picture in this post. However for me, there is no dropdown next to the language item when I click the storyboard, neither on the group, nor individual base or localised ones:
Is this a bug or am I missing something here? I am using macOS Big Sur 11.2.3 with Xcode 12.4 (12D4e).
Turns out, you need to use the Base Localization feature, the dropdown then appears and you can convert existing storyboards to *.strings files.
I have Googled this for hours but could find no advice for the following problem (using Swift).
I have seen in many apps an option to select the language from inside the app like this:
(source: unity3d.com)
I would like to achieve something similar, but am having trouble implementing it. I have localized my app and have my Localizable.strings files all set up. I'd imagine it has something to do with storing the language selected in NSUserDefaults, but how can I make the app use the appropriate Localizable.strings file once a language has been chosen? Or is that the wrong way to approach it?
How have others successfully implemented this feature in Swift?
I've already faced this issue on one of my project and found one solution :
When the user select a language from a list, post a NSNotification. All your UIViewController subclass must register to this notification and change the labels value according to the new language selected.
You can use the localized strings in order to set the labels, but NSLocalizedString(...) shouldn't be called since it's relying on the device language which is different from the application language.
You can find my implementation of a custom localisator on Github, available both on Swift and objective-C.
I have searched now quite a bit on Stackoverflow for an answer, but I can't seem to find an adequate one.
So, I am localizing an App with XCode. Everything works fine, I have localized a storyboard and everything. The last part which needs to be localized are the labels and buttons in XIB Files. Here I have the following Problem:
XCode Offers me to create localized Xib Files for every language or to create strings files. Both options are fine with me, but none seems to work. One answer to a similar question stated that this does not work my design. If so, why does XCode give me the option to do it in the first place? And, what is a good and easy solution for this?
And I am using Swift, not sure if that really matters, I just thought I mention it.
There is a known issue with recent versions of Xcode where the simulator would not correctly pass the language information to the app, so it seemed as if localization was not working. If that is your problem, there are two workarounds:
try your app on a device and confirm switching the language brings up your localized strings.
force the language via your build scheme (Product => Scheme => Edit Scheme... => Run => Application Language)
What are pros and cons of using Xcode base internationalization?
Maybe it's easier to use just NSLocalizedString and set titles, labels, buttons in code?
Base internalization is a much better idea than manually setting things in code. It is much less work both to implement originally and to maintain. You just add the .strings file for a language and then edit it to translate all the strings in your UI. With NSLocalizedString you have to do this as well, but in addition you need to write special code for every UI element with a string. If you add or remove a UI element, you need to write code again. Using NSLocalizedString is probably also less efficient at run time. Your app has to completely load the UI for your development language and then go through and change all the strings in the UI to the localized versions.
There really are not any cons to using base internalization except for legacy considerations:
It requires iOS 6 or Mac OS X 10.8 or newer.
Converting a legacy project with separate .xib or storyboard files for every language can be a pain since you need to convert to auto layout. (The string extraction can be done automatically by Xcode.)
I know how to turn on storyboard's localization. The problem is I don't know how to sync all localizaion storyboards, after main (English) storyboard is modified.
Is there any shortcut to sync them? Do I have to do all those modifies again and again in over TEN language storyboards?
My condition is: I have a project with over ten localizations. After I released it on AppStore, we have new user requirements.Then, we start program next version app. After I completed tons of improving and creating on stroyboard, I feel desperate to facing other language storyboards.
If you are using iOS version >= 6 (and Xcode >=4.5), you can use a single storyboard for multiple languages, i.e., do base localization + the usual string localization. Doing so, you have only to care about the localized strings in string files.
For a guide, see e.g. here.
If you're targeting iOS 6.0, you can use Base.lproj like Matthias mentioned.
If you're targeting a release prior to 6.0, you can use ibtool's localization merging features. They works for NIBs, XIBs and Storyboards. You can invoke them like this:
ibtool path-to/development.storyboard --local-
ize-incremental --previous-file path-to/development-storyboard-localization-was-based-on.storyboard --incremental-file path-to/previous-localized-storyboard.storyboard--write path-to/updated-localized-storyboard.storyboard
What that does is open development.storyboard, copies it, and the compares all localizable properties between path-to/development.storyboard and path-to/development-storyboard-localization-was-based-on.storyboard, if those properties are the same, the counterpart value from path-to/previous-localized-storyboard.storyboard is copied forward to path-to/updated-localized-storyboard.storyboard, otherwise the current development value is left in place.