diff --git a/app/src/main/java/org/schabi/newpipe/MainActivity.java b/app/src/main/java/org/schabi/newpipe/MainActivity.java index 90d299c7f..cac814085 100644 --- a/app/src/main/java/org/schabi/newpipe/MainActivity.java +++ b/app/src/main/java/org/schabi/newpipe/MainActivity.java @@ -67,6 +67,7 @@ import org.schabi.newpipe.fragments.list.search.SearchFragment; import org.schabi.newpipe.report.ErrorActivity; import org.schabi.newpipe.util.Constants; import org.schabi.newpipe.util.KioskTranslator; +import org.schabi.newpipe.util.Localization; import org.schabi.newpipe.util.NavigationHelper; import org.schabi.newpipe.util.PeertubeHelper; import org.schabi.newpipe.util.PermissionHelper; @@ -78,6 +79,8 @@ import org.schabi.newpipe.util.ThemeHelper; import java.util.ArrayList; import java.util.List; +import static org.schabi.newpipe.util.Localization.changeAppLanguage; + public class MainActivity extends AppCompatActivity { private static final String TAG = "MainActivity"; public static final boolean DEBUG = !BuildConfig.BUILD_TYPE.equals("release"); @@ -116,6 +119,8 @@ public class MainActivity extends AppCompatActivity { ThemeHelper.setTheme(this, ServiceHelper.getSelectedServiceId(this)); + changeAppLanguage(Localization.getPreferredLocale(getApplicationContext()), getResources()); + super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); diff --git a/app/src/main/java/org/schabi/newpipe/util/Localization.java b/app/src/main/java/org/schabi/newpipe/util/Localization.java index 9274df848..6b0b4cd0c 100644 --- a/app/src/main/java/org/schabi/newpipe/util/Localization.java +++ b/app/src/main/java/org/schabi/newpipe/util/Localization.java @@ -2,8 +2,11 @@ package org.schabi.newpipe.util; import android.content.Context; import android.content.SharedPreferences; +import android.content.res.Configuration; +import android.content.res.Resources; import android.preference.PreferenceManager; import android.text.TextUtils; +import android.util.DisplayMetrics; import org.ocpsoft.prettytime.PrettyTime; import org.ocpsoft.prettytime.units.Decade; @@ -216,4 +219,11 @@ public class Localization { public static String relativeTime(Calendar calendarTime) { return getPrettyTime().formatUnrounded(calendarTime); } + + public static void changeAppLanguage(Locale loc, Resources res) { + DisplayMetrics dm = res.getDisplayMetrics(); + Configuration conf = res.getConfiguration(); + conf.setLocale(loc); + res.updateConfiguration(conf, dm); + } } diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 6aaaa0630..3f361226d 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -272,6 +272,7 @@ cs da de + eo et en-GB en @@ -351,6 +352,7 @@ Čeština Dansk Deutsch + Esperanto Eesti English (UK) English (US)