ui language can now be chosen in the preferences

This commit is contained in:
Gonk
2019-10-28 23:59:29 +01:00
parent 495b48cbf8
commit da7dbdcf69
5 changed files with 60 additions and 10 deletions

View File

@@ -121,6 +121,33 @@
<item>2.0f</item>
</string-array>
<string-array name="preferences_language">
<item>@string/preferences_language_default</item>
<item>English</item>
<item>Deutsch (98%)</item>
<item>Español (98%)</item>
<item>Française (60%)</item>
<item>Italiano (98%)</item>
<item>Magyar (45%)</item>
<item>Polski (98%)</item>
<item>Português (85%)</item>
<item>Português Brasil (85%)</item>
<item>Русский язык (98%)</item>
</string-array>
<string-array name="preferences_language_values">
<item>default</item>
<item>en</item>
<item>de</item>
<item>es</item>
<item>fr</item>
<item>it</item>
<item>hu</item>
<item>pl</item>
<item>pt</item>
<item>pt-BR</item>
<item>ru</item>
</string-array>
<string-array name="preferences_movement_dpad_positions">
<item>@string/preferences_movement_dpad_positions_disabled</item>
<item>@string/preferences_movement_dpad_positions_lower_right</item>

View File

@@ -345,6 +345,10 @@
<string name="preferences_display_scaling_factor_50_percent_larger">1.5x size</string>
<string name="preferences_display_scaling_factor_double">Double size</string>
<string name="preferences_language_default">System language</string>
<string name="preferences_language">Language</string>
<string name="preferences_language_description">Select the language. English is used if the system language is not available or content has not ben translated. (Requires restart)</string>
<string name="inventory_assign">Assign quick slot</string>
<string name="inventory_selectitem">Select item to assign</string>
<string name="inventory_assign_slot1">Slot 1</string>

View File

@@ -110,10 +110,12 @@
android:defaultValue="false"
android:summary="@string/preferences_ui_show_quickslots_when_toolbox_is_visible"
android:key="showQuickslotsWhenToolboxIsVisible" />
<CheckBoxPreference
android:title="@string/preferences_ui_use_localized_resources_title"
android:defaultValue="true"
android:summary="@string/preferences_ui_use_localized_resources"
android:key="useLocalizedResources" />
<com.gpl.rpg.AndorsTrail.view.CustomListPreference
android:title="@string/preferences_language"
android:summary="@string/preferences_language_description"
android:key="language"
android:defaultValue="default"
android:entries="@array/preferences_language"
android:entryValues="@array/preferences_language_values" />
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -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<String, Locale> 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<String, Locale>(preferences.language, targetLocale);
}
if (targetLocale.equals(conf.locale)) {
return false;
}

View File

@@ -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;
}
}