Here's a method that do what you want. I don't think there's another way to do that in the code.
// You can change 'Base' to 'en' if you don't have Base.lproj folder
func localizedString(_ key: String) -> String? {
if let path = Bundle.main.path(forResource: "Base", ofType: ".lproj"),
let baseBundle = Bundle(path: path) {
return baseBundle.localizedString(forKey: key, value: nil, table: nil)
}
return nil
}
EDIT: I found another way to do it based on this answer.
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
UserDefaults.standard.set(["Base"], forKey: "AppleLanguages")
UserDefaults.standard.synchronize()
// Rest of your init code
}
EDIT 2:
What you could do for the first launch of the app in the viewDidLoad
of your initial ViewController
:
if let languageArray = UserDefaults.standard.object(forKey: "AppleLanguages") as? [String],
languageArray.count >= 1,
languageArray[0] != "Base" && languageArray.count == 1 {
UserDefaults.standard.set(["Base"], forKey: "AppleLanguages")
UserDefaults.standard.synchronize()
}