NSLocalizedString
has the advantage of being easy to implement. Risk is that you might forget to add an entry for a new Gui element.
You can use itool
to dump the string from the original xib file, translate these dumped strings and then load the translated string into the other-language-xib file.
There are some advantages doing it this way compared to NSLocalizedString
.
- All the consideration for translation and string length still apply but you need to touch only the original xib, the other languages can be updated by script.
- You see the elements already translated and the different possible states for each UIElement from the dumped file.
- You will have more single strings files to send to your translator but it is easier to keep an overview as to what part is in need of translation, what part is done.
- GUI Changes done to the english xib are applied to the localized xib, you are basically merging the original xib with the translated strings.
When you create a XIB you set it to being localized (as before), then run itool
against this original xib to extract the strings.
Translate the strings file into the desired language then load the translation into the localized xib.
If you google for ibtool --generate-strings-file
you should find a few tutorials and examples.
The syntax should be similar to:
#dump original xib to a $xibfile.strings file:
ibtool --generate-strings-file Resources/English.lproj/$xibfile.strings Resources/English.lproj/$xibfile.xib
# offline: translate the $xibfile.xib, place it into the correct lproj folder
# then: merge translated $xibfile.strings with original xib to create localized xib
ibtool --strings-file Resources/de.lproj/$xibfile.strings --write Resources/de.lproj/$xibfile.xib Resources/English.lproj/$xibfile.xib
$xibfile.strings
in the Resources/English.lproj directory will contain the original (English language) strings. The translated $xibfile.strings
must go in the appropriate xx.lproj
directory.
If you add a buildscript to xcode then the loading of the translation will be called at each build.