Internationalizing Your Application IPHONE APPS

Ideally, the text, images, and other content that iPhone applications display to users should be localized for multiple languages. The text that an alert dialog displays, for example, should be in the preferred language of the user. The process of preparing a project for content localized for particular languages is called internationalization. Project components that are candidates for localization include:

  • Code-generated text, including locale-specific aspects of date, time, and number formatting
  • Static text—for example, an HTML file loaded into a web view for displaying application help
  • Icons (including your application icon) and other images when those images either contain text or have some culture-specific meaning
  • Sound files containing spoken language
  • Nib files

Using the Settings application, users select the language they want to see in applications'user interfaces from the Language preferences view. They get to this view from the International group of settings, accessed from General settings.

The Language preference view

The Language preference view

The chosen language is associated with a subdirectory of the bundle. The subdirectory name has two components: an ISO 639-1 language code and a .lproj suffix. The language code may also be modified with a particular region by appending (after an underscore) an ISO 166-1 region designator. For example, to designate resources localized to English as spoken in the United States, the bundle would be named en_US.lproj. By convention, these language-localized subdirectories are called lproj folders.

An lproj folder contains all the localized content for a given language and, possibly, a given region. You use the facilities of the NSBundle class or the CF Bundle Ref opaque type to locate (in one of the application’s lproj folders) resources localized for the currently selected language. Listing gives an example of such a directory containing content localized for English (en).

The contents of a language-localized subdirectory

This subdirectory example has the following items:

  • The InfoPlist.strings file contains strings assigned as localized values of certain properties in the project’s Info.plist file (such as CF Bundle Display Name). For example, the CF Bundle Display Name key for an application named Battleship in the English version would have this entry in InfoPlist.strings in the fr.lproj subdirectory:
  • The Localizable.strings file contains localized versions of strings generated by application code.
  • The sign.png file in this example is a file containing a localized image.

To internationalize strings in your code for localization, use the NSLocalizedString macro in place of the string. This macro has the following declaration:

The first parameter is a unique key to a localized string in a Localizable.strings file in a given lproj folder. The second parameter is a comment that indicates how the string is used and therefore provides additional context to the translator. For example, suppose you are setting the content of a label (UILabel object) in your user interface. The following code would internationalize the label’s text:

You can then create a Localizable.strings file for a given language and add it to the proper lproj folder. For the above key, this file would have an entry similar to the following:


Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

IPHONE APPS Topics