Use Your Loaf

[[brain engage] write]

Xcode Localization Frustrations

Xcode does a lot to make it easy to localize project resources such as strings and NIB files. There is one small annoyance that is worth being aware of though if you want to maintain your sanity. Since Max OS X 10.4 the preferred way to identify a language is with the ISO language designations. To be precise the two letter codes as defined by ISO 639-1 should be used where possible. So English is identified by en, Spanish by es, French by fr, etc.

Prior to Max OS X 10.4 the legacy (but more user-readable) names such as English, Spanish, etc., were used but the Apple internationalization documentation now makes it clear that these values are deprecated:

In addition to the ISO language designators, the bundle routines also recognize several legacy language designators. These designators let you specify a language by a user-readable name, instead of by a two or three character code. Designators included names such as English, French, German, Japanese, Chinese, Spanish, Italian, Swedish, and Portuguese among others. Although these names are still recognized and processed by the NSBundle class and Core Foundation bundle functions, their use is deprecated and support for them in future versions of Mac OS X or iPhone OS is not guaranteed. Use the codes described in “Language Designations” and “Regional Designations” instead.

To localize a NIB file in Xcode you simply use the Make File Localizable button in the General tab after right-clicking on the NIB and selecting Get Info. The NIB file starts out with an English localization by default but you can easily add new localizations using the Add Localization button at the bottom. Each time you add a localization a copy of the NIB file is created in a folder named .lproj.

So if you have been following along at this point you might add localizations for fr, es and maybe even en. This works fine until you have the good idea to delete the legacy English localization file. At this point if you try to add a new language nothing happens. The new language file is not created and no error message is generated. Of course if you happen to be adding the new language at some future date it may not be immediately obvious what is going wrong.

The only way I have found to recover from this situation is to delete all of the localizations from Xcode and start again (copy the existing files to a safe location first). As long as you leave the English language localization everything works correctly even if you also have an en language.

Since Apple started deprecating the legacy identifiers in 10.4 I think it is about time they updated Xcode or at least included an error message to give you a hint as to why it is failing. Having said that I guess they have more important developments to be working on at the moment…

Comments