use of android.icu.text.LocaleDisplayNames in project j2objc by google.
the class TestLocaleNamePackaging method testLanguageDisplayNameDoesNotTranslateDialects.
@Test
public void testLanguageDisplayNameDoesNotTranslateDialects() {
// Dialect ids are also not language codes.
LocaleDisplayNames dn = LocaleDisplayNames.getInstance(ULocale.US, DialectHandling.DIALECT_NAMES);
assertEquals("dialect", "en_GB", dn.languageDisplayName("en_GB"));
String target = LocaleDisplayNamesImpl.haveData(LANG) ? "British English" : (LocaleDisplayNamesImpl.haveData(REGION) ? "en (United Kingdom)" : "en (GB)");
assertEquals("dialect 2", target, dn.localeDisplayName("en_GB"));
}
use of android.icu.text.LocaleDisplayNames in project j2objc by google.
the class ULocaleTest method TestDisplayWithKeyword.
@Test
public void TestDisplayWithKeyword() {
// Note, this test depends on locale display data for the U.S. and Taiwan.
// If the data changes (in particular, the keyTypePattern may change for Taiwan),
// this test will break.
LocaleDisplayNames dn = LocaleDisplayNames.getInstance(ULocale.US, DialectHandling.DIALECT_NAMES);
LocaleDisplayNames tdn = LocaleDisplayNames.getInstance(ULocale.TAIWAN, DialectHandling.DIALECT_NAMES);
String name = dn.localeDisplayName("de@collation=phonebook");
String target = "German (Phonebook Sort Order)";
assertEquals("collation", target, name);
name = tdn.localeDisplayName("de@collation=phonebook");
// \u5FB7\u6587\uFF08\u96FB\u8A71\u7C3F\u6392\u5E8F\uFF09
target = "德文(電話簿排序)";
assertEquals("collation", target, name);
name = dn.localeDisplayName("ja@currency=JPY");
target = "Japanese (Japanese Yen)";
assertEquals("currency (JPY)", target, name);
name = tdn.localeDisplayName("ja@currency=JPY");
// \u65E5\u6587\uFF08\u65E5\u5713\uFF09
target = "日文(日圓)";
assertEquals("currency (JPY)", target, name);
name = dn.localeDisplayName("de@currency=XYZ");
target = "German (Currency: XYZ)";
assertEquals("currency (XYZ)", target, name);
name = dn.localeDisplayName("de@collation=phonebook;currency=XYZ");
target = "German (Phonebook Sort Order, Currency: XYZ)";
assertEquals("currency", target, name);
name = dn.localeDisplayName("de_Latn_DE");
target = "German (Latin, Germany)";
assertEquals("currency", target, name);
name = tdn.localeDisplayName("de@currency=XYZ");
// \u5FB7\u6587\uFF08\u8CA8\u5E63: XYZ\uFF09
target = "德文(貨幣:XYZ)";
assertEquals("currency", target, name);
name = tdn.localeDisplayName("de@collation=phonebook;currency=XYZ");
// \u5FB7\u6587\uFF08\u96FB\u8A71\u7C3F\u6392\u5E8F\uFF09,\u5FB7\u6587\uFF08\u8CA8\u5E63: XYZ\uFF09
target = "德文(電話簿排序,貨幣:XYZ)";
assertEquals("collation", target, name);
name = dn.localeDisplayName("de@foo=bar");
target = "German (foo=bar)";
assertEquals("foo", target, name);
name = tdn.localeDisplayName("de@foo=bar");
// \u5FB7\u6587\uFF08foo=bar\uFF09
target = "德文(foo=bar)";
assertEquals("foo", target, name);
ULocale locale = ULocale.forLanguageTag("de-x-foobar");
name = dn.localeDisplayName(locale);
target = "German (Private-Use: foobar)";
assertEquals("foobar", target, name);
name = tdn.localeDisplayName(locale);
// \u5FB7\u6587\uFF08\u79C1\u4EBA\u4F7F\u7528: foobar\uFF09
target = "德文(私人使用:foobar)";
assertEquals("foobar", target, name);
}
use of android.icu.text.LocaleDisplayNames in project j2objc by google.
the class ULocaleCollationTest method TestNameList.
@Test
public void TestNameList() {
String[][][] tests = { /* name in French, name in self, minimized, modified */
{ { "fr-Cyrl-BE", "fr-Cyrl-CA" }, { "Français (cyrillique, Belgique)", "Français (cyrillique, Belgique)", "fr_Cyrl_BE", "fr_Cyrl_BE" }, { "Français (cyrillique, Canada)", "Français (cyrillique, Canada)", "fr_Cyrl_CA", "fr_Cyrl_CA" } }, { { "en", "de", "fr", "zh" }, { "Allemand", "Deutsch", "de", "de" }, { "Anglais", "English", "en", "en" }, { "Chinois", "中文", "zh", "zh" }, { "Français", "Français", "fr", "fr" } }, // some non-canonical names
{ { "iw", "iw-US", "no", "no-Cyrl", "in", "in-YU" }, { "Hébreu (États-Unis)", "עברית (ארצות הברית)", "iw_US", "iw_US" }, { "Hébreu (Israël)", "עברית (ישראל)", "iw", "iw_IL" }, { "Indonésien (Indonésie)", "Indonesia (Indonesia)", "in", "in_ID" }, { "Indonésien (Serbie)", "Indonesia (Serbia)", "in_YU", "in_YU" }, { "Norvégien (cyrillique)", "Norsk (kyrillisk)", "no_Cyrl", "no_Cyrl" }, { "Norvégien (latin)", "Norsk (latinsk)", "no", "no_Latn" } }, { { "zh-Hant-TW", "en", "en-gb", "fr", "zh-Hant", "de", "de-CH", "zh-TW" }, { "Allemand (Allemagne)", "Deutsch (Deutschland)", "de", "de_DE" }, { "Allemand (Suisse)", "Deutsch (Schweiz)", "de_CH", "de_CH" }, { "Anglais (États-Unis)", "English (United States)", "en", "en_US" }, { "Anglais (Royaume-Uni)", "English (United Kingdom)", "en_GB", "en_GB" }, { "Chinois (traditionnel)", "中文(繁體)", "zh_Hant", "zh_Hant" }, { "Français", "Français", "fr", "fr" } }, { { "zh", "en-gb", "en-CA", "fr-Latn-FR" }, { "Anglais (Canada)", "English (Canada)", "en_CA", "en_CA" }, { "Anglais (Royaume-Uni)", "English (United Kingdom)", "en_GB", "en_GB" }, { "Chinois", "中文", "zh", "zh" }, { "Français", "Français", "fr", "fr" } }, { { "en-gb", "fr", "zh-Hant", "zh-SG", "sr", "sr-Latn" }, { "Anglais (Royaume-Uni)", "English (United Kingdom)", "en_GB", "en_GB" }, { "Chinois (simplifié, Singapour)", "中文(简体,新加坡)", "zh_SG", "zh_Hans_SG" }, { "Chinois (traditionnel, Taïwan)", "中文(繁體,台灣)", "zh_Hant", "zh_Hant_TW" }, { "Français", "Français", "fr", "fr" }, { "Serbe (cyrillique)", "Српски (ћирилица)", "sr", "sr_Cyrl" }, { "Serbe (latin)", "Srpski (latinica)", "sr_Latn", "sr_Latn" } }, { { "fr-Cyrl", "fr-Arab" }, { "Français (arabe)", "Français (arabe)", "fr_Arab", "fr_Arab" }, { "Français (cyrillique)", "Français (cyrillique)", "fr_Cyrl", "fr_Cyrl" } }, { { "fr-Cyrl-BE", "fr-Arab-CA" }, { "Français (arabe, Canada)", "Français (arabe, Canada)", "fr_Arab_CA", "fr_Arab_CA" }, { "Français (cyrillique, Belgique)", "Français (cyrillique, Belgique)", "fr_Cyrl_BE", "fr_Cyrl_BE" } } };
ULocale french = ULocale.FRENCH;
LocaleDisplayNames names = LocaleDisplayNames.getInstance(french, DisplayContext.CAPITALIZATION_FOR_UI_LIST_OR_MENU);
for (Type type : DisplayContext.Type.values()) {
logln("Contexts: " + names.getContext(type).toString());
}
Collator collator = Collator.getInstance(french);
for (String[][] test : tests) {
Set<ULocale> list = new LinkedHashSet<ULocale>();
List<UiListItem> expected = new ArrayList<UiListItem>();
for (String item : test[0]) {
list.add(new ULocale(item));
}
for (int i = 1; i < test.length; ++i) {
String[] rawRow = test[i];
expected.add(new UiListItem(new ULocale(rawRow[2]), new ULocale(rawRow[3]), rawRow[0], rawRow[1]));
}
List<UiListItem> newList = names.getUiList(list, false, collator);
if (!expected.equals(newList)) {
if (expected.size() != newList.size()) {
errln(list.toString() + ": wrong size" + expected + ", " + newList);
} else {
errln(list.toString());
for (int i = 0; i < expected.size(); ++i) {
assertEquals(i + "", expected.get(i), newList.get(i));
}
}
} else {
assertEquals(list.toString(), expected, newList);
}
}
}
use of android.icu.text.LocaleDisplayNames in project android_packages_apps_Settings by omnirom.
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);
}
use of android.icu.text.LocaleDisplayNames in project android_packages_apps_Settings by omnirom.
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);
}
Aggregations