Created
April 11, 2019 11:57
-
-
Save brkphp/843893f0181f193f594c3e9930147a84 to your computer and use it in GitHub Desktop.
swift easy localizable
This file contains hidden or 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
| // | |
| // Localizable.swift | |
| // AnimatedLivePaper | |
| // | |
| // Created by Burak on 4/11/19. | |
| // Copyright © 2019 | |
| // | |
| import Foundation | |
| import UIKit | |
| protocol Localizable { | |
| var localized: String { get } | |
| } | |
| protocol StoryboardLocalizable { | |
| var localizationKey: String? { get set } | |
| } | |
| extension String: Localizable{ | |
| var localized: String { | |
| return NSLocalizedString(self, comment: self) | |
| } | |
| func localize(_ args: CVarArg...) -> String { | |
| return String(format: self.localized,arguments: args) | |
| } | |
| } | |
| extension UILabel: StoryboardLocalizable { | |
| @IBInspectable public var localizationKey: String? { | |
| get { return nil } | |
| set(key) { | |
| text = key?.localized | |
| } | |
| } | |
| } | |
| extension UIButton: StoryboardLocalizable { | |
| @IBInspectable public var localizationKey: String? { | |
| get { return nil } | |
| set(key) { | |
| setTitle(key?.localized, for: .normal) | |
| } | |
| } | |
| } | |
| extension UINavigationItem: StoryboardLocalizable { | |
| @IBInspectable public var localizationKey: String? { | |
| get { return nil } | |
| set(key) { | |
| title = key?.localized | |
| } | |
| } | |
| } | |
| extension UIBarItem: StoryboardLocalizable { | |
| @IBInspectable public var localizationKey: String? { | |
| get { return nil } | |
| set(key) { | |
| title = key?.localized | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment