Advertisement
Guest User

Untitled

a guest
Sep 20th, 2019
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 0.73 KB | None | 0 0
  1. "I don't use localizations (probably because there are about 30 language files)" I still didn't understood that.
  2. But I'd go with:
  3.  
  4.  
  5. protocol Translations {
  6.     var valid_email: String { get }
  7. }
  8.  
  9. struct German: Translations {
  10.     var valid_email: String = "Bitte geben Sie eine gültige e-mail Adresse ein"
  11. }
  12.  
  13. struct English: Translations {
  14.     var valid_email: String = ""
  15. }
  16.  
  17. extension Locale {
  18.     static func isGerman() -> Bool {
  19.         return Locale.preferredLanguages[0].range(of:"de") != nil
  20.     }
  21.  
  22.     static func language() -> Translations {
  23.         if isGerman() {
  24.             return German()
  25.         }
  26.         return English()
  27.     }
  28. }
  29.  
  30. let errorLabel = UILabel()
  31. errorLabel.text = Locale.language().valid_email
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement