From 1b2e7adc8821a6de2cfc2ce23b0c555c1bb7f1fa Mon Sep 17 00:00:00 2001 From: Mihai Nita Date: Fri, 8 Apr 2016 07:50:44 -0700 Subject: [PATCH] Use DisplayNameWithDialect only for some locales Although DisplayNameWithDialect seems to return friendlier, more "casual" names (e.g. "American English"), the result was inconsistent, and (at times) debatable. And since this setting affects not only the language of the translation, but a locale, names like "Flemish" kind of lost the whole "locale / location" idea. So we revert to use DisplayName for all but a few selected locales (that we verified are better with the "dialect" form). Bug: 27704583 Change-Id: I587081da1293cccac3cdabcd188a9b8160c233ea --- .../android/internal/app/LocaleHelper.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/core/java/com/android/internal/app/LocaleHelper.java b/core/java/com/android/internal/app/LocaleHelper.java index a9d51132cdcc7..7e9587adaf26a 100644 --- a/core/java/com/android/internal/app/LocaleHelper.java +++ b/core/java/com/android/internal/app/LocaleHelper.java @@ -90,6 +90,15 @@ public class LocaleHelper { return str.toUpperCase(); } + // For some locales we want to use a "dialect" form, for instance + // "Dari" instead of "Persian (Afghanistan)", or "Moldavian" instead of "Romanian (Moldova)" + private static boolean shouldUseDialectName(Locale locale) { + final String lang = locale.getLanguage(); + return "fa".equals(lang) // Persian + || "ro".equals(lang) // Romanian + || "zh".equals(lang); // Chinese + } + /** * Returns the locale localized for display in the provided locale. * @@ -99,8 +108,10 @@ public class LocaleHelper { * @return the localized name of the locale. */ public static String getDisplayName(Locale locale, Locale displayLocale, boolean sentenceCase) { - String result = ULocale.getDisplayNameWithDialect(locale.toLanguageTag(), - ULocale.forLocale(displayLocale)); + final ULocale displayULocale = ULocale.forLocale(displayLocale); + String result = shouldUseDialectName(locale) + ? ULocale.getDisplayNameWithDialect(locale.toLanguageTag(), displayULocale) + : ULocale.getDisplayName(locale.toLanguageTag(), displayULocale); return sentenceCase ? toSentenceCase(result, displayLocale) : result; } @@ -112,9 +123,7 @@ public class LocaleHelper { * @return the localized name of the locale. */ public static String getDisplayName(Locale locale, boolean sentenceCase) { - String result = ULocale.getDisplayNameWithDialect(locale.toLanguageTag(), - ULocale.getDefault()); - return sentenceCase ? toSentenceCase(result, Locale.getDefault()) : result; + return getDisplayName(locale, Locale.getDefault(), sentenceCase); } /**