appLanguageExceptions

This commit is contained in:
thomas.JY.Lin@gmail.com 2022-11-13 07:51:00 +08:00
parent 3fc63a2165
commit 9ccf951b8c

View file

@ -107,10 +107,19 @@ object CommonActivity {
logError(e)
}
}
/**
* Not all languages can be fetched from locale with a code.
* This map allows sidestepping the default Locale(languageCode)
* when setting the app language.
**/
val appLanguageExceptions = hashMapOf(
"zh-TW" to Locale.TRADITIONAL_CHINESE
)
fun setLocale(context: Context?, languageCode: String?) {
if (context == null || languageCode == null) return
val locale = Locale(languageCode)
val locale = appLanguageExceptions[languageCode] ?: Locale(languageCode)
val resources: Resources = context.resources
val config = resources.configuration
Locale.setDefault(locale)
@ -421,4 +430,4 @@ object CommonActivity {
}
return null
}
}
}