2

I am trying to get a string from Localizable.string file. In my app users can change the language at run time using LanguageManger https://github.com/Abedalkareem/LanguageManger-iOS.

The problem is when I get a string from localizedstring I am getting string from the old selected language. The whole application language changed at run time but when I try to get the string like this it always gets the string from old file. After restart it works but I don't want to restart.

This is my code to get string:

let mystring  = NSLocalizedString("hello", comment: "")
print("----\(mystring)")

This is how users change the language:

let selectedLanguage:Languages = (sender as AnyObject).tag == 1 ? .en : .de
print(selectedLanguage)
// change the language
LanguageManger.shared.setLanguage(language: selectedLanguage)

// return to root view contoller and reload it
UIApplication.topViewController!.dismiss(animated: true) {
    let delegate = UIApplication.shared.delegate as! AppDelegate
    let storyboard = UIStoryboard(name: "Main", bundle: nil)
    delegate.window?.rootViewController = storyboard.instantiateInitialViewController()
}
Lukas Würzburger
  • 6,543
  • 7
  • 41
  • 75
Jhony
  • 187
  • 1
  • 4
  • 16

0 Answers0