Reputation: 422
Thanks for reading the below (also feel free to be entertained by my frustration)
//Rant
First it's obvious this is an issue that there are so many questions for localizing apps. (yes i've started setting aside objects that I can break to make me feel better..haha)
//To Business
I've looked everywhere. I've read a number of tutorials for this (started with raywenderlich and have tried a number of different tutorials) and of course I've been searching SO for days.
steps I've taken:
select project and under localizations add the other language (I've read some people select 'use Base Internationalization - i'm not using storyboards (lots of nibs) so I don't think that is the option I should select)
Add localizable.strings file to my supporting files selected English and 2nd language and I get two strings files. I look in the project in finder and I see the two different language folders (in those folders are the infoplist and localizable string files.
I've updated the translation for the 2nd language .strings file ..
After that things get murky on what i'm supposed to do.
I selected a button that will be in two different languages ( I know I should change button titles in code) and clicked the localize button and selected the second language. this makes me another set of .lproj folders so I have one in the main directory (Project/en.lproj)and a second en.lproj in my resources directory((Project/res/en.lproj. Is that ok? or should all my assets (.strings files, nibs, images) be in only one folder?
I selected a nib and selected localize > added the 2nd language cleaned, built, recleaned, restarted Xcode, deleted simulator files, deleted derived data. Built, restarted, cleaned.. broke a few things, did it all again.
//Plea for help
I've looked at apple docs and they make it seem really easy to do this maybe I'm just missing something really simple. Any advice on what I should do/read/watch/yell would be much appreciated.
Thanks,
james
Upvotes: 0
Views: 464
Reputation: 422
//I feel weird answering my own question but I feel like others may find it helpful.
I’m embarrassed to say but the first part of my issue was very simple.
I figured out what I was doing wrong based on watching “Localization of your app” by Warren Evans. In the video at around 23min he uses some code to get the local and language
NSLocale *locale = [NSLocale currentLocale];
NSString *language = [locale displayNameForKey:NSLocaleIdentifier value:{locale localeIdentifier]];
My issue was that in project info for localizations I selected to add: French(France) (fr-FR) that created the .lproj folders in my project that were fr-FR.lproj. So when I tested on the device for French it wasn’t grabbing the images or strings.
With the above code I knew it would say French with the local of United States.. bing bing bing!! Dots were connected.
Originally, I didn’t even notice there was a generic French “French (fr)” option in localizations. I updated my project folder to use French(fr). The strings and the images then displayed correctly when I cleaned, and reset the simulator. (and yes you can have multiple .lproj files per lang- i have a separate one for resources)
The second part of my issue was with items not getting updated in the nib files. The solution which they describe in both apple docs on online seemed to always be missing a step and I was unclear how nibs updated.
It seems the way to do this with storyboards is the best way to keep things dynamic but my project has 15 nibs. The link I found describing that is http://www.ibabbleon.com/iphone_app_localization.html
The above helped me to understand a bit more about using ibtool having already read the apple instructions. The handy Terminal command from that was:
find . -name \*.xib | xargs -t -I '{}' ibtool --generate-strings-file '{}'.strings '{}'
I used that after changing the directory (cd) in terminal to my project directory and navigated accordingly for the lproj files. (trying to make this as detailed as I can to help others if they have the same issue)
To do generate one nib strings file at a time I used apple directions:
ibtool --generate-strings-file NIBNAME.strings en.lproj/NIBNAME.xib
That created my NIBNAME.strings file for translation.
Once I had the .strings file translated I followed app docs and created a nib from the original English template but with the above translated strings file:
ibtool --strings-file fr.lproj/NIBNAME.strings --write fr.lproj/NIBNAME.xib en.lproj/NIBNAME.xib
Next I selected the nib and chose ‘localize’ in file inspector then when I selected the nib to check ‘localize language’ it saw that I had already done the above step, which already created a new nib. Xcode asked if I wanted to use it or replace I selected use it and my translation changes were live. I had to go through the nibs to make sure formatting and centering of buttons looked right but now everything is working.
I feel like I should be able to do a master .strings file for all nibs like we do with genstrings based on the answer to this SO question: How can I extract all localizable strings from all XIB files into one file?
But I’ll need to experiment with that and I think it will be a battle for another day.
Upvotes: 1