mirror of
https://github.com/SchildiChat/SchildiChat-android.git
synced 2024-11-25 19:05:56 +03:00
Merge branch 'hotfix/crash_locales' into develop
This commit is contained in:
commit
7be3434136
2 changed files with 21 additions and 9 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
<string name="resources_language">en</string>
|
||||
<string name="resources_country_code">US</string>
|
||||
<!-- NOTE TO TRANSLATORS: ONLY POSSIBLE VALUES: Latn OR Cyrl -->
|
||||
<!-- NOTE TO TRANSLATORS: Value MUST have 4 letters and MUST be in this list: https://www.unicode.org/iso15924/iso15924-codes.html. Example: "Arab", "Cyrl", "Latn", etc. -->
|
||||
<string name="resources_script">Latn</string>
|
||||
|
||||
<!-- theme -->
|
||||
|
|
Loading…
Reference in a new issue