views:

26

answers:

1

Hello,

i am currently working on an iPad app (iOS SDK v3.2). The app is localized in several languages, i.e. english, german, russian, ...

I want the user to be able to switch the localization for some UI elements after the app has been started. What is the best way to achieve this? NSLocalizedString always chooses the locale defined in the system preferences, so that won't help.

Note: the localization is all done by using .strings files, there are no localized NIBs in my project.

To make the whole process more clear, here's an example: When the app is started the UI is displayed in english. The user can select a different language from a UITableView and parts of the UI get updated with the chosen language.

Do i have to manually load the specific Localizable.strings file and parse it all the way through or is there a better option, to get the relevant strings?

Any helpful advice is appreciated.

Thank you very much in advance and best regards.

+1  A: 

I guess i found an answer to my own question:

NSLocale *selectedLocale; // defined in the classes interface
NSString *language = [selectedLocale objectForKey:NSLocaleLanguageCode];
NSString *path = [[NSBundle mainBundle] pathForResource:language ofType:@"lproj"];
NSBundle *bundle = [NSBundle bundleWithPath:path];

self.textView.text = NSLocalizedStringFromTableInBundle(@"Yadayada", @"Localizable", bundle, @"Yadayada comment");
XCoder