views:

178

answers:

1

hi

how to change the language in iPhone application ?.

i mean eg : in my application one label is there i want put a dutch word . what is the easy way.

  1. read from property file

  2. make one static class in project with string variable.

or is possible any change in property file.

pls help me... thnx and regards all

+2  A: 

There is a ton of built infrastructure for this. Basically the NSBundle APIs have the concept of localization, and transparently redirect anything that goes through them to an appropriately localized version if one is available. If you have ever seen a ".lproj" in your bundle, that is for localization.

Okay, so the question is how do you set that up? With nibs it is easy, you just put multiple copies of the nib into your app, one in each lproj. Strings are a little bit trickier, what you do is create a Strings.localizable file, then whenever you need a string you get it by calling NSLocalizedString(), which will lookup the string in the Localized.strings file of your current language.

Xcode has some built in ways to set this up quickly. You can select any resource and bring up the Get Info window there will be a button titled "Make Localizable." Once you click that there will be another button "Add Localizations," which lets add specific localizations to the project. At this point there will be a disclosure triangle next to your resource that lets you edit the resource in each specific locale.

There are a number of different ways to handle some of these things, depending on your App, and there tools Apple provides to make this easier. This is a decent blog post about how to localize things.

The thing you should remember is that if you are looking up the localization and manually deciding what resources to use based on it you are probably doing it wrong. Most of the time you simply want to identify the place that requires localization and ask the system for the resource through an API that handles that for you (NSLocalizedString(), -[NSBundle pathForResource:ofType:], etc).

Louis Gerbarg
there's a problem with this approach. Suppose the user iphone is set to german an the application does not have localization for german. What happens? how to tell the application to use a "default" language in case the current language has not been translated?
Digital Robot
That is why you should use the built in infrastructure, it takes case of that sort of thing for you. Specifically, the phone looks at the localizations you have and chooses the best one it can, based on the users preferences. If your application only has one localization it will be used, regardless of what the user has specified, since it is the only one available.
Louis Gerbarg