|
| 1 | +// |
| 2 | +// IBDesignable+Localize1.swift |
| 3 | +// Localize-Swift |
| 4 | +// |
| 5 | +// Created by BinaryBoy on 7/23/19. |
| 6 | +// |
| 7 | + |
| 8 | +import Foundation |
| 9 | + |
| 10 | +// MARK: - UILabel localize Key extention for language in story board |
| 11 | + |
| 12 | +@IBDesignable public extension UILabel { |
| 13 | + @IBInspectable var localizeKey: String? { |
| 14 | + set { |
| 15 | + // set new value from dictionary |
| 16 | + DispatchQueue.main.async { |
| 17 | + self.text = newValue?.localized() |
| 18 | + } |
| 19 | + } |
| 20 | + get { |
| 21 | + return self.text |
| 22 | + } |
| 23 | + } |
| 24 | +} |
| 25 | + |
| 26 | +// MARK: - UIButton localize Key extention for language in story board |
| 27 | + |
| 28 | +@IBDesignable public extension UIButton { |
| 29 | + |
| 30 | + @IBInspectable var localizeKey: String? { |
| 31 | + set { |
| 32 | + // set new value from dictionary |
| 33 | + DispatchQueue.main.async { |
| 34 | + self.setTitle(newValue?.localized(), for: .normal) |
| 35 | + } |
| 36 | + } |
| 37 | + get { |
| 38 | + return self.titleLabel?.text |
| 39 | + } |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +// MARK: - UITextView localize Key extention for language in story board |
| 44 | + |
| 45 | +@IBDesignable public extension UITextView { |
| 46 | + |
| 47 | + @IBInspectable var localizeKey: String? { |
| 48 | + set { |
| 49 | + // set new value from dictionary |
| 50 | + DispatchQueue.main.async { |
| 51 | + self.text = newValue?.localized() |
| 52 | + } |
| 53 | + } |
| 54 | + get { |
| 55 | + return self.text |
| 56 | + } |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +// MARK: - UITextField localize Key extention for language in story board |
| 61 | + |
| 62 | +@IBDesignable public extension UITextField { |
| 63 | + @IBInspectable var localizeKey: String? { |
| 64 | + set { |
| 65 | + // set new value from dictionary |
| 66 | + DispatchQueue.main.async { |
| 67 | + self.placeholder = newValue?.localized() |
| 68 | + } |
| 69 | + } |
| 70 | + get { |
| 71 | + return self.placeholder |
| 72 | + } |
| 73 | + } |
| 74 | +} |
| 75 | + |
| 76 | +// MARK: - UINavigationItem localize Key extention for language in story board |
| 77 | + |
| 78 | +@IBDesignable public extension UINavigationItem { |
| 79 | + |
| 80 | + @IBInspectable var localizeKey: String? { |
| 81 | + set { |
| 82 | + // set new value from dictionary |
| 83 | + DispatchQueue.main.async { |
| 84 | + self.title = newValue?.localized() |
| 85 | + } |
| 86 | + } |
| 87 | + get { |
| 88 | + return self.title |
| 89 | + } |
| 90 | + } |
| 91 | +} |
0 commit comments