Add optional language filter on Universe feed

This commit is contained in:
2023-03-25 23:47:23 -06:00
parent 0b40cd127c
commit f75fc7eebe
6 changed files with 66 additions and 23 deletions

View File

@@ -21,3 +21,14 @@ func localizedStringFormat(key: String, locale: Locale?) -> String {
let fallback = bundleForLocale(locale: Locale(identifier: "en-US")).localizedString(forKey: key, value: nil, table: nil)
return bundle.localizedString(forKey: key, value: fallback, table: nil)
}
/**
Removes the variant part of a locale code so that it contains only the language code.
*/
func localeToLanguage(_ locale: String) -> String? {
if #available(iOS 16, *) {
return Locale.LanguageCode(stringLiteral: locale).identifier(.alpha2)
} else {
return NSLocale(localeIdentifier: locale).languageCode
}
}