Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e544d408 authored by Mihai Niță's avatar Mihai Niță Committed by Android (Google) Code Review
Browse files

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

parents 6b34b310 1b2e7adc
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -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);
    }

    /**