From da7dbdcf6911ff38fdef23784687fdaa41722cc0 Mon Sep 17 00:00:00 2001 From: Gonk Date: Mon, 28 Oct 2019 23:59:29 +0100 Subject: [PATCH] ui language can now be chosen in the preferences --- AndorsTrail/res/values/arrays.xml | 27 +++++++++++++++++++ AndorsTrail/res/values/strings.xml | 4 +++ AndorsTrail/res/xml/preferences.xml | 12 +++++---- .../AndorsTrail/AndorsTrailApplication.java | 20 ++++++++++++-- .../AndorsTrail/AndorsTrailPreferences.java | 7 ++--- 5 files changed, 60 insertions(+), 10 deletions(-) diff --git a/AndorsTrail/res/values/arrays.xml b/AndorsTrail/res/values/arrays.xml index e7c3ec4eb..7de0256aa 100644 --- a/AndorsTrail/res/values/arrays.xml +++ b/AndorsTrail/res/values/arrays.xml @@ -121,6 +121,33 @@ 2.0f + + @string/preferences_language_default + English + Deutsch (98%) + Español (98%) + Française (60%) + Italiano (98%) + Magyar (45%) + Polski (98%) + Português (85%) + Português Brasil (85%) + Русский язык (98%) + + + default + en + de + es + fr + it + hu + pl + pt + pt-BR + ru + + @string/preferences_movement_dpad_positions_disabled @string/preferences_movement_dpad_positions_lower_right diff --git a/AndorsTrail/res/values/strings.xml b/AndorsTrail/res/values/strings.xml index 31f55ce7e..45102f7a5 100644 --- a/AndorsTrail/res/values/strings.xml +++ b/AndorsTrail/res/values/strings.xml @@ -345,6 +345,10 @@ 1.5x size Double size + System language + Language + Select the language. English is used if the system language is not available or content has not ben translated. (Requires restart) + Assign quick slot Select item to assign Slot 1 diff --git a/AndorsTrail/res/xml/preferences.xml b/AndorsTrail/res/xml/preferences.xml index aaa992698..1fbd6b217 100644 --- a/AndorsTrail/res/xml/preferences.xml +++ b/AndorsTrail/res/xml/preferences.xml @@ -110,10 +110,12 @@ android:defaultValue="false" android:summary="@string/preferences_ui_show_quickslots_when_toolbox_is_visible" android:key="showQuickslotsWhenToolboxIsVisible" /> - + diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailApplication.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailApplication.java index b6033af28..a2312870f 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailApplication.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailApplication.java @@ -7,6 +7,7 @@ import java.util.Locale; import com.gpl.rpg.AndorsTrail.context.ControllerContext; import com.gpl.rpg.AndorsTrail.context.WorldContext; import com.gpl.rpg.AndorsTrail.controller.Constants; +import com.gpl.rpg.AndorsTrail.util.Pair; import android.annotation.SuppressLint; import android.app.Activity; @@ -66,12 +67,27 @@ public final class AndorsTrailApplication extends Application { //Get default locale at startup, as somehow it seems that changing the app's //configured locale impacts the value returned by Locale.getDefault() nowadays. private final Locale defaultLocale = Locale.getDefault(); - + + private Pair lastLocale = null; + @SuppressLint("NewApi") public boolean setLocale(Activity context) { Resources res = context.getResources(); Configuration conf = res.getConfiguration(); - final Locale targetLocale = preferences.useLocalizedResources ? defaultLocale : Locale.US; + + Locale targetLocale; + + if (lastLocale != null && lastLocale.first == preferences.language) { + targetLocale = lastLocale.second; + } else { + if (preferences.language.equalsIgnoreCase("default")) { + targetLocale = defaultLocale; + } else { + targetLocale = Locale.forLanguageTag(preferences.language); + } + lastLocale = new Pair(preferences.language, targetLocale); + } + if (targetLocale.equals(conf.locale)) { return false; } diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailPreferences.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailPreferences.java index e9af916a5..841a6167b 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailPreferences.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailPreferences.java @@ -55,7 +55,8 @@ public final class AndorsTrailPreferences { public int displayOverwriteSavegame = CONFIRM_OVERWRITE_SAVEGAME_ALWAYS; public int quickslotsPosition = QUICKSLOTS_POSITION_HORIZONTAL_CENTER_BOTTOM; public boolean showQuickslotsWhenToolboxIsVisible = false; - public boolean useLocalizedResources = true; + public String language = "default"; + public int selectedTheme = 0; public void read(final Context androidContext) { @@ -77,7 +78,7 @@ public final class AndorsTrailPreferences { dest.displayOverwriteSavegame = Integer.parseInt(prefs.getString("display_overwrite_savegame", Integer.toString(CONFIRM_OVERWRITE_SAVEGAME_ALWAYS))); dest.quickslotsPosition = Integer.parseInt(prefs.getString("quickslots_placement", Integer.toString(QUICKSLOTS_POSITION_HORIZONTAL_CENTER_BOTTOM))); dest.showQuickslotsWhenToolboxIsVisible = prefs.getBoolean("showQuickslotsWhenToolboxIsVisible", false); - dest.useLocalizedResources = prefs.getBoolean("useLocalizedResources", true); + dest.language = prefs.getString("language", "default"); dest.selectedTheme = Integer.parseInt(prefs.getString("selectedTheme", Integer.toString(0))); // This might be implemented as a skill in the future. //dest.movementAggressiveness = Integer.parseInt(prefs.getString("movementaggressiveness", Integer.toString(MOVEMENTAGGRESSIVENESS_NORMAL))); @@ -98,7 +99,7 @@ public final class AndorsTrailPreferences { dest.displayOverwriteSavegame = CONFIRM_OVERWRITE_SAVEGAME_ALWAYS; dest.quickslotsPosition = QUICKSLOTS_POSITION_HORIZONTAL_CENTER_BOTTOM; dest.showQuickslotsWhenToolboxIsVisible = false; - dest.useLocalizedResources = true; + dest.language = "default"; dest.selectedTheme = 0; } }