mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2025-01-12 10:55:49 +01:00
allow to switch languages at runtime
This commit is contained in:
parent
9d3f3c57cd
commit
0fb664c141
@ -1,14 +1,33 @@
|
||||
package nodomain.freeyourgadget.gadgetbridge.activities;
|
||||
|
||||
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.util.Prefs;
|
||||
|
||||
|
||||
public class GBActivity extends AppCompatActivity {
|
||||
private void setLanguage(String language) {
|
||||
Locale locale;
|
||||
if (language.equals("default")) {
|
||||
locale = Locale.getDefault();
|
||||
} else {
|
||||
locale = new Locale(language);
|
||||
}
|
||||
Configuration config = new Configuration();
|
||||
config.locale = locale;
|
||||
|
||||
// FIXME: I have no idea what I am doing
|
||||
getApplicationContext().getResources().updateConfiguration(config, getApplicationContext().getResources().getDisplayMetrics());
|
||||
getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
if (GBApplication.isDarkThemeEnabled()) {
|
||||
@ -17,6 +36,9 @@ public class GBActivity extends AppCompatActivity {
|
||||
setTheme(R.style.GadgetbridgeTheme);
|
||||
}
|
||||
|
||||
Prefs prefs = GBApplication.getPrefs();
|
||||
String language = prefs.getString("language", "default");
|
||||
setLanguage(language);
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,36 @@
|
||||
<string name="pref_theme_value_light" translatable="false">light</string>
|
||||
<string name="pref_theme_value_dark" translatable="false">dark</string>
|
||||
|
||||
<string-array name="pref_language_options">
|
||||
<item name="default">System Default</item>
|
||||
<item name="de">Deutsch</item>
|
||||
<item name="en">English</item>
|
||||
<item name="es">Español</item>
|
||||
<item name="fr">Français</item>
|
||||
<item name="pl">Polski</item>
|
||||
<item name="ru">Русский</item>
|
||||
<item name="vi">Tiếng Việt</item>
|
||||
<item name="tr">Türkçe</item>
|
||||
<item name="uk">Українська</item>
|
||||
<item name="ko">한국어</item>
|
||||
<item name="ja">日本語</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_language_values">
|
||||
<item>default</item>
|
||||
<item>de</item>
|
||||
<item>en</item>
|
||||
<item>es</item>
|
||||
<item>fr</item>
|
||||
<item>pl</item>
|
||||
<item>ru</item>
|
||||
<item>vi</item>
|
||||
<item>tr</item>
|
||||
<item>uk</item>
|
||||
<item>ko</item>
|
||||
<item>ja</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="notification_mode">
|
||||
<item>@string/always</item>
|
||||
<item>@string/when_screen_off</item>
|
||||
|
@ -47,6 +47,8 @@
|
||||
<string name="pref_theme_light">Light</string>
|
||||
<string name="pref_theme_dark">Dark</string>
|
||||
|
||||
<string name="pref_title_language">Language</string>
|
||||
|
||||
<string name="pref_header_notifications">Notifications</string>
|
||||
<string name="pref_title_notifications_repetitions">Repetitions</string>
|
||||
<string name="pref_title_notifications_call">Phone Calls</string>
|
||||
|
@ -23,6 +23,13 @@
|
||||
android:entryValues="@array/pref_theme_values"
|
||||
android:defaultValue="@string/pref_theme_value_light"
|
||||
android:summary="%s" />
|
||||
<ListPreference
|
||||
android:key="language"
|
||||
android:title="@string/pref_title_language"
|
||||
android:entries="@array/pref_language_options"
|
||||
android:entryValues="@array/pref_language_values"
|
||||
android:defaultValue="default"
|
||||
android:summary="%s" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:key="pref_key_datetime"
|
||||
|
Loading…
x
Reference in New Issue
Block a user