Localizing NIB files with Xcode 4
Tuesday, May 10, 2011 One problem I have with Xcode 4 is that there are lots of tiny icons and tabs whose purpose is not immediately obvious. Also the UI has undergone a radical overhaul so knowing how to do something with Xcode 3 is not always much of a help when you want to do the same thing with Xcode 4. This means that the first time you try to do something you spend a few minutes hunting around for the right button to press.
One example of this is when you want to localize a NIB file. With Xcode 3 you right-clicked on the NIB file and managed the localizations in the file info dialog window. Unfortuantely Xcode 3 made a mess of handling the naming of the locales (see Xcode localization frustrations). With Xcode 4 things are a little different.
Localizing a NIB file
The action of localizing a NIB file is pretty easy once you know where to look in Xcode 4. Now that Interface Builder is integrated into Xcode you need to look in the right-hand utility pane with the NIB you want to localize selected:

To display the localization option you need to ensure you have selected the first tab in the utility pane by selecting the file inspector icon:

Adding new languages is then as easy as clicking the “+” button in the localization section of the inspector. A nice touch here is that frequently used languages are grouped at the top along with an Add all button which speeds things up. The menu also lists all locales by their user-readable names (e.g. German) together with the ISO language designator (e.g. de) so you no longer have to hunt around for the correct codes.

As you add each language Xcode creates the appropriate project directory and copies the NIB file into the directory. The directory names now also use the short country codes so in the following example:

The project ends up with directories named en.lproj, es.lproj, fr.lproj and it.lproj and everything finally works as expected. Of course, at this point you have to do the hard work of actually localizing all of the strings in the NIB file…
5 Comments | tagged
localization
Reader Comments (5)
Hi,
That's ok until you modify or add an element. Say I have a toolbar, and I have added a new item. How can I spread the changes to my localized versions of this xib?
thanks for your help,
Jean
@Jean - keeping localized NIB files in sync is a real pain for any complex user interface. The best approach I have seen is to have a single NIB file and set the strings at run time from a standard strings file. Take a look at this post from Matt Gallagher for an example: http://cocoawithlove.com/2011/04/user-interface-strings-in-cocoa.html
Your last sentence is leaving me hanging... I cannot figure out how to do the string localization for nib files. Argh!
@dana there is no magic solution, at least that I have found. Once you have the separate Nib files, one for each language, you need to go through each one and adjust the strings. The best advice I can give is to minimize the strings you have in the Nib file.
You can extract all the strings from all your localizable nib files by running the ibtool in Terminal. This creates a .xib.strings file corresponding to each xib file. Then create a new lproj folder, eg. es.lproj, copy these files to the new es.lproj folder, localize the strings and run the ibtool in the es.lproj folder. This will combine each new .strings file with its corresponding xib file in the original lproj folder to create the translated xib file.
Matt Gallagher has the code for running ibtool here: http://cocoawithlove.com/2011/04/user-interface-strings-in-cocoa.html