How to localize view in xcode4? - iphone

I want to localize my iOS project in xcode4. In xcode4 this seems to be very simple. In the utility sidebar there is a localization panel where I can add languages.
Adding a language I get following structure:
I want to localize a button. So I open MainWindow.xib (German) and just edit the title of the button. But when I run my project on both device or simulator I always get the english version even if it is set to German.
Where is the problem? Any ideas?

Delete the app from the device or simulator. If you've launched it before you've added the localization there is still a MainWindow.xib in the root file structure of the project.
If you deploy from Xcode files are only added, never removed.
So you have three files now.
MainWindow.xib
de.lproj/MainWindow.xib
en.lproj/MainWindow.xib
And as long there is a file in the root folder iOS doesn't look into the language specific folders.

Go into settings on the iPhone or Simulator and change the International from English to German, then restart the app.

Related

iOS universal app localization xcode 4. bug?

well, i've just faced with localization problem on my projet and decided to make an experiment to reveal the problem:
experiment:
create universal iOS application;
change the text on main windows from "My Universal iPhone (iPad) App" to "Hello" both for MainWindow_iPhone.xib and MainWindow_iPad.xib files;
build and run app in iPhone and iPad simulators - both displaying "Hello" message - everything is fine;
add spanish localization for MainWindow_iPhone.xib and for MainWindow_iPad.xib (english localization was already there)
change the text on main windows from "Hello" to "Hola" both for spanish version of MainWindow_iPhone.xib and MainWindow_iPad.xib files;
change language in simulator to spanish;
build and run app in iPhone and iPad simulators - both still displaying "Hello" message - what?!?!?!
fix:
open project properties and go to "build phases" tab;
in "copy bundle resources" add xib files: locate MainWindow_iPhone.xib and MainWindow_iPad.xib files in es.lproj directory of project and add them
build and run app in iPhone and iPad simulators - both displaying "Hola" message - OK
well, what conclusion can i make? when adding new localization to xib file, xcode is forgetting to add this file to copy bundle resources target. so after running app on different localization (spanish in example) iOS can't find spanish localization (of course, Xcode forgot to copy it!!!) and load english version of xib.
manual adding localized versions of files makes mess in the project tree - added files will be displayed in project hierarchy, but they are already displayed when we expand xib file with localizations. (in example we will have MainWindow_iPhone.xib and MainWindow_iPad.xib in project structure tree, but at the same time they are available in iPhone and iPad file groups after expanding localized MainWindow_iPhone.xib or MainWindow_iPad.xib files)
or am i missing something cruicial?
If you manually add resources to Xcode, you'll often need to (K)lean your project to rebuild the links. Command-K should do the trick.
I can't remember having to do this in Xcode 3 and it may already be fixed in later version of Xcode 4.

iPhone - System strings not localized on device

I build a project using XCode 4 and I was running on the simulator since now. I had noticed that the strings in System type "Edit" and "Save" buttons where in english, but everything in my simulator was set to french. I suspected a bug like the one I had in XCode 3.
But now I'm running on my pure french configured iPhone, and those buttons are still in english, and are not localised as in other apps I can use.
I noticed that in my info.plist, the "Localization native development region" was set to "en" by default. I've changed this to "Fr" or "France" in the drop down menu, but that does not chage anything.
How may I correct this to make those buttons show a localized title ?
I had basically the same question, but Black Frog's answer didn't really help me. I did some research and this is what I found out:
The localization is primarily based on the bundle. With info.plist you can add localizations that aren't in the bundle, but you can't remove localizations that are present in the bundle.
The preferred way to add a French localization in Xcode 4 is to do the following:
Open project in Xcode >= 4.0.2
Click on project file
Select item under Project title on the right
Check Localizations table.
Select the localization you want to duplicate (English)
Click + and select the language you want you're app to use (French)
If you don't wan't to support English there are two additional steps:
Select the localization you want to remove (English)
Click - and delete the files
Special thanks to Nekto who helped me figure this out.
You have to create localized version of your nib files. Or you can set the text of each button/label to a localized string in view load.

Resource problem - Localization and iPhone/iPad XIBs all broken

I had a localized universal application. I copied a bunch of resources (XIB) files from an old project into the appropriate locations (English.lprog) directories for both iPhone (Filename~iPhone.xib) and iPad (Filename~iPad.xib). I added them to the project, and they all appear correctly in Xcode, as localizations, etc. I can open the localized files for each device in XCode/IB, and everything appears correct.
Now, when I run the project - everything is completely haywire. In short, when I run in English on the iPad simulator, I get the Chinese version of the iPhone XIBs!!!
I can't figure out what the problem is - any idea how to dig deeper?!
Few things fixed this:
Total clean build of project
Erase old application from device and/or simulator before reinstall.
Just because the icon in XCode looks like an IB icon, and double-clicking opens in IB, it still MUST have an ".xib" extension visible on the file.
Simulator is NOT case sensitive, but iPhone IS. This includes differences like MyClass~iphone.xib (works) vs. MyClass~iPhone.xib (doesn't work).
These steps have worked for me: In Xcode,
Check the location of folders for every language
Build > Clean all targets
Build > Compile
alt-R

iOS Settings.bundle localization difficulties

From what I can read I'm not the only having this problem; except this is just happening in my Settings.bundle in my app it's all fine…
My app is localized in English (primary) and French.
My Root.strings file isn't getting called in at all, for English and French. If I put my iPhone in French the Settings bundle will be defaulted to the title declared in my Root.plist. Now in whatever language my iPhone's set to (English or French), let's say I add a group entitled "hello" and set the corresponding string to "world" I'll just get "hello" as my "localized" string…
Thanks
I've been struggling with the same problem. Using version 5.0 of the iOS simulator and Xcode 4.2, the localizations don't appear to take effect when the Root.strings file is changed.
My setup has a Settings.bundle which contains a Root.plist and a directory for each language supported containing a Root.strings file:
Settings.bundle:
Root.plist
en.lproj:
Root.strings
fr.lproj:
Root.strings
This is pretty much the standard setup which Apple documentation suggests.
When simulator is using the english localization, I change the matching Root.strings file and recompile, the changes don't appear to take effect. But if I uninstall the app, clean the project, and then re-run, the localization takes effect. It seems like an Xcode or iOS Simulator bug.
My solution: uninstall the app from the simulator, then run it again from Xcode to see the changes.

Localization of Default.png is not working

I wonder if anyone has encountered the same problem and how they solve it.
I want to localize Default.png so I do the following steps which from what I understand should be the correct way (please correct me if I'm wrong).
Select Default.png in xcode
Command-I to Get Info
Click on Make File Localizable
Go back to General Tab (why Apple, why?)
Click on Add Localization
Enter es for Spanish according to this:
In finder I replace the Default.png in the es.lproj folder
I have tried in both the simulator and on an iPhone with changing the language between English and Spanish, but I only get the original file. Other localizations like app name and strings works just fine, but not this one...
I'm on xcode 3.2.3
Thanks
I'd thought I'd add the answer for localizing Launch.xib.
Create InfoPlist.strings file. (File,New,Resource,Strings)
Localize it and select your languages
For e.g. the Spanish version, add your launch screen key and name for the Spanish version of your Launch screen
"UILaunchStoryboardName" = "Launch_es";
Copy your existing Launch.xib to Launch_es.xib, and change the text and/or images to the Spanish translations or Spanish-named images.
I got this solution from Developers Forum (credit to Sascha Paulus, thanks Sascha!).
I had a similar problem in another project with localization, but the solution worked for both issues.
Here we go:
Delete App from Simulator (just to be sure)
Delete all versions of the localized Default.png (in XCode & on Disc)
Select Build > Clean All Targets
If not done yet, make the Localizion Directories (e.g. es.lproj, de.lproj)
Copy the localized Default.png in the appropriate Localizion Directory
Go To XCode > Right Mouse Click on Resources > Add > Existing File ...
Select the localized Default.png in the Localizion Directory
Don't forget to mark "Copy items into destination group's folder...." > Add
Repeat it with every localized Default.png
I think the trick is to delete the file you have a problem with, clean all and then add it again. If you don't have any localization there is no need to create a specific folder.
Give it a try, worked for me.
I have had the same problem. I have solved it with this:
In the Simulator, menu "simulator iOs", option "restart content and settings".
In Xcode, menu "Build", option "Clean All Targets"
And when I have selected the button "Build and run" it has worked.
Just to add that on a latest 4.3.3 every attempt to remove and re-add the files, and the clean all, nothing worked, but what solved everything was the remove-app-from-device-and-simulator and reinstall. Now every image and xib are translated correctly.