How to support localization for your application on iPhone development
Here is the simple steps to achieve this:
1. Collect the text in whatever the languages that you are needed in.
2. Create any kind of project in Xcode.
3. Open the project folder through finder.
4. Create new folders called "en.lproj" for English language, "es.lproj" for Spanish language, "it.lproj" for Italian language, "ja.lproj" for Japanese language, "de.lproj" for Deutch language, under your project in finder.
5. Launch your project in Xcode.
6. Right click "Resources" folder and click on "Add"-> "New File".
7. In the 'choose template ....' section, look for "Other" section (which will be in the last), and Choose "Strings File" from the right side tab.
8. Name it as "Localizable.strings" and Save it under the folder "en.lproj"(which u created in step 4). Continue creating another "Localizable.strings" and Save it under the folder "es.lproj"... like-wise continue doing it upto how many *.lproj you have created. In my example, i created "Localizable.strings" and Save it under upto "de.lproj" folder.
[Xcode is smart enough to figure out the folder and sitting there properly, which you could see there..]
9. Handling Localization here is matter of adding two values. One is "Key" and other is "Value". Format is looking like
"Key" = "Value";
Let us see the below sample of adding Key-Value pair from the resource.
10. Choose "en.lproj" in Xcode project resource and add welcome text in this
format -> "WelcomeKey" = "Welcome!"
Same for this in Italian language will be, "WelcomeKey" = "Benvenuto!"
Same for this in Spanish language will be, "WelcomeKey" = "Bienvenida!"
Likewise add the text in the languages whatever you want.
11. We will see next how to access this in code:
It is pretty simple, it does by an API called "NSLocalizedString("key", "comment")";
We can leave second parameter "comment" parameter blank as it does serve a purpose of generating the strings file automatically.
For example, If i want to localize the above mentioned Welcome text and put in a label. Here is the sample below.
myLabel.text = NSLocalizedString(@"WelcomeKey", "");
Result will be,
Whenever user chooses the language on iPhone from settings, it takes welcome text for that languages which we added in our *.lproj file and show in label. If the text is not available for particular chosen language, then it picks text from the second language in the list.
That's it to achieve this!!! If any doubts or comments. Please leave here.
Thank you.
Cheers!
M.P.Prabakar
Senior Systems Analyst.
Have fun and be addictive by playing "TossRing" marvelous iPhone game. Link is below..
That’s what I was looking for. I am talking about all topics bundled in this blog. They all are really very useful for me as well as for my team. We are definitely going to use its highlighted information.
ReplyDeleteiphone Application Development Company