diff --git a/sudoq-app/sudoqapp/src/main/kotlin/de/sudoq/controller/menus/MainActivity.kt b/sudoq-app/sudoqapp/src/main/kotlin/de/sudoq/controller/menus/MainActivity.kt index 7c37f795..45a2c213 100644 --- a/sudoq-app/sudoqapp/src/main/kotlin/de/sudoq/controller/menus/MainActivity.kt +++ b/sudoq-app/sudoqapp/src/main/kotlin/de/sudoq/controller/menus/MainActivity.kt @@ -101,6 +101,8 @@ class MainActivity : SudoqCompatActivity() { //load language from memory val fromConf = getConfLocale(this) if (fromConf != currentLanguageCode!!.language) { + //language has been changed so we need to restart this activity + //so that the new language is applied to it Log.d("lang", "refresh because $currentLanguageCode -> $fromConf") val refresh = Intent(this, this.javaClass) finish() diff --git a/sudoq-app/sudoqapp/src/main/kotlin/de/sudoq/controller/menus/preferences/LanguageSetting.kt b/sudoq-app/sudoqapp/src/main/kotlin/de/sudoq/controller/menus/preferences/LanguageSetting.kt index 396013d0..f7ad1d16 100644 --- a/sudoq-app/sudoqapp/src/main/kotlin/de/sudoq/controller/menus/preferences/LanguageSetting.kt +++ b/sudoq-app/sudoqapp/src/main/kotlin/de/sudoq/controller/menus/preferences/LanguageSetting.kt @@ -10,8 +10,20 @@ class LanguageSetting { } //may never be system! - @JvmField var language: LanguageCode + get() { + if (language == LanguageCode.system) + throw java.lang.IllegalStateException("LanguageSetting.language is 'system'. This is not allowed") + else + return language + } + set(value) { + if (value == LanguageCode.system) + throw java.lang.IllegalArgumentException("LanguageSetting.language may not be set to 'system'.") + + language = value + } + var isSystemLanguage: Boolean private set diff --git a/sudoq-app/sudoqapp/src/main/kotlin/de/sudoq/controller/menus/preferences/LanguageUtility.kt b/sudoq-app/sudoqapp/src/main/kotlin/de/sudoq/controller/menus/preferences/LanguageUtility.kt index 903bb6af..aebdf8fb 100644 --- a/sudoq-app/sudoqapp/src/main/kotlin/de/sudoq/controller/menus/preferences/LanguageUtility.kt +++ b/sudoq-app/sudoqapp/src/main/kotlin/de/sudoq/controller/menus/preferences/LanguageUtility.kt @@ -45,19 +45,31 @@ object LanguageUtility { /* save language to enum */ @JvmStatic fun loadLanguageFromLocale(): LanguageCode { - val code = Locale.getDefault().language + val code = Locale.getDefault().language //TODO won't this always return en? LanguageCode.values().forEach { if (it.name == code) return it} return LanguageCode.en } + //can be 'system' @JvmStatic fun getConfLocale(a: Activity): LanguageCode { val res = a.resources val conf = res.configuration val code = conf.locale.language - return LanguageCode.valueOf(code) + + val unmaintainedLang = !LanguageCode.values() + .map { it.name } + .contains(code) + + return if (unmaintainedLang) { + Log.e("lang","Inexplicably, the language loaded from conf is $code, defaulting to 'system'") + LanguageCode.system + } else{ + LanguageCode.valueOf(code) + } } + //can be 'system' @JvmStatic fun setConfLocale(lang: String, a: Activity) { Log.i("lang", "setLocale( " + lang + ", " + a.javaClass.simpleName + ")")