XIB File Internationalization

In a previous post I discussed options for internationalizing iOS apps. In this addendum to that article I’m sharing an amazing discovery that has saved me so much work and time. You can actually take all of the strings out of a XIB file using the ibtool command in the terminal. You then translate the resulting .strings file into the language of your choice and generate a new localized XIB file from the original one using the same command line tool.

Let’s follow a simple example. In my app I have a XIB file (WaitViewController.xib) I need to localize into three languages. The original version is in English.

  1. If not already so, we need to make the WaitViewController.xib file localized. We can do this by either moving it manually into the en.lproj folder and then adjusting our project’s references, or in the project itself by using the File Inspector to add a new localization, which will perform the same move and adjust references all at once.
  2. In the Terminal application, run the ibtool command in the project’s folder that contains the en.lproj directory with the following switches

    The –generate-strings-file option specifies what file will be created, while the parameter indicates what XIB file will be examined to extract strings from.
  3. Now we have the English localisation file with all the strings used in the XIB file. We have to translate it into the languages required by our app. For example, I need Spanish and Italian, so I will have es.lproj/WaitViewController.strings and it.lproj/WaitViewController.strings once the translation work has been done.
  4. The localized XIB files must already be present in your project structure for the next step to work, so we simply copy the English original into the appropriate language folders. You can also use the File Inspector again to create the localized versions.
  5. Last thing, given the translated .strings file, we modify the localized XIBs based on the original (English) one, but with text from the localized strings. It’s the ibtool command again that does the job.
  6. At this point your XIB files are localized and ready to use with no changes to your code. The .strings file become unnecessary once you have localized XIBs and can be deleted.

Leave a comment

Your email address will not be published. Required fields are marked *


*