diff --git a/vector/src/main/java/im/vector/riotx/features/settings/VectorLocale.kt b/vector/src/main/java/im/vector/riotx/features/settings/VectorLocale.kt
index a4ccfdba47..75ddbadd2e 100644
--- a/vector/src/main/java/im/vector/riotx/features/settings/VectorLocale.kt
+++ b/vector/src/main/java/im/vector/riotx/features/settings/VectorLocale.kt
@@ -21,10 +21,12 @@ import android.content.res.Configuration
import android.os.Build
import androidx.core.content.edit
import androidx.preference.PreferenceManager
+import im.vector.riotx.BuildConfig
import im.vector.riotx.R
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import timber.log.Timber
+import java.util.IllformedLocaleException
import java.util.Locale
/**
@@ -38,6 +40,8 @@ object VectorLocale {
private val defaultLocale = Locale("en", "US")
+ private const val ISO_15924_LATN = "Latn"
+
/**
* The cache of supported application languages
*/
@@ -189,13 +193,21 @@ object VectorLocale {
)
}
- val list = knownLocalesSet.map { (language, country, script) ->
+ val list = knownLocalesSet.mapNotNull { (language, country, script) ->
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- Locale.Builder()
- .setLanguage(language)
- .setRegion(country)
- .setScript(script)
- .build()
+ try {
+ Locale.Builder()
+ .setLanguage(language)
+ .setRegion(country)
+ .setScript(script)
+ .build()
+ } catch (exception: IllformedLocaleException) {
+ if (BuildConfig.DEBUG) {
+ throw exception
+ }
+ // Ignore this locale in production
+ null
+ }
} else {
Locale(language, country)
}
@@ -218,7 +230,7 @@ object VectorLocale {
append(locale.getDisplayLanguage(locale))
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
- && locale.script != "Latn"
+ && locale.script != ISO_15924_LATN
&& locale.getDisplayScript(locale).isNotEmpty()) {
append(" - ")
append(locale.getDisplayScript(locale))
@@ -242,7 +254,7 @@ object VectorLocale {
return buildString {
append("[")
append(locale.displayLanguage)
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && locale.script != "Latn") {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && locale.script != ISO_15924_LATN) {
append(" - ")
append(locale.displayScript)
}
diff --git a/vector/src/main/res/values/strings.xml b/vector/src/main/res/values/strings.xml
index 36532f25e3..35a49cee4a 100644
--- a/vector/src/main/res/values/strings.xml
+++ b/vector/src/main/res/values/strings.xml
@@ -5,7 +5,7 @@
en
US
-
+
Latn