Localize several storyboards - ios

I have a project which is relatively big, for such reason I use several storyboards. The thing is, I have not find the way to localize several storyboards in xcode. The options I see when using Base Internationalization are only related to my Main.storyboard and the LaunchScreen.storyboard files.
My app should be in english and spanish, those are the requirements. I have searched and searched but have not found the way to have .strings (english and spanish) for every storyboard, except the Main.
My storyboards are located in disk (and project structure) like this:
General_UI_Folder
Main.storyboard (with its .strings)
LaunchScreen.storyboard (with its .strings)
Subfolder1
...several .storyboards
Subfolder2
...several .storyboards
I'm using Xcode 8 and Swift 3.
I would appreciate any help, since I'm somehow new to iOS development.

You have 2 choices.
1) You localize each storyboard, using the storyboard localization system where it creates "substoryboards", 1 per language, where you change the value of labels, and other components, straight into the storyboards themselves.
You have to use this option:
2) Use the Localizable.strings files and update your view in every viewDidLoad method of your controllers.

Related

Why is my main storyboard not picked up for localisation when I add a new language?

I am starting to localise my app to other languages but when I add a new language in Xcode 9, only my launch screen storyboard is picked up for localisation not my main storyboard, I had expected both to be picked up for localisation, how do I get my main storyboard included for localisation?
Select your storyboard -> In file inspector there is a button "Localize", i believe that is what you need.
I wouldn't recommend localizing your app using Storyboard.
Why: In future, you won't be able to send a storyboard to the interpreter to translate it. It's slower and heavier. It takes more time.
Instead, there is another solution. Use NSLocalizedString to do localization. Then you will generate the file with translations and have 1 file for 1 language of the app. It's a common practice among developers and I always have been doing it that way.
Check out this tutorial it seems to be good from what I've looked through: link.

Localizing UIImages

After reading similar questions about localization in iOS - Everybody is talking about .strings files but i have different UIImage with different sizes for each country and they spread all over the app.
If I'm using the old method of several storyboards the localized storyboards will not get synced with future changes on the BASE storyboard
what is the best practice for localizing UIImages?
You can assign assets to languages.
In the project navigator, select the image file that you're loading from, and on the Utilities pane file inspector, click "Localize...".
If you are using image assets, check out this other answer:
How to localize the images in Images.xcassets?

Localization with NSLocalizedString or in .xib

I'm looking for an information that I haven't found on the Internet. I would like to know in which iOS version did NSLocalizedString appear ? (maybe it's here since the first version of iOS ?)
I also would like to know in which case using localization in the .xib and in which case using NSLocalizedString ?
I'm asking this question because I'm working on an iOS project using localization in the .xib files AND NSLocalizedString, and I don't really know why the two methods are used... (it's an old project, that's why I'm asking the first question ^^)
Last question, for a new project, which one of these two methods would be your preferred one ?
Sorry for all this questions, and thanks for the answer ! =)
Localisation using xib files is used when we want to localise elements on a UI e.g., when you want to show different images which has a localised text for a particular UIButton. You can achieve this using localised xib files.
There will be separate xib files for each language.
And when you are setting any text on the UI from you controller, NSLocalizedString.
I hope this helps.
NSLocalizedString was first available in 10.0
So I localize programmatically w/ NSLocalizedString because this way I can have all of my strings in one location.
Instead of through .xib localization generation, because with that you'll have a strings file for each xib you have.
However, if you have a .xib that you aren't modifying programmatically (i.e you don't have a custom class set as the file's owner), then you won't be able to programmatically set the NSLocalizedStrings. In which case, you will have to generate the strings files through the .xib.
Also, it is slightly more difficult to access string files associated with a .xib because it's directly connected with the .xib
NSLocalizedString exists since iOS 1.
Basically you need NSLocalizedString for all dynamically created strings.
In a new project I'd recommend AutoLayout and Base Localization.
There is one .xib file and all localizations – and layout adjustments – are performed at runtime via .strings files
Probably this question is dead but I jumped here searching for a method to localize xib strings and this page was the first result.
You can use both NSLocalizedString and xib. Have a look a this answer:https://stackoverflow.com/a/21443515/907720 discussed in detail here: https://medium.com/zendesk-engineering/ios-how-to-add-adaptive-constraints-to-support-a-universal-app-273663475b12

Localized Storyboard: How to add new content?

I just started to use Localization in my app. I now see that there are multiple "MainStoryboard.storyboard" files, for each language one. I can easily change the text.
But what happens when I want to extend the storyboard with a new view? I expected it to be duplicated into all storyboard files, but that doesn't seem to be the case?
Any suggestions?
Thank you.
You should be using Base Internationalization (see docs). The idea is to build up a flexible UI in your storyboards and then rely on Xcode / iOS to substitute in appropriate text. Instead of having a storyboard per language, you would have a single Base storyboard and a set of language strings files.

Difficulty Localizing xib Files

I have localized two sets of xibs and put them in my project navigator as shown in the picture below:
My Localized.strings files are working fine, but the xib files are sometimes selected incorrectly. When I set the device language to French, I see the English xib view. When I set the device language to English, I see the French xib view.
I removed the xib files from the project, deleting the references only, and then dragged them back into project in the same places, as the picture shows. Right at the moment, I'm only seeing the English version, regardless of which language I have the device set to.
Is there something anyone can see that I'm doing wrong?
(I have read advice, like this one, on not using separate frames for each language. I may switch to that at some point, but right now, I just want to understand what is wrong with my set up.)
Update
Here is the file organization for the en.lproj folder. The fr.lproj folder is set up the same way. These are inside a folder called Resources.
Update - Final Result
I experimented with the localization settings for my xib files in the panel at the right.
and finally noticed those disclosure buttons when I had two or more languages selected for localization. Clicking on the disclosure button revealed a xib file for each language. I then had redo the localization for the foreign language xib. (I probably could have copied and pasted from the existing xibs.)
So the files are now organized like this:
The project navigator shows the en.proj and fr.proj, but are the files really localized in folders on the file system? In XCode 4.2 the localized files will show there localization after the file name in parentheses. I do not see that in your example. Here is what my localized resources look like.
To make the XIB localized you need to put them into folders on the file system with the appropriate names. It is easiest to do this from the file inspector.
Don't know if this helps?

Resources