iPhone – Localization

Localization is a must in mobile application development. The article will shows you how to localize your iPhone Application in just a few steps.

1. Whenever you need a localized string in your application, use the NSLocalizedString(NSString *key, NSString *comment).

[self.label1 setText:NSLocalizedString(@"label1.text", @"Label1 in MyViewController.m")];
[self.label2 setText:NSLocalizedString(@"label2.text", @"Label2 in MyViewController.m")];
[self.label3 setText:NSLocalizedString(@"label3.text", @"Label3 in MyViewController.m")];

 

2. Generate the Localizable.strings file using the genstrings command under your Xcode project directory.

 

3. Add the Localizable.strings to your Xcode project with UTF-16 encoding.

                                       

4. Open the Info of the Localizable.strings and click Make File Localizable.

 

5. Go to the General tab and add as many as localizations you want with language code as the localization name.

 

6. The Localizable.strings is split and you can now edit the localized string with each key.

 

7. You can try it now~

 

Please note that you can change your iPhone/iPhone Simulator preferred language in Settings -> General -> International -> Language.
 

Done =)

Reference:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.