Adding localizable files to project on Xcode 4 - iphone

I'm developing an App that needs Localization.
I've followed these steps:
I've created the es.lproj, it.lproj, en.lproj folders in the root of the project with finder.
I've created the Localizable.strings file in each folder with the key pair values corresponding to the target language.
I've imported with Add Files To option from Xcode.
When I test the App in the iphone simulator all works fine. I configure the iphone to any localizaed language and the app is translated properly.
But when I run the App in the device, only shows the strings in english.
I've made a test following these steps.
From Xcode 4 right button over Supporting Files Folder, New File.
Create Localizable.strings file
In file inspector, section Localization. I've added the rest of languages. Creating the file like a folder with all Localizable files in the tree.
In the root folder of the project, the xcode created a folder for each language.
After editing every file, I've executed in simulator and all works fine. I've tested in 3 different devices and the only language is English.
In the Project -> Info -> localization I've added every language.
In the Build Phases I've observed that only is referenced the Localizable.string file in the en.lproj folder. I've tried to add the rest of files, but only accepts one more Localizable file. I've tested in device with the "extra" added language but doesn't works.
Can someone help me please?
Thanks in advance.

Try this: Remove the app from the device, clean project, make sure that the files appear in Build Phases>Copy Bundle Resources and run again.

Are you sure you are testing properly on your device ? I just tried making a simple localization test, just a Hello world in different languages, and when i
I used Xcode 4 and followed the same steps as you. Changed my device language, reloaded the app, and there it was.
You might need to do a clean install in order for this to work. Do the clean install after you changed your device language to "something you haven't seen yet" ;]
Maybe this tutorial can help you : Localization Tutorial with XCode

Have you tried to delete the app from the device and then reinstalling?
EDIT: I have checked in a project of mine and the names I see are: English.lproj, French.lproj, etc.
Don't know if this could make a difference, but you could try it. Also, you can go to the app binary for the iPhone with the Finder and select Show package content to inspect its content and make sure the localization files are there This could help to pin down the problem...

If it can be run in the simulator ok, but the device has a problem with the localization, then the link provided here by Nils Munch has the answer. In troubleshooting it says "Unlike the iPhone simulator, the iPhone only recognizes strings files that are formatted UTF-16. Always test your localizations on the device, as the simulator and the device do not always behave the same way."
I think the problem here might be the file is UTF-8. The simulator can handle that but the device can't.

Related

Loading wrong xib after updating the app

I already have my app on the App Store and I want to publish a new internationalized version. So, I created a xib for the english version and a xib for the french one (localized in the good en.lproj and fr.lproj folders). And when I set up the app on my iPhone that already have the first no-internationalized version, I had some troubles with the interface : the app does not update all the changes on the UI and I still have french labels even if I set the iPhone language to English (the app does not choose automatically the good xib).
If I only clean the project and build again, it still does not work but when I cleaned my project, deleted the app of the phone and build again, everything works like a charm. I don't want that the problem occurs to people who already have the app and update it via the App Store :/ is there a way to understand what happens ?
This is what happens: In your old version, you have one .xib file in the application bundle, and the bundle looks like this:
<bundle-path>/interface.xib
In the new version you have the two localized versions of this file and your bundle looks like this:
<bundle-path>/fr.lproj/interface.xib
<bundle-path>/en.lproj/interface.xib
When the app tries to load the xib file it looks directly in the bundle directory first and, if it doesn't find the file there, looks for the file in the subdirectories with the localized files.
If you have the old version on the device and then build and run the new version from Xcode, legacy files are not deleted, so you end up with this bundle
<bundle-path>/interface.xib
<bundle-path>/fr.lproj/interface.xib
<bundle-path>/en.lproj/interface.xib
and the app loads the unlocalized file as it never needs to look into the localization subdirectories.
I assume that legacy files are not deleted when you deploy from Xcode to a development device for performance reasons.
However, your users will not run into this problem. When a user installs an update of your app, the app bundle will be completely replaced by your new bundle. So if you upload a "clean" bundle without legacy files, and this version works when you do a fresh install on a your device, it will also work on your users' devices.

Which file contains Localization info in an iPhone Xcode project?

I am working on a iPhone app and trying to add a German localization. And we are using TFS for version control.
I have added the German strings file all right, but every time I restart Xcode, the Localizable.strings(German) is gone. The file still exists on disk, but just not included in the project. I believe it's because some controlling file is read-only. I have to find this file and explicitly check it out. I cannot checkout/check-in the whole project because the guy integrate the code will be mad.
It's the xxxxx.xcodeproj folder.

Experiencing An Issue With Localizable.strings in an iOS iPad App

This is the first time that I have attempted to add some localization into an app using Localizable.strings files and I am experiencing an unexpected issue with it. For clarity, these are the steps I have gone through.
File >> New >> New File and added a Resources file of Strings type.
Named the file 'Localizable.strings'
Clicked into the Localizable.strings file and added Spanish through the Localization section. (I have confirmed in my project folder that I have the en and es folders).
Started to add my KEYS in the Localizable.strings (English) file and then add the Spanish translation into the Spanish file.
As an example, this is one of the localizations I am trying to add.
"CAMERA_ERROR" = "The device does not have a camera";
I am added the exact same string in the Spanish .strings file, but changing the text to suit Spanish. Within my app code I am using the following:
NSString *cameraError = NSLocalizedString(#"CAMERA_ERROR", nil);
Everything seems fine up until this point, but this is where it gets weird and I get confused. If I run the app on one of my iMacs it works fine and depending on what language I set the simulator to it displays the correct English or Spanish string.
However, when I run the exact same app on this MacBook Pro it doesn't display the string, it instead takes the "KEY" title and displays that. So instead of showing the message as "The device does not have a camera" it shows it as "CAMERA_ERROR". The code is exactly the same as it is the same project cloned from a git repo.
Can anyone shed any light on this? Any setting on the MacBook that could be different?
Try doing the following on your MacBook Pro:
clean the project;
remove the app from the simulator/device;
rebuild the app.
This should fix it.

How to get multiple targets into one binary for app store submission?

I have split my iPhone app into two targets one for the ipad and one for the iphone. When I upload to the appstore I can only have one binary. But I have two targets?
I think I am missing a step. Thanks in advance for any help.
A "target" encompasses all of the instructions that Xcode uses to build your app.
You can have two targets inside of one binary, although this is not always done. This is how Universal Binaries are made. The two apps are bundled together inside of one binary. If you open up a Mac app "bundle" you will notice a few meta files, like icons and such, and there will be the actual compiled binary code. An iOS Universal Binary has both apps inside of it.
(If you watch your compilation carefully, you'll notice that Xcode actually builds your app twice. It does one build for iPhone/iPod and one for iPad.)
Provided that your Xcode project is set up properly, you will get the intended results.
The binary will be fine, the "targets" refer to what runs when it is run on an iPhone vs iPad. If the project is setup correctly for universal it should work fine.

Why is my iPhone application not using the proper localization?

I have an iPhone application that initially had only English and German localizations. I just added a French localization, but when I change the user language to French it still shows the German strings.
What could be causing this odd behavior?
Are you testing this on the simulator or the device?
Often the localized folders (.lproj) directories aren't copied into the bundles during a clean build as they should - even with a 'Clean & Clean all targets'.
Ensure this happens correctly by deleting the app from the simulator (easiest way is to 'press and hold' on the app icon in the simulator, then delete). Also, ensure the simulator doesn't keep hold of the old app data by manually deleting the app.bundle dir from the iPhone simulator directory using Finder.
Build, clean, run. Should work properly then.
If not, make sure the fr.lproj exists in the bundle after the build.