SwiftDate
SwiftDate copied to clipboard
toRelative can't correctly map language.
ex. Locale (zh-Hant)
let localeId = (locale.collatorIdentifier ?? Locales.english.toLocale().collatorIdentifier!) // zh-Hant
case in RelativeFormatterLanguage is "zh_Hant"
This case makes it impossible to map the correct RelativeFormatterLanguage
, and it map to the case zh
https://github.com/malcommac/SwiftDate/blob/89774a1e28826af1498693bcbdf9ff6037ec646f/Sources/SwiftDate/Formatters/RelativeFormatter/RelativeFormatter.swift#L32-L44
I think the solution
let localeId = (locale.collatorIdentifier ?? Locales.english.toLocale().collatorIdentifier!).replacingOccurrences(of: "-", with: "_")
or write RelativeFormatterLanguage init:rawValue
public init?(rawValue: String) {
let rawValue = rawValue.replacingOccurrences(of: "-", with: "_")
self = RelativeFormatter.allLanguages.first(where: { $0.rawValue == rawValue }) ?? .en
if rawValue == "bs_Cyrl" {
self = .bs_Cyrl
}
Fixed in #778 Create a locale id fallback rule to support different locale format as we can as possible: collatorIdentifier: zh-Hant-TW -> zh_Hant_TW -> zh-Hant -> zh_Hant -> zh -> en