clear language setting if it matches the system-wide setting

If the user can set the language using the Setting app, then there is
not reason to use the Languages hack.  This then clears the preference
if it matches the language of the system-wide locale.  This also
removes the current system-wide language from the Languages menu.

closes #943
This commit is contained in:
Hans-Christoph Steiner 2017-05-10 20:43:11 +02:00
parent 6456f56ced
commit 1b390cceca

View File

@ -73,6 +73,9 @@ public final class Languages {
}
}
// remove the current system language from the menu
tmpMap.remove(currentLocale.getLanguage());
/* SYSTEM_DEFAULT is a fake one for displaying in a chooser menu. */
tmpMap.put(USE_SYSTEM_DEFAULT, activity.getString(resId));
nameMap = Collections.unmodifiableMap(tmpMap);
@ -116,13 +119,21 @@ public final class Languages {
}
@TargetApi(17)
/**
* Handles setting the language if it is different than the current language,
* or different than the current system-wide locale. The preference is cleared
* if the language matches the system-wide locale or "System Default" is chosen.
*/
public static void setLanguage(final ContextWrapper contextWrapper, String language, boolean refresh) {
if (Build.VERSION.SDK_INT >= 24) {
Utils.debugLog(TAG, "Languages.setLanguage() ignored on >= android-24");
Preferences.get().clearLanguage();
return;
}
if (locale != null && TextUtils.equals(locale.getLanguage(), language) && (!refresh)) {
if (TextUtils.equals(language, DEFAULT_LOCALE.getLanguage())) {
Preferences.get().clearLanguage();
locale = DEFAULT_LOCALE;
} else if (locale != null && TextUtils.equals(locale.getLanguage(), language) && (!refresh)) {
return; // already configured
} else if (language == null || language.equals(USE_SYSTEM_DEFAULT)) {
Preferences.get().clearLanguage();