Monday, 9 March 2015

How to add localization to your IOS app - Tutorial



IOS App Localization


Tags: #App Localization #IOS #Tutorial #Multi language 

In this post, we are going to learn about multi language iOS app support. Follow the below steps to add multi language support to your app. I am assuming that you had already created your project, if not then create it and start following below steps in order to add multi language support.

Step 1:  Right click on Supporting Files folder and click New File


IOS APP LOCALIZATION Screen 1

Step 2:  Select strings file from the drop down window. You can get there by selecting Resources under IOS on left side pane and then chose Strings file. Name it Localizable.strings

IOS APP LOCALIZATION Screen 2

Step 3: Select your project (not target) and navigate to info. In the bottom, you will see Localizations, click on + icon and add the language you want your app to be in.

IOS APP LOCALIZATION Screen 3

IOS APP LOCALIZATION Screen 4

Here, Xcode will prompt you to create localize string files for xib files or storyboard files. This is very helpful if you want to change text of button placed in xib file or on storyboard.(It only works if they are already created prior to localization)

Step 4: Select your Localizable.strings  file and on right side in inspector window click on Localize button. It will ask for permission. Select language from drop down menu and click localize.

IOS APP LOCALIZATION Screen 5
  
Step 5: No you will see Russian language file there too under Localizable.string file, select the Localizable.string file and checkmark the english checkbox so that we can set our english strings in that file.

IOS APP LOCALIZATION Screen 6

Now, its time to create keys and set there values in both files. You can create keys as shown here

IOS APP LOCALIZATION Screen 7

IOS APP LOCALIZATION Screen 8

No to use them, you can use below syntax

NSLocalizedString(NSString *key, NSString *comment)

Example:

    yesEng.text = NSLocalizedString(@"Yes", nil);
    noEng.text = NSLocalizedString(@"No", nil);

Here, yesEng and noEng are our IBOutlet to UILable.

Change you simulator/device language to Russian and run your app. If it does not work on simulator then run app on device to get the results.

OutPut:

English Language
English Language 
Russian Language
Russian Language

No comments:
Write comments