Why is my iPhone application not using the proper localization? - iphone

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.

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.

Adding localizable files to project on Xcode 4

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.

Why isn't my iPhone app bundle replacing the old one during an update?

I'm starting with an app that has foo.png as a resource, and the app is installed (either in the simulator or on the device). If I delete foo.png, do a clean build, etc., and install, then it still shows up in the bundle on the simulator or device!
But I know the file isn't in the bundle before copying to the simulator or device (for example:
I can see it's not there in the build folder.
If I delete the app from the simulator or device, and then install, then foo.png doesn't show up on the simulator or device.
So it seems that when updating, it doesn't replace the app bundle; instead, it only copies new files and replaces updated ones. (I can confirm that it does, in fact, copy and replace files properly.)
Why isn't it replacing the entire app bundle?
If you update your application through iTunes using an ad hoc build you will see that your .app bundle will be replaced completely and old resources, such as the foo.png file described in the original post will be removed.
Reset the simulator, go up to the menu and then click reset simulator. I always have that problem with databases on the device. You will have to delete it on the device. Just a quirk that I've experienced as well.

XIB actualization problem

I'm facing a weird problem dealing with Xcode. When I run my project using simulator I got the correct xib showing, but when I select my iPhone as target, it shows an older version of that xib... I'm going crazy with this, I have tried to clean targets, deleting and reinstalling the app on iphone, :^S
Please could anybody help me with this issue?
Thanks a lot and sorry for my english.
When Xcode installs development builds of iOS apps on the simulator and on the device, it copies all files from the .app bundle into the target directory for the app in the simulator or on the device. However, it does not remove old files. This can sometimes cause strange effects.
For example:
You have MyView~ipad.xib and MyView.xib for iPhone, you install the app and run it on the device, now you decide to delete the MyView~ipad.xib so that it will just use the MyView.xib same as iPhone, you test this in the simulator and it works fine but when you put it on the device again it still uses the old iPad xib file, but how when it's not even in the project any more? Well the old file still exists in the filesystem on the device until you actually delete the app off the device.
This can happen when you remove files from the project or rename them to something else, the old files will still be there and especially if you have fall-back beaviour or how iOS can look for other suffixes automatically like #2x or ~ipad - this can easily cause confusion. Check for this whenever you notice strange effects like old versions of files seem to resurrect themselves, or it works on one device but not the other.

How to force application Settings bundle get updated?

Application Settings.bundle contains a version number, which is automatically generated during build. From build log I can see that new value is written there, also when looking inside the file itself in MacOS X Finder I see correct updated value.
Settings in iPhone simulator or in real iPhone shows me the old value. Removing application and reinstalling is so far the only way I've managed to get the new updated value visible.
Question: how can I force iPhone Settings application to read my new latest updated bundle file?
Some background info, which might or might not be related: I install application only via Xcode into both simulator and iPhone. Is this the problem? Just found this in Apple docs, not sure what it actually says. Seems to contradict itself (last chapter)...
Each time you reinstall your application, iPhone OS performs a clean install, which deletes any previous preferences. In other words, building or running your application from Xcode always installs a new version, replacing any old contents. To test preference changes between successive executions, you must run your application directly from the simulator interface and not from Xcode.
So Xcode always replaces old content, but to test changes I cannot use Xcode? What was that? Done both (after installation via Xcode) and didn't see new values in settings. Any ideas how does it actually work? Do I always have to make non-Xcode installation?
Try cleaning and building. It seems that xcode caches dates and doesn't notice the change that your script is making. I've had similar things happen, clean always fixes it, but it is indeed a nuisance.
Make sure to shut down the Settings app running in the background on device. It looks like Settings caches settings while it's running - but pulls the updated values when the Settings app is re-launched.
In my case, it seems that my modified root.plist, created/edited via the Xcode property list editor, just wasn't being saved.
There was no problem at all with the Settings Bundle being copied over to the iPad. A quick cmd-S followed by a rebuild and go/debug updated Settings on the iPad straight away - no app uninstall/reinstall even needed. You'd think there'd at least be a haven't-saved-it warning from Xcode, as there always is for code source files.
I just tried this and it worked.
In Xcode go to : Window->Organizer,
then view installed apps on the connected iPad/iPhone, remove the app, then recompile and run your app on the device.
I think the issue has something to do with the iPad's cache.