I hereby claim:
- I am damijanracel on github.
- I am maishu (https://keybase.io/maishu) on keybase.
- I have a public key ASCmxxCQDHnV-oY5wDvy6YI__vkzajzNbHQKrJaVbcFa_Ao
To claim this, I am signing this object:
I hereby claim:
To claim this, I am signing this object:
label.text = String(format: LocalizationKey.bye.string, name) |
label.text = LocalizationKey.progress(10, 1) |
enum LocalizationKey { | |
case hello | |
case bye(String) | |
case progress(Int, Int) | |
var string: String { | |
switch self { | |
case .hello: | |
return "hello".localized() | |
case .bye(let name): |
“hello”.localized() |
struct Localization { | |
let string: String | |
private init(string: String) { | |
self.string = string | |
} | |
static func bye(name: String) -> Localization { | |
return Localization(string: String(format: LocalizationKey.bye.string, name)) | |
} |
enum LocalizationKey: String { | |
case hello = "hello" | |
case bye = "bye" | |
case progress = "progress" | |
var string: String { | |
return rawValue.localized() | |
} | |
} |
func testLabel_Should_SetCorrectLocalizationKey() { | |
XCTAssertEqual(mainViewController!.label.localizationKey, LocalizationKey.bye) | |
} |
struct Localization { | |
let key: LocalizationKey | |
let string: String | |
private init(string: String, key: LocalizationKey) { | |
self.string = string | |
self.key = key | |
} | |
static func bye(name: String) -> Localization { |
class LocalizedLabel: UILabel { | |
var localizationKey: LocalizationKey? | |
func set(key localization: Localization) { | |
self.text = localization.string | |
self.localizationKey = localization.key | |
} | |
} |