Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. //
  2. // Localizable.swift
  3. // AnimatedLivePaper
  4. //
  5. // Created by Burak on 4/11/19.
  6. // Copyright © 2019
  7. //
  8.  
  9. import Foundation
  10. import UIKit
  11.  
  12. protocol Localizable {
  13. var localized: String { get }
  14. }
  15.  
  16. protocol StoryboardLocalizable {
  17. var localizationKey: String? { get set }
  18. }
  19.  
  20. extension String: Localizable{
  21.  
  22. var localized: String {
  23. return NSLocalizedString(self, comment: self)
  24. }
  25.  
  26. func localize(_ args: CVarArg...) -> String {
  27. return String(format: self.localized,arguments: args)
  28. }
  29.  
  30. }
  31.  
  32. extension UILabel: StoryboardLocalizable {
  33. @IBInspectable public var localizationKey: String? {
  34. get { return nil }
  35. set(key) {
  36. text = key?.localized
  37. }
  38. }
  39. }
  40.  
  41. extension UIButton: StoryboardLocalizable {
  42. @IBInspectable public var localizationKey: String? {
  43. get { return nil }
  44. set(key) {
  45. setTitle(key?.localized, for: .normal)
  46. }
  47. }
  48. }
  49.  
  50. extension UINavigationItem: StoryboardLocalizable {
  51. @IBInspectable public var localizationKey: String? {
  52. get { return nil }
  53. set(key) {
  54. title = key?.localized
  55. }
  56. }
  57. }
  58.  
  59. extension UIBarItem: StoryboardLocalizable {
  60. @IBInspectable public var localizationKey: String? {
  61. get { return nil }
  62. set(key) {
  63. title = key?.localized
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement