From d890bf28fa4db160ce0768a958b4a00cf485be36 Mon Sep 17 00:00:00 2001 From: Markus Fisch Date: Thu, 8 Apr 2021 20:47:31 +0200 Subject: [PATCH] Fix creating Locale from resource format Locale() requires the country part as secondary argument and can't use the resource format "lang-country" directly. --- .../kotlin/de/markusfisch/android/binaryeye/app/Locale.kt | 7 ++++++- app/src/main/res/values/locales.xml | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/kotlin/de/markusfisch/android/binaryeye/app/Locale.kt b/app/src/main/kotlin/de/markusfisch/android/binaryeye/app/Locale.kt index 2d59374f..adf5ff10 100644 --- a/app/src/main/kotlin/de/markusfisch/android/binaryeye/app/Locale.kt +++ b/app/src/main/kotlin/de/markusfisch/android/binaryeye/app/Locale.kt @@ -6,7 +6,12 @@ import java.util.* fun Context.applyLocale(localeName: String) { if (localeName.isNotEmpty()) { - val locale = Locale(localeName) + val localeParts = localeName.split("-") + val locale = if (localeParts.size == 2) { + Locale(localeParts[0], localeParts[1]) + } else { + Locale(localeName) + } Locale.setDefault(locale) val conf = resources.configuration if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { diff --git a/app/src/main/res/values/locales.xml b/app/src/main/res/values/locales.xml index 3437c386..a7d8bd7a 100644 --- a/app/src/main/res/values/locales.xml +++ b/app/src/main/res/values/locales.xml @@ -16,7 +16,7 @@ Turkish Ukrainian Chinese - Chinese (Simplified Han,China) + Chinese (Simplified Han, China) Japanese Czech