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

后端 未结 2 948
小蘑菇
小蘑菇 2021-01-19 23:16

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 wil

2条回答
  •  醉梦人生
    2021-01-19 23:25

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

提交回复
热议问题