Herbert Poul
Herbert Poul

Reputation: 4883

Change locale for current iphone application (custom locale for NSBundle?)

i want to change the locale programmatically in my iphone app (basically because not all languages are supported by iphone itself, it should be possible for the user to switch language only for my application). I have seen on a different question How to force NSLocalizedString to use a specific language that on OSX apps? it should work with [[NSUserDefaults standardUserDefaults] setObject: [NSArray arrayWithObjects:@"de", nil] forKey:@"AppleLanguages"]; - but for me it doesn't... [NSLocale currentLocale] still returns the system wide locale and the 'main bundle' gives me files from the system wide locale..

so.. is there a way to set a custom locale for my application? or - which would be sufficient for me - create a new NSBundle instance with a different locale?

Upvotes: 2

Views: 6936

Answers (1)

Herbert Poul
Herbert Poul

Reputation: 4883

ok, stupid me.. as the question linked already answered.. that code requires a restart.. ie. when the user selects another language call [[NSUserDefaults standardUserDefaults] setObject: [NSArray arrayWithObjects:@"de", nil] forKey:@"AppleLanguages"]; - the next time the application is launched the [NSBundle mainBundle] will return the correct resources for the given locale.. (although [NSLocale currentLocale] will still return the iphone-wide locale.. but i think this doesn't matter to me anyway...)

Upvotes: 2

Related Questions