Search in sources :

Example 1 with LocaleDisplayNames

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

the class TimeZoneGenericNames method getLocaleDisplayNames.

/**
 * Private method returning LocaleDisplayNames instance for the locale of this
 * instance. Because LocaleDisplayNames is only used for generic
 * location formant and partial location format, the LocaleDisplayNames
 * is instantiated lazily.
 *
 * @return the instance of LocaleDisplayNames for the locale of this object.
 */
private synchronized LocaleDisplayNames getLocaleDisplayNames() {
    LocaleDisplayNames locNames = null;
    if (_localeDisplayNamesRef != null) {
        locNames = _localeDisplayNamesRef.get();
    }
    if (locNames == null) {
        locNames = LocaleDisplayNames.getInstance(_locale);
        _localeDisplayNamesRef = new WeakReference<LocaleDisplayNames>(locNames);
    }
    return locNames;
}
Also used : LocaleDisplayNames(android.icu.text.LocaleDisplayNames)

Example 2 with LocaleDisplayNames

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

the class TestLocaleNamePackaging method testRegionDisplayNames.

@Test
public void testRegionDisplayNames() {
    String[] expectedWithRegionData = { "", "US", "ES", "DE", "TH", "", "United States", "Spain", "Germany", "Thailand", "", "Estados Unidos", "Espa\u00f1a", "Alemania", "Tailandia", "", "Vereinigte Staaten", "Spanien", "Deutschland", "Thailand", "", "United States", "Spain", "Germany", "Thailand" };
    String[] expectedWithoutRegionData = { "", "US", "ES", "DE", "TH" };
    String[] expected = LocaleDisplayNamesImpl.haveData(REGION) ? expectedWithRegionData : expectedWithoutRegionData;
    int n = 0;
    for (ULocale displayLocale : locales) {
        LocaleDisplayNames dn = LocaleDisplayNames.getInstance(displayLocale);
        for (ULocale targetLocale : locales) {
            String result = dn.regionDisplayName(targetLocale.getCountry());
            assertEquals(targetLocale + " in " + displayLocale, expected[n++], result);
            if (n == expected.length) {
                n = 0;
            }
        }
    }
    // Same test with Java Locale
    n = 0;
    for (Locale displayJavaLocale : javaLocales) {
        LocaleDisplayNames dn = LocaleDisplayNames.getInstance(displayJavaLocale);
        for (Locale targetLocale : javaLocales) {
            String result = dn.regionDisplayName(targetLocale.getCountry());
            assertEquals(targetLocale + " in " + displayJavaLocale, expected[n++], result);
            if (n == expected.length) {
                n = 0;
            }
        }
    }
}
Also used : Locale(java.util.Locale) ULocale(android.icu.util.ULocale) ULocale(android.icu.util.ULocale) LocaleDisplayNames(android.icu.text.LocaleDisplayNames) Test(org.junit.Test)

Example 3 with LocaleDisplayNames

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

the class TestLocaleNamePackaging method testLanguageDisplayNames.

@Test
public void testLanguageDisplayNames() {
    String[] expectedWithLanguageData = { "", "en", "es", "de", "und", "", "English", "Spanish", "German", "Unknown Language", "", "ingl\u00E9s", "espa\u00F1ol", "alem\u00E1n", "lengua desconocida", "", "Englisch", "Spanisch", "Deutsch", "Unbestimmte Sprache", "", "English", "Spanish", "German", "Unknown Language" };
    String[] expectedWithoutLanguageData = { "", "en", "es", "de", "und" };
    String[] expected = LocaleDisplayNamesImpl.haveData(LANG) ? expectedWithLanguageData : expectedWithoutLanguageData;
    int n = 0;
    for (ULocale displayLocale : locales) {
        LocaleDisplayNames dn = LocaleDisplayNames.getInstance(displayLocale);
        for (ULocale targetLocale : locales) {
            String result = dn.languageDisplayName(targetLocale.getLanguage());
            assertEquals(targetLocale + " in " + displayLocale, expected[n++], result);
            if (n == expected.length) {
                n = 0;
            }
        }
    }
    // Same test with Java Locale
    n = 0;
    for (Locale displayJavaLocale : javaLocales) {
        LocaleDisplayNames dn = LocaleDisplayNames.getInstance(displayJavaLocale);
        for (Locale targetLocale : javaLocales) {
            String result = dn.languageDisplayName(targetLocale.getLanguage());
            assertEquals(targetLocale + " in " + displayJavaLocale, expected[n++], result);
            if (n == expected.length) {
                n = 0;
            }
        }
    }
}
Also used : Locale(java.util.Locale) ULocale(android.icu.util.ULocale) ULocale(android.icu.util.ULocale) LocaleDisplayNames(android.icu.text.LocaleDisplayNames) Test(org.junit.Test)

Example 4 with LocaleDisplayNames

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

the class TestLocaleNamePackaging method testLanguageDisplayNameDoesNotTranslateRoot.

@Test
public void testLanguageDisplayNameDoesNotTranslateRoot() {
    // "root" is not a language code-- the fact that we have our data organized this
    // way is immaterial.  "root" remains untranslated whether we have data or not.
    LocaleDisplayNames dn = LocaleDisplayNames.getInstance(ULocale.US);
    assertEquals("root", "root", dn.languageDisplayName("root"));
}
Also used : LocaleDisplayNames(android.icu.text.LocaleDisplayNames) Test(org.junit.Test)

Example 5 with LocaleDisplayNames

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

the class ULocaleTest method TestUldnWithGarbage.

@Test
public void TestUldnWithGarbage() {
    LocaleDisplayNames ldn = LocaleDisplayNames.getInstance(Locale.US, DisplayContext.DIALECT_NAMES);
    String badLocaleID = "english (United States) [w";
    // case changed from input
    String expectedResult = "english [united states] [w";
    String result = ldn.localeDisplayName(badLocaleID);
    if (result.compareTo(expectedResult) != 0) {
        errln("FAIL: LocaleDisplayNames.localeDisplayName(String) for bad locale ID \"" + badLocaleID + "\", expected \"" + expectedResult + "\", got \"" + result + "\"");
    }
    ULocale badLocale = new ULocale(badLocaleID);
    result = ldn.localeDisplayName(badLocale);
    if (result.compareTo(expectedResult) != 0) {
        errln("FAIL: LocaleDisplayNames.localeDisplayName(ULocale) for bad locale ID \"" + badLocaleID + "\", expected \"" + expectedResult + "\", got \"" + result + "\"");
    }
}
Also used : ULocale(android.icu.util.ULocale) 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