Skip to content

Commit

Permalink
Merge branch 'hotfix/crash_locales'
Browse files Browse the repository at this point in the history
  • Loading branch information
bmarty committed May 28, 2020
2 parents d1c4d4b + ec1422b commit 997101a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

/**
Expand All @@ -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
*/
Expand Down Expand Up @@ -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)
}
Expand All @@ -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))
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion vector/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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 -->
Expand Down

0 comments on commit 997101a

Please sign in to comment.