Created
September 3, 2018 05:45
-
-
Save leoiphonedev/7f631a539a3fbbc9027e907de4adf9e9 to your computer and use it in GitHub Desktop.
Using LocalizationSystem and changing app language from inside of the app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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