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
|
private func tableForLocale(_ locale: Locale) -> RelativeFormatterLanguage { |
|
let localeId = (locale.collatorIdentifier ?? Locales.english.toLocale().collatorIdentifier!) |
|
|
|
if let lang = RelativeFormatterLanguage(rawValue: localeId) { |
|
return lang |
|
} |
|
|
|
guard let fallbackFlavours = RelativeFormatterLanguage(rawValue: localeId.components(separatedBy: "_").first!) ?? |
|
RelativeFormatterLanguage(rawValue: localeId.components(separatedBy: "-").first!) else { |
|
return tableForLocale(Locales.english.toLocale()) // fallback not found, return english |
|
} |
|
return fallbackFlavours // return fallback |
|
} |
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
}
ex. Locale (zh-Hant)
let localeId = (locale.collatorIdentifier ?? Locales.english.toLocale().collatorIdentifier!) // zh-Hantcase in RelativeFormatterLanguage is "zh_Hant"
This case makes it impossible to map the correct
RelativeFormatterLanguage, and it map to the casezhSwiftDate/Sources/SwiftDate/Formatters/RelativeFormatter/RelativeFormatter.swift
Lines 32 to 44 in 89774a1
I think the solution
or write RelativeFormatterLanguage
init:rawValue