1

I am using the following code to return a localized string:

[self.languageBundle localizedStringForKey:key value:key table:nil];

In case of English, there is no problem. However, for Dutch, it defaults to English. To make everything clear, self.languageBundle is an empty bundle that's copied in the first launch. Then two localization directories are created (en.lproj and nl.lproj), and Localizable.strings file is created in both directories and filled with correct localization strings (I checked them).

I change the language using:

[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObject:@"nl"]
                                                  forKey:@"AppleLanguages"];
[[NSUserDefaults standardUserDefaults] synchronize];

However, it still loads localization inside en.lproj instead of nl.lproj

Abdalrahman Shatou
  • 4,550
  • 6
  • 50
  • 79

2 Answers2

0

If you have added your localized.string file in the project then delete all other localized files which are created automatically in the project.Try out this link

Community
  • 1
  • 1
V-Xtreme
  • 7,230
  • 9
  • 39
  • 79
0

It looks like you are trying to change the language during runtime and Apple doesn't officially support this. Changing the key for "AppleLanguages" will only take effect after you close and restart the app.

However it is possible to change the localization for your app at runtime, see answer of this question.

In the aggressive-mediocrity solution you keep your own language code variable, and create a custom LocalizedString function (in example source "AMLocalizedString") instead of using NSLocalizableString. It's a good solution which I've used it in one of my projects, and the app was approved by Apple without problems.

Also, this way you can use the default Localizable.strings files as you would normally, so there's no need to create directories and copy Localizable.strings at the first app launch.

Community
  • 1
  • 1
BdR
  • 2,770
  • 2
  • 17
  • 36
  • I need to add the localization strings at runtime. I got them using a web service (a JSON parsed into NSDictionary written to a Localizable.strings file). So the second parts is not feasible. Regarding the first part, it doesn't work even after restarting. It also doesn't work when I change the language from Settings. Always defaulting to English. – Abdalrahman Shatou Dec 04 '12 at 08:06