本地化布尔值的一些好方法是什么



对于String,我们可以通过以下方式进行本地化。

Localizable.strings
-------------------
"created_time" = "Created time";
Source code
-----------
extension String: Localizable {
public var localized: String {
return NSLocalizedString(self, comment: "")
}
}
let localizedString = "created_time".localize

但是,布尔值呢?例如,对于说中文的用户,我希望defaultValuetrue,但对于其他用户,则为false

static var isShowLunarCalendar: Bool {
set {
UserDefaults.standard.set(newValue, forKey: "SHOW_LUNAR_CALENDAR")
}
get {
// TODO: How to localize this boolean variable?
let defaultValue = false
UserDefaults.standard.bool(forKey: "SHOW_LUNAR_CALENDAR", defaultValue)
}
}

我可以知道,有什么好的方法来本地化布尔值吗?

你可以这样做

let res = Bool("BoolLocalize".localize)! // res is a true Bool in ch

ch.local

"BoolLocalize" = "true";

其他。本地

"BoolLocalize" = "false";

相关内容

最新更新