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

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

Merge "Create the locale list with ICU4J's ListFormatter"

parents b8a74e5b fc881a25
Loading
Loading
Loading
Loading
+6 −9
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.internal.app;

import android.icu.util.ULocale;
import android.icu.text.ListFormatter;
import android.util.LocaleList;

import java.text.Collator;
@@ -145,20 +146,16 @@ public class LocaleHelper {
     * @return the locale aware list of locale names
     */
    public static String getDisplayLocaleList(LocaleList locales, Locale displayLocale) {
        final StringBuilder result = new StringBuilder();

        final Locale dispLocale = displayLocale == null ? Locale.getDefault() : displayLocale;

        int localeCount = locales.size();
        final String[] localeNames = new String[localeCount];
        for (int i = 0; i < localeCount; i++) {
            Locale locale = locales.get(i);
            result.append(LocaleHelper.getDisplayName(locale, dispLocale, false));
            // TODO: language aware list formatter. ICU has one.
            if (i < localeCount - 1) {
                result.append(", ");
            }
            localeNames[i] = LocaleHelper.getDisplayName(locales.get(i), dispLocale, false);
        }

        return result.toString();
        ListFormatter lfn = ListFormatter.getInstance(dispLocale);
        return lfn.format(localeNames);
    }

    /**