Adding new language to existing localized app - ios

I have an app that uses localization, I need to add one more language, I want to display two different language images of same name in one xib file, the xib file is not localized as I am localizing the images. Can it be done using interface builder, without writing any code?

You can add one more language by click on + button.Hope this will help you.But you have to make multiple XIB's as you are saying to set the images only in one XIB i think it is not possible.

Add the images to your localized subdirectories in your project (en.lproj, es.lproj, etc.) and iOS will pick up the correct image when it unarchives the localized xib file.
Xcode can do this for you automatically: Just select the resource you want to localize (an image, xib file, etc.), display the File Inspector pane, and then click the Localize button.
(As a side note, it's a bad practice to localize a high number of images. You should remove text from images and choose them so they are "neutral" and "understandable" in every region of the world. Your app size will thank you for it.)

To do it without code you must localize the xibs, otherwise you will require code from you or others and some configuration. It's easier as follows:
Assuming you have added already localizations to the project (you can do it in Project > Info tab) you just need to select the image in the project tree and check the desired localizations in the right sidebar (cmd-alt-1, localizations).
Replace the image in each *.lproj directory with the localized version. Then in your viewDidLoad use -[UIImage imageNamed:] as usual to load an image into the xib image view or whatever you are doing.

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.

Where should I put background and button image files? Assets or just drag into the app files?

I am making an app but I'm not quite sure where should I put the image files? Just drag and copy inside the app or in assests? What's the difference, I'm not quite sure.
I'd strongly recommend using the xcassets, which you can do by dragging your files onto it when you have it open in Xcode. Xcode handles the rest, copying them into your project. Doing this also allows you do call UIImage(imageNamed:), using the title you give to each Image Set. You also don't have to worry about specific naming of the different size classes, as you drag them to the appropriate section there.

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

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