Alex Rivera | Logout

Creating a localized iPhone app but allowing the user to change language for the application

Asked 2009-08-07T17:21:35.160
15

I'm working on a localized app and everything is working fine. The problem is I want to allow the user to specifically select the lenguage for the specific app, in the app settings folder. This should users that their phone is set to one language (e.g. french) to set the app to work in English.

I'm currently using NSLocalizedString to get localized string but looking through all variation of the macro I can't find one that will let me specify the language.

Any ideas on how to do it?

Edit
Report

2 Answers

13

There is a better way to do this. You can force the language like so:

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

And undo this setting by:

[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"AppleLanguages"];

NB. you will normally have to restart the app for this to take affect.

Consider if you need to call [[NSUserDefaults standardUserDefaults] synchronize];

I agree there is little need to allow the user to specify a language. However the one exception is being able to override the language and set it to the developer's native language. If the user can speak the developer's language (e.g. English for me) then they may wish to use the App in that language, if the translations are incorrect.

I reference this answer: How to force NSLocalizedString to use a specific language (the answer doesn't actually work for me, but following the ideas in the comments did. The undo stuff I worked out.

answered 2010-03-10T15:11:09.520
3

The trick to use specific language by selecting it from the app is to force the NSLocalizedString to use specific bundle depending on the selected language ,

here is the post i have written for this http://learning-ios.blogspot.com/2011/04/advance-localization-in-ios-apps.html

and here is the code of one sample app https://github.com/object2dot0/Advance-Localization-in-ios-apps

answered 2011-05-01T17:55:07.017

Your Answer