Tutorial: iPhone Localization in Xib (Nib) Files

This tutorial is about localizing your Nib(.xib) files inside your iPhone application. I will write another tutorial to localized your application from your Xcode code as well. You might read few tutorials on Localization in iPhone but I am going to write for those who try those and didnt get success. So this tutorial is for one of my friend Waqas Qureshi.If you are not interested to read about theory please skip following two paragraphs.

What is Localization in iPhone? Translate your application in multiple languages. In simple words you want that your application will be easily understandable in different languages. So you want to localized your application in French/German or any other language. iPhone support more then 22 languages and I hope in SDK 3.0 it will support more then that. Localization is a very important feature which you can easily achieve in iPhone.

What are the steps? iPhone has a robust localization architecture that let you easily translate your application in to multiple languages. So its easy if you start your application with that architecture because it will be hard for you to convert your application localized at the end. So please make sure if you want to have this feature in your application, build your application accordingly and do not put this feature in phase two on your application.

Please follow the following steps to make your application localized. In this tutorial I will localized application in French. Output of this project will look like this for two languages (English and French)
30 Tutorial: iPhone Localization in Xib (Nib) Files31 Tutorial: iPhone Localization in Xib (Nib) Files
1. Create a new project in Xcode and name it LocalizediPhone (I place it in Desktop)

15 Tutorial: iPhone Localization in Xib (Nib) Files

2. Open LocalizediPhoneAppDelegate.m file in Xcode and change the applicationDidFinishLaunching method, such that it shows your TitleBar.

- (void)applicationDidFinishLaunching:(UIApplication *)application {
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:viewController];
// Override point for customization after app launch
[window addSubview:navController.view];
[window makeKeyAndVisible];

3. Now open LocalizediPhoneViewController.m file and in viewDidLoad function write this code

- (void)viewDidLoad {
NSLocale *locale = [NSLocale currentLocale];
NSString *titleOFApplication = [locale displayNameForKey:NSLocaleIdentifier value:[locale localeIdentifier]];
self.title = titleOFApplication;
[super viewDidLoad];

4. Now run the application and you will see English in Title

21 Tutorial: iPhone Localization in Xib (Nib) Files

5. Now change the language of your iPhone. Close this application(by pressing home button in iPhone) and open Settings application. Move to General > International > Region Format, and select French. Now click on Back button (International). Now selected Language row in International view and change your language to French. Press Done button and your iPhone will change the language.
31 Tutorial: iPhone Localization in Xib (Nib) Files

6. Now in Xcode run the application again and you will see the change in Title.
41 Tutorial: iPhone Localization in Xib (Nib) Files

7. Now it times to change in Xib Files. Open LocalizediPhoneViewController.xib from your Xcode and place 4 labels inside View.

51 Tutorial: iPhone Localization in Xib (Nib) Files

8. Close the Xib file (LocalizediPhoneViewController.xib) and in Xcode “Group and files” panel expand “NIB Files”. Right click on it (LocalizediPhoneViewController.xib) and select “Get Info”

61 Tutorial: iPhone Localization in Xib (Nib) Files71 Tutorial: iPhone Localization in Xib (Nib) Files

9. Now select “General” tab and in bottom left click “Make File Localizable”, you will be navigate to “Target”. Close this Info window and you will see under “NIB Files” an expander under “LocalizediPhoneViewController.xib” file. You will see “English” file. Right click on it and select “Reveal in Finder”. You will see a new folder inside your code project (English.lproj)

81 Tutorial: iPhone Localization in Xib (Nib) Files91 Tutorial: iPhone Localization in Xib (Nib) Files101 Tutorial: iPhone Localization in Xib (Nib) Files

[Note: Nothing has been changed so far, you can run your application and it will behave the same way. Now it times to add French in your application. If it does not, do not get panic and continue reading below]

10. Now inside your Xcode project, right click on LocalizediPhoneViewController.xib file and select “Get Info”. Select “General” tab and click on “Add Localization” in bottom left. In popup type “fr” without quotes and press “Add button”. You will see fr will be added in Info window. Close this window and you will see “fr”(xib) file is added under English(xib) file. If you right click on “fr”(xib) file and select “Reveal in Finder”. You will see a new folder in your code project (fr.lproj)

111 Tutorial: iPhone Localization in Xib (Nib) Files121 Tutorial: iPhone Localization in Xib (Nib) Files131 Tutorial: iPhone Localization in Xib (Nib) Files

141 Tutorial: iPhone Localization in Xib (Nib) Files

151 Tutorial: iPhone Localization in Xib (Nib) Files16 Tutorial: iPhone Localization in Xib (Nib) Files

11. Open “fr”(xib) file in interface builder. Change the text of labels in to French language(i use google translation).

17 Tutorial: iPhone Localization in Xib (Nib) Files

Now everything is setup for this tutorial. If you are using iPhone simulator then select from menu “iPhone Simulator” and select “Reset content and settings”. It will make your iPhone simulator language to English. Open Settings application in iPhone, and move to “General”> “International”. Your “Region format” is “United States” and Language is “English”. (Your Setting screen should look like this.)

18 Tutorial: iPhone Localization in Xib (Nib) Files19 Tutorial: iPhone Localization in Xib (Nib) Files

20 Tutorial: iPhone Localization in Xib (Nib) Files

Open Xcode and run your application, it will be shown like this

30 Tutorial: iPhone Localization in Xib (Nib) Files

[Note: If it does not show the changes we made. Do not worry about this, iPhone or iPhone simulator stored your application information in cache. So you have to remove your application from iPhone/iPhone simulator first. Then move to ~/Library/Application Support/iPhone Simulator/ ( here ~ means your home directory) and delete "User" folder. Clean your Xcode project by pressing Cmd+ Shift+K (or in menu go to "Build" > "Clean". Run the application again and it will show you the changes]

Now we want to see how its look like in French language. Repeat point 5 again and launch the application in Xcode. It will shown like this

31 Tutorial: iPhone Localization in Xib (Nib) Files

[Note: If it still shown the English xib file please repeat the above note (i.e deleting the application from iPhone, cleaning your Xcode project and delete the User folder form ~/Library/Application Support/iPhone Simulator/).]

You can grab the code from here. Also you can get the complete list of country codes http://www.iso.org/iso/country_codes.html (i.e for Itly, German and other languages)
[Update: check out part 2 of localization]

Popularity: 24% [?]

My name is Adeem M Basraa. I am a software engineer from Lahore, PK. I’ve been involved in software development for nearly 4 years, with the last 1 year focused on application development for mobile devices (iPhone & Android).

24 Comments on "Tutorial: iPhone Localization in Xib (Nib) Files"

  1. Alex Curylo says:

    Here’s a post I just did with some more tips and tools for localization.


  2. admin says:

    Thank for sharing the link :) I already written another tutorial about localization will share with you as well :)

  3. Geoffroy says:

    Thanks for picking French! That was cool! Just a minor comment. To be consistent you would want to have all questions using either the familiar form (tu) or the formal form (vous). In case of the later the first question would become “Comment vous appelez-vous?”. In case of the former you would replace “vous” with “ta” (questions 2 and 3) and “ton” (question 4). For “hobby” I would suggest “passe-temps”?
    Thanks for the article. I’ll be applying it soon!

  4. admin says:

    Thank you for your comments ( I am sorry, i do not know much about French) :) I will change the text on weekend.

  5. Amir Helzer says:

    Great tutorial. I guess that you’re using Google translation just for this tutorial, as machine translation will not give you good enough translation for real users.

    This must be the iPhone localization guide week. It just so happens that I finished my own iPhone localization guide today:

    We’re running a translation service, and have commercial interest in this, but still I hope that our guide is helpful for anyone (or clients or not).

  6. mcr says:

    Why do we need two xib files ? Can’t we sent the questions text similar to how titleOFApplication is set ?

    separate xib files may make sense if the UI elements are different for the locales?

  7. I was going to ask the same question as “mcr”, if the interface is not different for each local why not just change the text labels based on the language chosen, why do you need to create another xib file, seems like a lot of extra un-needed work.

  8. Adeem Basraa says:

    @James & MCR
    I will check and let you know. I think its a must thing to do but i will verify this and update you tonight.

  9. MLBT says:

    Hey thanks for the tutorial works like a charm! Just one question what can you do for alerts or action sheets? is there a way to localized them also?… because they are not in define in the xib file….

  10. Adeem Basraa says:

    did you read the 2nd part of this tutorial series? check out http://adeem.me/blog/2009/05/10/tutorial-part-2-localizing-your-iphone-application/ might be helpful for you!

  11. Mehta says:

    Hi, I am developing one iPhone application, in which I have to translate user data in other language. It is not web application but I can use Google translation services. So I cannot understand that how can I call that from my application.Can you help me for that?? Any suggestion??? Thanks.

  12. Adeem Basraa says:

    I guess you have to call google something like this
    where you can see de= German & en = English and next to it is the sentence you want to translate. I guess it involves a little bit of parsing in objective C or on your server side.

  13. Mehta says:

    I have tried link as you shown above but it doesn’t work. Do you have any other clue for that?? Thanks.

  14. Adeem Basraa says:

    can you shear the code with me, i will check this out and tells you.

  15. raghu nandan says:

    Hi adeem how can i localize the dynamic content,For example the content which i am retriving from web services.thanks a lot for the previous post.

  16. Rahul Sharma says:

    Thanks Adeem for a nice tutorial. Keep it up. Just a quick question here what about the IBOutlets and action methods for the elements of particular nib file. Will we have to link them up separately i.e for en and fr files?

  17. Ali says:

    thank you this was really useful

  18. CJ says:

    My xcode(4.0.2) is not letting me change the fr.xib file, a lock appears every time I try to. Is there a setting that im missing?

Trackbacks for this post

  1. Tutorial Part 2 for iPhone to localized your application | Localized your iPhone application using genstrings | Localization of your iPhone application using xcode | Different languages for your iPhone applciation | iPhone Diary
  2. iPhone Tutorial Roundup « Purposefully
  3. Localize an iPhone App « Brainwash Inc. – iPhone/Mobile Development
  4. Localize – Localization an iPhone application « Brainwash Inc. – iPhone/Mobile Development
  5. ONE AND ONE MAKES TEN - Incremental localization on XCode-based projects
  6. Tutorial: iPhone Localization in Xib (Nib) Files | Bookmarks

Got something to say? Go for it!