Merge "Use DisplayNameWithDialect only for some locales" into nyc-dev

am: e544d40

* commit 'e544d408c06fe3e6bc3b237f718b56f03f079f29':
  Use DisplayNameWithDialect only for some locales

Change-Id: I0611e41a010c6b5c4a937c8c5de501d3749cd438
This commit is contained in:
Mihai Nita
2016-04-12 05:03:34 +00:00
committed by android-build-merger

View File

@@ -90,6 +90,15 @@ public class LocaleHelper {
return str.toUpperCase(); 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. * Returns the locale localized for display in the provided locale.
* *
@@ -99,8 +108,10 @@ public class LocaleHelper {
* @return the localized name of the locale. * @return the localized name of the locale.
*/ */
public static String getDisplayName(Locale locale, Locale displayLocale, boolean sentenceCase) { public static String getDisplayName(Locale locale, Locale displayLocale, boolean sentenceCase) {
String result = ULocale.getDisplayNameWithDialect(locale.toLanguageTag(), final ULocale displayULocale = ULocale.forLocale(displayLocale);
ULocale.forLocale(displayLocale)); String result = shouldUseDialectName(locale)
? ULocale.getDisplayNameWithDialect(locale.toLanguageTag(), displayULocale)
: ULocale.getDisplayName(locale.toLanguageTag(), displayULocale);
return sentenceCase ? toSentenceCase(result, displayLocale) : result; return sentenceCase ? toSentenceCase(result, displayLocale) : result;
} }
@@ -112,9 +123,7 @@ public class LocaleHelper {
* @return the localized name of the locale. * @return the localized name of the locale.
*/ */
public static String getDisplayName(Locale locale, boolean sentenceCase) { public static String getDisplayName(Locale locale, boolean sentenceCase) {
String result = ULocale.getDisplayNameWithDialect(locale.toLanguageTag(), return getDisplayName(locale, Locale.getDefault(), sentenceCase);
ULocale.getDefault());
return sentenceCase ? toSentenceCase(result, Locale.getDefault()) : result;
} }
/** /**