app language: refactoring
renamed NewPipe's language into App language, and same for all the concerning thing (keys, comments…) we now call assureCorrectAppLanguage(CONTEXT) in activities needing it instead of changeAppLanguage(getAppLocale(CONTEXT), RESOURCES) changeAppLanguage becomes private.
This commit is contained in:
parent
156a2eb4ff
commit
edc9d47da7
14 changed files with 43 additions and 52 deletions
|
|
@ -218,7 +218,7 @@ public class Localization {
|
|||
return getPrettyTime().formatUnrounded(calendarTime);
|
||||
}
|
||||
|
||||
public static void changeAppLanguage(Locale loc, Resources res) {
|
||||
private static void changeAppLanguage(Locale loc, Resources res) {
|
||||
DisplayMetrics dm = res.getDisplayMetrics();
|
||||
Configuration conf = res.getConfiguration();
|
||||
conf.setLocale(loc);
|
||||
|
|
@ -227,11 +227,13 @@ public class Localization {
|
|||
|
||||
public static Locale getAppLocale(Context context) {
|
||||
SharedPreferences prefs = androidx.preference.PreferenceManager.getDefaultSharedPreferences(context);
|
||||
String lang = prefs.getString("newpipes_language_key", "en");
|
||||
String lang = prefs.getString("app_language_key", "en");
|
||||
Locale loc;
|
||||
if (lang.equals("system")) {
|
||||
loc = Locale.getDefault();
|
||||
} else if (lang.matches(".*-.*")) {
|
||||
//to differentiate different versions of the language
|
||||
//for example, pt (portuguese in Portugal) and pt-br (portuguese in Brazil)
|
||||
String[] localisation = lang.split("-");
|
||||
lang = localisation[0];
|
||||
String country = localisation[1];
|
||||
|
|
@ -241,4 +243,8 @@ public class Localization {
|
|||
}
|
||||
return loc;
|
||||
}
|
||||
|
||||
public static void assureCorrectAppLanguage(Context c) {
|
||||
changeAppLanguage(getAppLocale(c), c.getResources());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue