how to force an ios app to use a certain localization?

夙愿已清 提交于 2019-12-23 19:38:50

问题


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 !


回答1:


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];



回答2:


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()


来源:https://stackoverflow.com/questions/23977816/how-to-force-an-ios-app-to-use-a-certain-localization

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!