diff --git a/android/app/src/main/java/com/cleverraven/cataclysmdda/CataclysmDDA.java b/android/app/src/main/java/com/cleverraven/cataclysmdda/CataclysmDDA.java index 7be201bf01560..762d0257cab86 100755 --- a/android/app/src/main/java/com/cleverraven/cataclysmdda/CataclysmDDA.java +++ b/android/app/src/main/java/com/cleverraven/cataclysmdda/CataclysmDDA.java @@ -59,15 +59,6 @@ public boolean getDefaultSetting(final String settingsName, boolean defaultValue } public String getSystemLang() { - String language = getResources().getConfiguration().locale.toString(); - // remove suffix we are not interested in if it exists, eg. "en_US_WIN" -> "en_US" - int first_underscore = language.indexOf("_"); - if(first_underscore != -1) { - int second_underscore = language.indexOf("_", first_underscore + 1); - if(second_underscore != -1) { - language = language.substring(0, second_underscore); - } - } - return language; + return getResources().getConfiguration().locale.toLanguageTag().replace('-', '_'); } } diff --git a/src/translations.cpp b/src/translations.cpp index 30e477c2d1a5b..2649d09dc54bc 100644 --- a/src/translations.cpp +++ b/src/translations.cpp @@ -219,9 +219,6 @@ void set_language() #elif defined(__ANDROID__) system_lang = getAndroidSystemLang(); #endif - if( !isValidLanguage( system_lang ) ) { - system_lang = std::string(); - } // Step 1. Setup locale settings. std::string lang_opt = get_option( "USE_LANG" ).empty() ? system_lang : get_option( "USE_LANG" ); @@ -346,11 +343,20 @@ std::string getAndroidSystemLang() // fail-safe if retrieving Java string failed return std::string(); } - std::string lang( ans_c_str ); + const std::string lang( ans_c_str ); env->ReleaseStringUTFChars( ans, ans_c_str ); env->DeleteLocalRef( activity ); env->DeleteLocalRef( clazz ); - return lang; + DebugLog( D_INFO, D_MAIN ) << "Read Android system language: '" << lang << '\''; + const std::vector available_languages = + get_options().get_option( "USE_LANG" ).getItems(); + for( const options_manager::id_and_option &available_language : available_languages ) { + if( string_starts_with( lang, available_language.first ) ) { + return available_language.first; + } + } + DebugLog( D_WARNING, D_MAIN ) << "Unrecognised language: '" << lang << "', fallback to English"; + return std::string(); } #endif