Tuesday, December 30, 2008

Localizable.strings problem in iPhone apps

Lately I have been writing an iPhone application that needs to work in English and Turkish.
I used NSLocalizedString macro all across my code, then ran 'genstrings' from command-line to generate the Localizable.strings file with the key-value pairs.
In XCode, I selected Localizable.strings, hit the 'Info' button and then hit the 'Make file localizable' button. I then used the 'Add Localization' to add 'tr' support. I updated the Turkish version of the file with translated strings.

It all looked good when I tested on the simulator. Pretty cool. But while testing on the actual device, I noticed that the strings were not being replaced with their Turkish translations.

iPhone documentation says the Localizable.strings file needs to be in UTF-16 encoding. But suprisingly, if you are using SDK 2.2, the file generated when you hit the 'Add Localization' button is in UTF-8 encoding. So just because you added the original Localizable.strings file in XCode by specifying UTF-16 econding, do not assume that XCode will stick to that for its localized copies. To change the file's encoding to UTF-16 from UTF-8, use 'View' --> 'Text' --> 'File Encoding' in XCode menu.

'Clean', 'Build', and it all works!