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

Commit fc881a25 authored by Mihai Nita's avatar Mihai Nita
Browse files

Create the locale list with ICU4J's ListFormatter

The list of user locales showing under Language & input -- Language
used a hard-coded comma as separator.
Changing that code to use the ICU locale-aware formatter.

Bug: 26848487
Change-Id: I36975da3a3770df8abaf7e3987b188f2e912f378
parent 5720c8c1
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);
    }

    /**