From 7b52bb63c7e4a46b518414b23e8eadc8d8397354 Mon Sep 17 00:00:00 2001 From: PrashantKT <35359315+PrashantKT@users.noreply.github.com> Date: Sat, 10 Mar 2018 19:09:02 +0530 Subject: [PATCH 1/2] Create LocalizableUIl.swift This allows user to directly set Localised label or button from storyboard. by just setting the class name. with two parameters table and key. Hope it may helpful to others --- LocalizableUIl.swift | 56 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 LocalizableUIl.swift diff --git a/LocalizableUIl.swift b/LocalizableUIl.swift new file mode 100644 index 0000000..c3fd846 --- /dev/null +++ b/LocalizableUIl.swift @@ -0,0 +1,56 @@ +// +// LocalizableUIl.swift +// Localize_Swift +// +// Created by Prashant Tukadiya +// + +import UIKit +import Localize_Swift + + + +@IBDesignable class LocalizableLabel: UILabel { + + @IBInspectable var table :String? + @IBInspectable var key:String? + + override func awakeFromNib() { + guard let key = key else {return} + self.text = key.localized(using: table) + NotificationCenter.default.addObserver(self, selector: #selector(setText), name: NSNotification.Name(LCLLanguageChangeNotification), object: nil) + + } + + @objc func setText () { + guard let key = key else {return} + self.text = key.localized(using: table) + + } + +} + + +@IBDesignable class LocalizableButton: UIButton { + + @IBInspectable var table :String? + @IBInspectable var key:String? + + override func awakeFromNib() { + guard let key = key else {return} + self.setTitle(key.localized(using: "HomeScreen"), for: .normal) + NotificationCenter.default.addObserver(self, selector: #selector(setText), name: NSNotification.Name(LCLLanguageChangeNotification), object: nil) + + } + + @objc func setText () { + guard let key = key else {return} + self.setTitle(key.localized(using: "HomeScreen"), for: .normal) + + } + +} + + + + From 00bb640e92abb93d14331726b8bf8147612a596a Mon Sep 17 00:00:00 2001 From: PrashantKT <35359315+PrashantKT@users.noreply.github.com> Date: Mon, 16 Apr 2018 12:07:34 +0530 Subject: [PATCH 2/2] Added support for navigation item Set this subclass as your navigation item in your storyboard and pass `key` of your localised string --- LocalizableUIl.swift | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/LocalizableUIl.swift b/LocalizableUIl.swift index c3fd846..305fdc1 100644 --- a/LocalizableUIl.swift +++ b/LocalizableUIl.swift @@ -51,6 +51,26 @@ import Localize_Swift } +// Set this subclass as your navigation item in your storyboard and pass `key` of your localized string +@IBDesignable class LocalizeUINavigationItem: UINavigationItem { + + @IBInspectable var table :String? + @IBInspectable var key:String? + + override func awakeFromNib() { + guard let key = key else {return} + self.title = key.localized(using: table) + NotificationCenter.default.addObserver(self, selector: #selector(setText), name: NSNotification.Name(LCLLanguageChangeNotification), object: nil) + + } + + @objc func setText () { + guard let key = key else {return} + self.title = key.localized(using: table) + + } + +}