Search in sources :

Example 6 with LocaleDisplayNames

use of android.icu.text.LocaleDisplayNames in project j2objc by google.

the class ULocaleCollationTest method TestIllformedLocale.

@Test
public void TestIllformedLocale() {
    ULocale french = ULocale.FRENCH;
    Collator collator = Collator.getInstance(french);
    LocaleDisplayNames names = LocaleDisplayNames.getInstance(french, DisplayContext.CAPITALIZATION_FOR_UI_LIST_OR_MENU);
    for (String malformed : Arrays.asList("en-a", "$", "ü--a", "en--US")) {
        try {
            Set<ULocale> supported = Collections.singleton(new ULocale(malformed));
            names.getUiList(supported, false, collator);
            assertNull("Failed to detect bogus locale «" + malformed + "»", supported);
        } catch (IllformedLocaleException e) {
            logln("Successfully detected ill-formed locale «" + malformed + "»:" + e.getMessage());
        }
    }
}
Also used : ULocale(android.icu.util.ULocale) IllformedLocaleException(android.icu.util.IllformedLocaleException) Collator(android.icu.text.Collator) LocaleDisplayNames(android.icu.text.LocaleDisplayNames) Test(org.junit.Test)

Example 7 with LocaleDisplayNames

use of android.icu.text.LocaleDisplayNames in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class RegionSearchPicker method createAdapterItem.

private List<RegionItem> createAdapterItem(Set<String> regionIds) {
    final Collator collator = Collator.getInstance(getLocale());
    final TreeSet<RegionItem> items = new TreeSet<>(new RegionInfoComparator(collator));
    final LocaleDisplayNames localeDisplayNames = LocaleDisplayNames.getInstance(getLocale());
    long i = 0;
    for (String regionId : regionIds) {
        String name = localeDisplayNames.regionDisplayName(regionId);
        items.add(new RegionItem(i++, regionId, name));
    }
    return new ArrayList<>(items);
}
Also used : TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) Collator(android.icu.text.Collator) LocaleDisplayNames(android.icu.text.LocaleDisplayNames)

Example 8 with LocaleDisplayNames

use of android.icu.text.LocaleDisplayNames in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class RegionZonePicker method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final LocaleDisplayNames localeDisplayNames = LocaleDisplayNames.getInstance(getLocale());
    final String regionId = getArguments() == null ? null : getArguments().getString(EXTRA_REGION_ID);
    mRegionName = regionId == null ? null : localeDisplayNames.regionDisplayName(regionId);
}
Also used : LocaleDisplayNames(android.icu.text.LocaleDisplayNames)

Example 9 with LocaleDisplayNames

use of android.icu.text.LocaleDisplayNames in project j2objc by google.

the class TestLocaleNamePackaging method testLocaleDisplayNameWithKeywords.

// test a 'root' locale, with keywords
@Test
public void testLocaleDisplayNameWithKeywords() {
    String[] expectedWithLanguageData = { "root (collation=phonebook)", "Root (Phonebook Sort Order)", "ra\u00EDz (orden de list\u00EDn telef\u00F3nico)", "Root (Telefonbuch-Sortierung)", "Root (Phonebook Sort Order)" };
    String[] expectedWithoutLanguageData = { "root (collation=phonebook)" };
    String[] expected = LocaleDisplayNamesImpl.haveData(LANG) ? expectedWithLanguageData : expectedWithoutLanguageData;
    ULocale kl = new ULocale("@collation=phonebook");
    int n = 0;
    for (ULocale displayLocale : locales) {
        LocaleDisplayNames dn = LocaleDisplayNames.getInstance(displayLocale);
        String result = dn.localeDisplayName(kl);
        assertEquals(kl + " in " + displayLocale, expected[n++], result);
        if (n == expected.length) {
            n = 0;
        }
    }
}
Also used : ULocale(android.icu.util.ULocale) LocaleDisplayNames(android.icu.text.LocaleDisplayNames) Test(org.junit.Test)

Example 10 with LocaleDisplayNames

use of android.icu.text.LocaleDisplayNames in project j2objc by google.

the class TestLocaleNamePackaging method testLocaleKeywords.

@Test
public void testLocaleKeywords() {
    LocaleDisplayNames dn = LocaleDisplayNames.getInstance(ULocale.US, DialectHandling.DIALECT_NAMES);
    String name = dn.localeDisplayName("de@collation=phonebook");
    String target = LocaleDisplayNamesImpl.haveData(LANG) ? "German (Phonebook Sort Order)" : "de (collation=phonebook)";
    assertEquals("collation", target, name);
}
Also used : LocaleDisplayNames(android.icu.text.LocaleDisplayNames) Test(org.junit.Test)

Aggregations

LocaleDisplayNames (android.icu.text.LocaleDisplayNames)15 Test (org.junit.Test)10 ULocale (android.icu.util.ULocale)7 Collator (android.icu.text.Collator)4 ArrayList (java.util.ArrayList)3 Locale (java.util.Locale)2 TreeSet (java.util.TreeSet)2 Type (android.icu.text.DisplayContext.Type)1 UiListItem (android.icu.text.LocaleDisplayNames.UiListItem)1 IllformedLocaleException (android.icu.util.IllformedLocaleException)1 LinkedHashSet (java.util.LinkedHashSet)1