Tuesday, 26 July 2011

Problems with switching languages on iPhone Simulator?

There are some pitfalls when you start localising your iPhone app. Let's say you followed the guidebook by the letter:
  • you create a Localizable.strings file - and add one for each language.
  • you replace all your "hardwired" strings in the program with NSLocalizableString(keyString, commentString).
  • you then create localised XIB files.
  • you've done all the adjustments.
  • you then clean the project build
  • and rebuild from scratch.
And then you run it on the iPhone Simulator (or your testing device). When changing the language of the device from English to - say German - what happens?
Still only one language is shown - the one you started with.

Well - there is one obvious way to enforce it:
  • delete the app from the iPhone Simulator or your iOS testing device
  • clean, build and reinstall
Voila - the language switching now works.
Unfortunately, all previously saved data are now lost. My app e.g. uses SQLite - and un/re-installing the app means we start from scratch. Sucks, doesn't it? You definitely don't want the user to let this happen to them - or there will be a lot of VERY unhappy bunnies out there.

Apparently, this is a known issue in XCode. Read the following entry:
The upshot of this blog seems to be that the AppStore installation does the right thing. Meaning, users can continue using their app and the language switching works out of the box.
The only way of testing this - prior to submission to iTunes - would be to install your app as ad-hoc application and see what happens.

Localizing iStayHealthy

Some gotcha's for localising iPhone apps:

In principle it is straight forward
  1. localise your NIB files (all ending .xib)
  2. localise your strings by putting them into a single .strings file
  3. localise any graphics etc.
What I found is
  • localising strings in .strings file. I experimented with different names. But only the default name - Localizable.strings - worked. Initially I used Localize.strings and the app didn't pick up any of them.
  • Making it work on Simulator takes a bit effort: a.) delete the app on the simulator, b.) in XCode clean your project and rebuild c.) install clean up in Simulator.
  • When switching the language in the Simulator, make sure that the App isn't running in XCode - it will crash otherwise
PS: iPhone Simulator works just like iOS devices. But here is a quick recap of how to delete apps and how to change language settings

Delete Apps on iPhone Simulator
  1. open Simulator
  2. click on the app on your home screen and keep the mouse/tap pressed down.
  3. the app will start to 'wobble' (as it would if you keep pressing on a real iOS device)
  4. hit the (X) button in the upper left corner.
  5. click ok when asked whether you want to delete it from the Simulator
Change Language on iPhone Simulator
  1. open Simulator
  2. go to home screen 'Settings' app
  3. select General->International->Language
  4. there change the language