Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leoiphonedev/7f631a539a3fbbc9027e907de4adf9e9 to your computer and use it in GitHub Desktop.
Save leoiphonedev/7f631a539a3fbbc9027e907de4adf9e9 to your computer and use it in GitHub Desktop.
Using LocalizationSystem and changing app language from inside of the app
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var lblHeader: UILabel!
@IBOutlet weak var btnChangeLangauge: UIButton!
@IBOutlet weak var lblCurrentLanguage: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
lblHeader.text = LocalizationSystem.sharedInstance.localizedStringForKey(key: "header_text", comment: "")
lblCurrentLanguage.text = LocalizationSystem.sharedInstance.getLanguage()
btnChangeLangauge.setTitle(LocalizationSystem.sharedInstance.localizedStringForKey(key: "change_language", comment: ""), for: .normal)
}
@IBAction func changeLanguage(_ sender: Any) {
if LocalizationSystem.sharedInstance.getLanguage() == "ar" {
LocalizationSystem.sharedInstance.setLanguage(languageCode: "en")
UIView.appearance().semanticContentAttribute = .forceLeftToRight
} else {
LocalizationSystem.sharedInstance.setLanguage(languageCode: "ar")
UIView.appearance().semanticContentAttribute = .forceRightToLeft
}
let vc = self.storyboard?.instantiateViewController(withIdentifier: "vc") as! ViewController
let appDlg = UIApplication.shared.delegate as? AppDelegate
appDlg?.window?.rootViewController = vc
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment