clean up language tags parser

This commit is contained in:
andrekir
2022-12-12 21:51:15 -03:00
parent c9ac6860db
commit 08ec7dfef1

View File

@@ -51,16 +51,15 @@ object LanguageUtils : Logging {
} catch (e: Exception) {
errormsg("Error parsing locale_config.xml ${e.message}")
}
fun getDisplayLanguage(tag: String): String {
return languageTags.map { tag ->
val loc = Locale(tag)
return when (tag) {
when (tag) {
SYSTEM_DEFAULT -> context.getString(R.string.preferences_system_default)
"fr-HT" -> context.getString(R.string.fr_HT)
"pt-BR" -> context.getString(R.string.pt_BR)
else -> loc.getDisplayLanguage(loc)
.replaceFirstChar { if (it.isLowerCase()) it.titlecase(loc) else it.toString() }
}
} to tag
}
return languageTags.map { getDisplayLanguage(it) to it }
}
}