separate index locale preference handling on >= android-24

In android-24 and newer, the user can specify multiple languages in a
priority list. Therefore, the locale chooser logic here does not need
to work so hard to find a language match.  For example, if the user
wanted to see country-specific variants, they would add them to the
preference list.

With older versions of Android, the pref is only a single locale. So
chances are that someone who specified de_AT would rather see de or
de_DE than en_US.  Same goes for es_AR, ar_EG, etc.  This could annoy
Chinese speakers, since someone who sets zh_TW could potentially see
zh_CN, which are written pretty differently.
This commit is contained in:
Hans-Christoph Steiner 2017-04-27 23:02:34 +02:00
parent dc57fd712b
commit 03168ff99e

View File

@ -386,18 +386,27 @@ public class App extends ValueObject implements Comparable<App>, Parcelable {
Set<String> locales = localized.keySet();
Set<String> localesToUse = new LinkedHashSet<>();
if (Build.VERSION.SDK_INT >= 24) {
LocaleList localeList = Resources.getSystem().getConfiguration().getLocales();
for (String toUse : localeList.toLanguageTags().split(",")) {
localesToUse.add(toUse);
for (String l : locales) {
if (l.equals(toUse.split("-")[0])) {
localesToUse.add(l);
break;
}
}
}
} else {
if (locales.contains(localeTag)) {
localesToUse.add(localeTag);
}
if (Build.VERSION.SDK_INT >= 24) {
LocaleList localeList = Resources.getSystem().getConfiguration().getLocales();
localesToUse.addAll(Arrays.asList(localeList.toLanguageTags().split(",")));
if (locales.contains(languageTag)) {
localesToUse.add(languageTag);
}
for (String toUse : localesToUse) {
for (String l : locales) {
if (l.startsWith(toUse.split("-")[0])) {
if (l.startsWith(languageTag)) {
localesToUse.add(l);
break;
}
}
}