return prefix + suffix;
}
}
public void TestLocale() {
ICULocaleService service = new ICULocaleService("test locale");
service.registerObject("root", ULocale.ROOT);
service.registerObject("german", "de");
service.registerObject("german_Germany", ULocale.GERMANY);
service.registerObject("japanese", "ja");
service.registerObject("japanese_Japan", ULocale.JAPAN);
Object target = service.get("de_US");
confirmEqual("test de_US", "german", target);
ULocale de = new ULocale("de");
ULocale de_US = new ULocale("de_US");
target = service.get(de_US);
confirmEqual("test de_US 2", "german", target);
target = service.get(de_US, LocaleKey.KIND_ANY);
confirmEqual("test de_US 3", "german", target);
target = service.get(de_US, 1234);
confirmEqual("test de_US 4", "german", target);
ULocale[] actualReturn = new ULocale[1];
target = service.get(de_US, actualReturn);
confirmEqual("test de_US 5", "german", target);
confirmEqual("test de_US 6", actualReturn[0], de);
actualReturn[0] = null;
target = service.get(de_US, LocaleKey.KIND_ANY, actualReturn);
confirmEqual("test de_US 7", actualReturn[0], de);
actualReturn[0] = null;
target = service.get(de_US, 1234, actualReturn);
confirmEqual("test de_US 8", "german", target);
confirmEqual("test de_US 9", actualReturn[0], de);
service.registerObject("one/de_US", de_US, 1);
service.registerObject("two/de_US", de_US, 2);
target = service.get(de_US, 1);
confirmEqual("test de_US kind 1", "one/de_US", target);
target = service.get(de_US, 2);
confirmEqual("test de_US kind 2", "two/de_US", target);
target = service.get(de_US);
confirmEqual("test de_US kind 3", "german", target);
LocaleKey lkey = LocaleKey.createWithCanonicalFallback("en", null, 1234);
logln("lkey prefix: " + lkey.prefix());
logln("lkey descriptor: " + lkey.currentDescriptor());
logln("lkey current locale: " + lkey.currentLocale());
lkey.fallback();
logln("lkey descriptor 2: " + lkey.currentDescriptor());
lkey.fallback();
logln("lkey descriptor 3: " + lkey.currentDescriptor());
target = service.get("za_PPP");
confirmEqual("test zappp", "root", target);
ULocale loc = ULocale.getDefault();
ULocale.setDefault(ULocale.JAPANESE);
target = service.get("za_PPP");
confirmEqual("test with ja locale", "japanese", target);
Set ids = service.getVisibleIDs();
for (Iterator iter = ids.iterator(); iter.hasNext();) {
logln("id: " + iter.next());
}
ULocale.setDefault(loc);
ids = service.getVisibleIDs();
for (Iterator iter = ids.iterator(); iter.hasNext();) {
logln("id: " + iter.next());
}
target = service.get("za_PPP");
confirmEqual("test with en locale", "root", target);
ULocale[] locales = service.getAvailableULocales();
confirmIdentical("test available locales", locales.length, 6);
logln("locales: ");
for (int i = 0; i < locales.length; ++i) {
log("\n [" + i + "] " + locales[i]);
}
logln(" ");
service.registerFactory(new ICUResourceBundleFactory());
target = service.get(ULocale.JAPAN);
{
int n = 0;
List factories = service.factories();
Iterator iter = factories.iterator();
while (iter.hasNext()) {
logln("[" + n++ + "] " + iter.next());
}
}
// list only the english display names for es, in reverse order
// since we're using locale keys, we should get all and only the es locales
// hmmm, the default toString function doesn't print in sorted order for TreeMap
{
SortedMap map = service.getDisplayNames(ULocale.US,
new Comparator() {
public int compare(Object lhs, Object rhs) {
return -String.CASE_INSENSITIVE_ORDER.compare((String)lhs, (String)rhs);
}
},