4

i have an app that have two localizations (hebrew and english), and i've been asked to cancel the english localization so that whatever your device's language, the app will be the same (but save the localization for future use).

the localization is via Localizable.strings and also Xib localization (allot of them).

is there a way to tell the app to always use a certain localization and ignore the device language?

thanks !

dowi
  • 1,005
  • 15
  • 30

2 Answers2

4

I have adapted this to Swift and use this to test localizations with ease. When placed in AppDelegate->didFinishLaunchingWithOptions the simulator needs to run twice to get the correct settings, but maybe there is a better way.

In the example Danish localization is used and more can be found here: Locale codes for iPhone lproj folders

let langCultureCode: String = "da"
let defaults = NSUserDefaults.standardUserDefaults()
defaults.setObject([langCultureCode], forKey: "AppleLanguages")
defaults.synchronize()

And to remove the defaults once again:

let defaults = NSUserDefaults.standardUserDefaults()
defaults.removeObjectForKey("AppleLanguages")
defaults.synchronize()
Community
  • 1
  • 1
scbojer
  • 144
  • 4
  • 1
    You have no idea how much you've saved my life. In my app I was struggling forcing MapView results ( cityName , countryName ) to display in english instead of local results ( **Arabic** ). And this did the trick. Seven blessings on your soul! – Khaledonia Oct 06 '17 at 06:37
3

in that case just set the defaults key AppleLanguages EARLY at startup to override IOS settings

(EARLY = before a xib/storyboard or NSLocalizedString is used)

NSString *langCultureCode = @"he";
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:@[langCultureCode] forKey:@"AppleLanguages"];
[defaults synchronize];
Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
  • thanks!! it works ( i used he instead of he_IL). thanks allot! – dowi Jun 01 '14 at 08:26
  • but I think it needs to reload root view after that to see change immediately. – user2526811 Jul 07 '16 at 06:07
  • 1
    Any way to make this work on the first time the app loads? It seems that the forced localization only works the second time the app is loaded, even if the snippet is called in the first line of `didFinishLaunchingWithOptions` – royherma Jul 17 '16 at 02:41
  • You have to do this in main.m in order for it to work 100% of the time. Would not recommend this approach for app that needs to be submitted. – Boon Mar 06 '17 at 22:17