Post navigation

Localization in Xib (Nib) Files

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.

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)

1) Create a new project in Xcode and name it LocalizediPhone (I place it in Desktop)

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

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.

6) Now in Xcode run the application again and you will see the change in Title.

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

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”

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)

& then do as follows

& then illustrated as follows

[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]

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)

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

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.)

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

[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

[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/).]

About Nimit Parekh

Hey ! I am Nimit S. Parekh a passionate mobile application developer from India.. I am always hunting for better knowledge in iOS. I am looking forward to be a good app & game developer. I keep on sharing my knowledge @ http://sugartin.info as soon as I get spare time for it. I would love to hear your personal feedback about this blog.