Fix pre 21 support

This commit is contained in:
topjohnwu
2021-02-20 03:38:39 -08:00
parent 9cc91b30b3
commit ccb55205e6
6 changed files with 13 additions and 11 deletions

View File

@@ -38,7 +38,7 @@ withContext(Dispatchers.Default) {
add("pt-BR")
// Then add all supported locales
addAll(res.assets.locales)
addAll(Resources.getSystem().assets.locales)
}.map {
it.langTagToLocale()
}.distinctBy {

View File

@@ -51,7 +51,7 @@ fun String.langTagToLocale(): Locale {
if (Build.VERSION.SDK_INT >= 21) {
return Locale.forLanguageTag(this)
} else {
val tok = split("-".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
val tok = split("[-_]".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
if (tok.isEmpty()) {
return Locale("")
}