Localizing Cocoa
- Translating GUIs
- Time and Dates
- Translating Text
- Caching Locale Information
- When Not To Localize
Localization is a big topic. Most developers start by writing their applications for their own language, using their own conventions, and then worry about translation when the application is finished. This can create a lot of work for them later on.
Good programmers are lazy and try to avoid anything that will create extra work for them later. It's quite likely that you'll want people in other locales to use your application later. Even a country like the USA only accounts for a small fraction of the global market, and localized versions make a program a lot more attractive to end users. Thinking about localization early on will save a lot of work eventually.
Translating GUIs
Cocoa stores user interfaces in nib files. With newer versions of Apple's developer tools, these are created from xib files, which contain property lists describing how all of the objects in the user interface fit together.
Nib files are intended to be created by a user interface designer, who may or may not be a programmer. All of the strings for displaying in the user interface are stored in the nib. This is intentional, because the size of various user interface elements depends on the size of the text stored in them.
In a large organization the user interface designers and the translators may be different people. To help with this, Apple provides a ibtool utility, which extracts strings from a nib or xib file and then lets you merge them back in later. Prior to 10.5, this was called nibtool. The "n" was dropped because it now works with xib files as well.
The first step in translating a Cocoa user interface is usually to extract the strings, translate them, and then merge them back in. You do that with these two commands:
$ ibtool --generate-strings-file MainMenu.strings en.lproj/MainMenu.nib $ ibtool --strings-file es.lproj/MainMenu.strings --write es.lproj/MainMenu.nib en.lproj/MainMenu.nib
This creates a MainMenu.strings file from the English nib and then creates a Spanish nib from that file. Between these two commands, obviously, you should translate the strings file.
You then have a translated nib file, although some of the strings may be too big or too small for the user interface elements containing them. The next step is to re-size everything and make it look tidy.
This isn't quite the end. You might need to change some of the images in your interfaces to correspond more closely with local associations, and you may want to reorder some of the elements in your interface based on the local reading order. For example, in English where you read from left to right and then top to bottom, this is the order in which you should present interface elements that the user will interact with sequentially. In a right to left reading order locale, you might want to put them the other way around.