Languages, interfaces and images - iPhone i18n tutorial part 1
This part of the tutorial will show you the steps you can't do without if you want to have a localized iphone app.
A Test
Just to get your feet wet, let's find your current locale.
NSLocale *locale = [NSLocale currentLocale];
NSString *currentLocale = [locale displayNameForKey:NSLocaleIdentifier
value:[locale localeIdentifier]];
NSLog( @"Complete locale: %@", currentLocale );
This should then display something like "Deutsch (Schweiz)" if you run this application while it is set to be from the German speaking part of Switzerland. This could be useful if you need to show the locale to the user or if you want to hard-code some behavior specific to one locale.
Defining Languages & Translating the App Interface
This is how you can translate the part of your program that is immediately visible to your users upon start-up. In your Resources older, find the .xib file that you wish to internationalize. Click on this file and then press ⌘I to bring up its Info window. Make sure you're on the General tab, and then click the Make File Localizable button. Notice that this file will now have a disclosure triangle next to it.
Now make sure this file is still highlighted and press ⌘I again. Now make sure you're still on the General tab and press the Add Localization button. A new window will pop up asking you to enter new languages. Here you will want to add de (the official 2-letter language code for German) and ja (the official 2-letter code for Japanese). Don't use the defaults legacy names German and Japanese from the drop-down list, because these are likely to become deprecated in the future.
Now when you click on the disclosure tag, you should see English, de and ja.
Right-click on this nib file and click Reveal in Finder. Now you can see that XCode has generated the folders English.lproj, de.lproj and ja.lproj. These folders will contain all of your internationalized resources for each language respectively. Now you can go back into XCode and open these files in Interface Builder to change your interface text into the appropriate language.
How to Localize
The difference between internationalization (i18n) and localization (l10n) is that after localization, your app will not just be translated, it will feel like it had originally been developed by somebody from the customers' culture.
This requires not just skilled wording of the translation, it may also involve:
- using different images, e. g. because they have text on them or because a picture of an American mailbox would not be recognized as a mailbox by a European
- using different colors, since colors have different connotations in different cultures
- positioning interface elements differently, especially if you're going for the Israeli or Arab market - Hebrew and Arabic are read from right to left and this heavily influences how people perceive your interface
- changing words or names to more culturally-aware ones. Some words are just taboo in some cultures, some ways of expressing yourself are more acceptable than others, and a good translator should take that into account and have the leeway to adjust your texts accordingly. In the worst of cases, you may even have to find a different brand name, if your chosen product name means something vulgar or inappropriate in the target language.
Most of these changes can be made from the interface builder, which is why it's so important to collaborate with linguists who also have knowledge of technology.
Localizing Images
Most likely there are one or two images in your app that will need to be localized because they contain English text. For example, this could be your splash screen, your app icon or a fancy button. To localize any image, just follow the same procedure as for nib files. Click the image you wish to localize and press ⌘I to bring up its Info window. Now right-click on the image's filename and choose Reveal in Finder. You'll now see that the original image was copied. Now replace this image with the new image you have for that language. You'll have to clean and build again before the compiler will recognize the new images though.