Omer Waqas Khan
Omer Waqas Khan

Reputation: 2413

iPhone application localization

In my MainViewController I am using this code:

static NSBundle *bundle = nil;

+(void)setLanguage:(NSString *)l {

NSLog(@"preferredLang: %@", l);
NSString *path = [[ NSBundle mainBundle ] pathForResource:l ofType:@"lproj" ];
bundle = [[NSBundle bundleWithPath:path] retain];}


+(void)initialize {

NSUserDefaults* defs = [NSUserDefaults standardUserDefaults];
NSArray* languages = [defs objectForKey:@"AppleLanguages"];
NSString *current = [[languages objectAtIndex:0] retain];
[self setLanguage:current];
}

+(NSString *)get:(NSString *)key alter:(NSString *)alternate {
return [bundle localizedStringForKey:key value:alternate table:nil];}

And in application main:

[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"tr", @"en", nil] forKey:@"AppleLanguages"];

Its working fine and showing the turkish language in my application other than the iPhone native language. But, I want to allow the user to change the language through buttons, like if user clicks on english language button, a dialogue should open that application will be restarted and your lang will be changed.

How to do that?

I am using iOS 5....

Upvotes: 1

Views: 242

Answers (1)

Thomas Zoechling
Thomas Zoechling

Reputation: 34243

Your app should not provide a custom language selector.
Users probably have prior knowledge on how to change the preferred language by navigating to General > International > Language in the Settings application.

Further details in Apple's Internationalization Programming Guide

Upvotes: 3

Related Questions