views:

41

answers:

3

Hi,

Is it possible to have my app running in a different language than the one that is set in the OS? I want to have a language switch in my app’s setting menu, where the user can e.g. select german for the app, while his system is running in english.

From what I’ve already read, it seems it’s not possible without having my own localization mechanism…

What do you think?

Cheerz, pawi

A: 

I have an app named Chirp! which does this. My main OS is in English but I can get the bird's names and descriptions in Swedish. Perhaps you can contact the publisher (http://spinysoft.co.uk/ispiny) and ask how they have solved it?

Lizzan
Hi there, Thanks for your Answers. It was the customers request, to do that :-) I life in Switzerland, we have People with iPhone's language set to french / italian, working in the german part of Switzerland. I guess they want to use the app in german when working... Anyways
pawi
A: 

You need to implement your custom resource loading mechanism to achieve that. For example you will no longer be able to use NSLocalizedString macro or [NSBundle pathForResource:]. You will always have to specify paths including the localization (as in de.lproj/MyStrings.strings instead of just MyStrings.strings). I would suggest against doing this unless absolutely necessary.

Steam Trout
A: 

Hi pawi,

it can be done easily although it took me weeks to work out how ;-)

I have an iPhone app called iDEX which is a Romanian dictionary. On the iPad, Romanian is not available as a UI language, so I wanted to give the user the option of selecting Romanian in the application settings, as the device settings do not include it.

What you have to do is internationalize the app and localize it as usual. Then, in the main method, set the AppleLanguages key of the standard NSUserDefaults to the language and country of your choice, like so

int main(int argc, char *argv[]) {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    [defaults setObject:[NSArray arrayWithObject:@"ro_RO"] forKey:@"AppleLanguages"];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool drain];
    return retVal;
}

It is imperative that you set the AppleLanguages key before you run UIApplicationMain(), because it is at that point that the UIKit framework is loaded and the default language determined.

It also important that you specify both language and country (eg, @"ro_RO" and not just @"ro") otherwise your app might crash when setting the key.

By doing this, all calls to NSBundle that support localization will look for the language that you have programatically established, as opposed to the one set on the device.

Hope that helps...

fedmest