diff --git a/src/main/java/menion/android/whereyougo/gui/activity/XmlSettingsActivity.java b/src/main/java/menion/android/whereyougo/gui/activity/XmlSettingsActivity.java index 8289bbe9..a42da894 100644 --- a/src/main/java/menion/android/whereyougo/gui/activity/XmlSettingsActivity.java +++ b/src/main/java/menion/android/whereyougo/gui/activity/XmlSettingsActivity.java @@ -16,13 +16,12 @@ import androidx.preference.PreferenceManager; import menion.android.whereyougo.R; +import menion.android.whereyougo.gui.extension.activity.CustomActivity; import menion.android.whereyougo.preferences.PreferenceValues; import menion.android.whereyougo.preferences.Preferences; import menion.android.whereyougo.utils.Logger; import menion.android.whereyougo.utils.Utils; -import static menion.android.whereyougo.gui.extension.activity.CustomActivity.setLocale; - public class XmlSettingsActivity extends AppCompatActivity @@ -38,7 +37,11 @@ public void onCreate(Bundle savedInstanceState) { // Set language SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); String lang = sharedPreferences.getString(getString(R.string.pref_KEY_S_LANGUAGE), ""); - setLocale(this, lang); + CustomActivity.setLocale(this, lang); + + setContentView(R.layout.layout_settings); + setTitle(R.string.settings); + ((TextView) findViewById(R.id.title_text)).setText(R.string.settings); setContentView(R.layout.layout_settings); setTitle(R.string.settings); diff --git a/src/main/java/menion/android/whereyougo/gui/extension/activity/CustomActivity.java b/src/main/java/menion/android/whereyougo/gui/extension/activity/CustomActivity.java index bd99ca2d..a4e49be4 100644 --- a/src/main/java/menion/android/whereyougo/gui/extension/activity/CustomActivity.java +++ b/src/main/java/menion/android/whereyougo/gui/extension/activity/CustomActivity.java @@ -253,14 +253,34 @@ private void unbindDrawables(View view) { } public static void setLocale(Activity activity, String languageCode) { - String lang = languageCode; + Locale locale; + String lang; + Resources resources = activity.getResources(); + Configuration config = resources.getConfiguration(); + + // we need to get language and region first even for default to correctly initialize Locale if (languageCode.equals("default")) { - lang = Locale.getDefault().getLanguage(); + lang = Locale.getDefault().toString(); + } else { + lang = new Locale(languageCode).toString(); + } + + // need to parse language codes with dash and hyphen + String[] loc = lang.split("[-_]"); + if (loc.length == 1) { + if (loc[0].equals("pt")) { + // nasty hotfix for Portuguese language selected without regional code + locale = new Locale(loc[0], loc[0]); + } else { + locale = new Locale(lang); + } + } else if (loc.length == 2) { + locale = new Locale(loc[0], loc[1]); + } else { + locale = config.locale; } - Locale locale = new Locale(lang); + Locale.setDefault(locale); - Resources resources = activity.getResources(); - Configuration config = resources.getConfiguration(); config.setLocale(locale); resources.updateConfiguration(config, resources.getDisplayMetrics()); config.locale = locale;