Setting “AppleLanguages” doesn't change app language

前端 未结 7 1872
无人及你
无人及你 2020-12-01 19:29

I am trying to implement a function that can change app language.
I tried to set it like this:

let defaults = NSUserDefaults.standardUserDefaults()
defa         


        
7条回答
  •  误落风尘
    2020-12-01 19:50

    Updated Swift syntax of the main.swift file mentioned in @royherma's answer. This will avoid having to restart the app after overriding the UserDefaults settings:

    import Foundation
    import UIKit
    
    // Your initialization code here
    let langCultureCode: String = "LANGUAGE_CODE"
    
    UserDefaults.standard.set([langCultureCode], forKey: "AppleLanguages")
    UserDefaults.standard.synchronize()
    
    UIApplicationMain(CommandLine.argc, CommandLine.unsafeArgv, nil, NSStringFromClass(AppDelegate.self))
    

    paired together with the removal of @UIApplicationMain in your AppDelegate.swift file.

提交回复
热议问题