Search in sources :

Example 21 with UResourceBundle

use of android.icu.util.UResourceBundle in project j2objc by google.

the class ICUResourceBundleTest method TestCoverage.

public void TestCoverage() {
    UResourceBundle bundle;
    bundle = UResourceBundle.getBundleInstance(ICUData.ICU_BASE_NAME);
    if (bundle == null) {
        errln("UResourceBundle.getBundleInstance(String baseName) failed");
    }
    bundle = null;
    bundle = UResourceBundle.getBundleInstance(ULocale.getDefault());
    if (bundle == null) {
        errln("UResourceBundle.getBundleInstance(ULocale) failed");
        return;
    }
    if (new UResourceTypeMismatchException("coverage") == null) {
        errln("Create UResourceTypeMismatchException error");
    }
    class Stub extends UResourceBundle {

        @Override
        public ULocale getULocale() {
            return ULocale.ROOT;
        }

        @Override
        protected String getLocaleID() {
            return null;
        }

        @Override
        protected String getBaseName() {
            return null;
        }

        @Override
        protected UResourceBundle getParent() {
            return null;
        }

        @Override
        public Enumeration getKeys() {
            return null;
        }

        @Override
        protected Object handleGetObject(String aKey) {
            return null;
        }
    }
    Stub stub = new Stub();
    if (!stub.getLocale().equals(ULocale.ROOT.toLocale())) {
        errln("UResourceBundle.getLoclae(Locale) should delegate to (ULocale)");
    }
}
Also used : ICUResourceBundle(android.icu.impl.ICUResourceBundle) UResourceBundle(android.icu.util.UResourceBundle) UResourceTypeMismatchException(android.icu.util.UResourceTypeMismatchException)

Example 22 with UResourceBundle

use of android.icu.util.UResourceBundle in project j2objc by google.

the class DisplayNameTest method getZoneString.

private String getZoneString(ULocale locale, String olsonID, int item) {
    Map data = (Map) zoneData.get(locale);
    if (data == null) {
        data = new HashMap();
        if (SHOW_ALL)
            System.out.println();
        if (SHOW_ALL)
            System.out.println("zones for " + locale);
        ICUResourceBundle bundle = (ICUResourceBundle) UResourceBundle.getBundleInstance(locale);
        ICUResourceBundle table = bundle.getWithFallback("zoneStrings");
        for (int i = 0; i < table.getSize(); ++i) {
            UResourceBundle stringSet = table.get(i);
            // ICUResourceBundle stringSet = table.getWithFallback(String.valueOf(i));
            String key = stringSet.getString(0);
            if (SHOW_ALL)
                System.out.println("key: " + key);
            ArrayList list = new ArrayList();
            for (int j = 1; j < stringSet.getSize(); ++j) {
                String entry = stringSet.getString(j);
                if (SHOW_ALL)
                    System.out.println("  entry: " + entry);
                list.add(entry);
            }
            data.put(key, list.toArray(new String[list.size()]));
        }
        zoneData.put(locale, data);
    }
    String[] strings = (String[]) data.get(olsonID);
    if (strings == null || item >= strings.length)
        return olsonID;
    return strings[item];
}
Also used : ICUResourceBundle(android.icu.impl.ICUResourceBundle) UResourceBundle(android.icu.util.UResourceBundle) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ICUResourceBundle(android.icu.impl.ICUResourceBundle) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map)

Example 23 with UResourceBundle

use of android.icu.util.UResourceBundle in project j2objc by google.

the class ICUResourceBundleTest method TestJavaULocaleBundleLoading.

@Test
public void TestJavaULocaleBundleLoading() {
    String baseName = "android.icu.dev.data.resources.TestDataElements";
    String locName = "en_Latn_US";
    UResourceBundle bundle = UResourceBundle.getBundleInstance(baseName, locName, testLoader);
    String fromRoot = bundle.getString("from_root");
    if (!fromRoot.equals("This data comes from root")) {
        errln("Did not get the expected string for from_root");
    }
    String fromEn = bundle.getString("from_en");
    if (!fromEn.equals("This data comes from en")) {
        errln("Did not get the expected string for from_en");
    }
    String fromEnLatn = bundle.getString("from_en_Latn");
    if (!fromEnLatn.equals("This data comes from en_Latn")) {
        errln("Did not get the expected string for from_en_Latn");
    }
    String fromEnLatnUs = bundle.getString("from_en_Latn_US");
    if (!fromEnLatnUs.equals("This data comes from en_Latn_US")) {
        errln("Did not get the expected string for from_en_Latn_US");
    }
    UResourceBundle bundle1 = UResourceBundle.getBundleInstance(baseName, new ULocale(locName), testLoader);
    if (!bundle1.equals(bundle)) {
        errln("Did not get the expected bundle for " + baseName + "." + locName);
    }
    if (bundle1 != bundle) {
        errln("Did not load the bundle from cache");
    }
    UResourceBundle bundle2 = UResourceBundle.getBundleInstance(baseName, "en_IN", testLoader);
    if (!bundle2.getLocale().toString().equals("en")) {
        errln("Did not get the expected fallback locale. Expected: en Got: " + bundle2.getLocale().toString());
    }
    UResourceBundle bundle3 = UResourceBundle.getBundleInstance(baseName, "te_IN", testLoader);
    if (!bundle3.getLocale().toString().equals("te")) {
        errln("Did not get the expected fallback locale. Expected: te Got: " + bundle2.getLocale().toString());
    }
    // non-existent bundle .. should return default
    UResourceBundle defaultBundle = UResourceBundle.getBundleInstance(baseName, "hi_IN", testLoader);
    ULocale defaultLocale = ULocale.getDefault();
    if (!defaultBundle.getULocale().equals(defaultLocale)) {
        errln("Did not get the default bundle for non-existent bundle");
    }
    // non-existent bundle, non-existent default locale
    // so return the root bundle.
    ULocale.setDefault(ULocale.CANADA_FRENCH);
    UResourceBundle root = UResourceBundle.getBundleInstance(baseName, "hi_IN", testLoader);
    if (!root.getULocale().toString().equals("")) {
        errln("Did not get the root bundle for non-existent default bundle for non-existent bundle");
    }
    // reset the default
    ULocale.setDefault(defaultLocale);
    Enumeration keys = bundle.getKeys();
    int i = 0;
    while (keys.hasMoreElements()) {
        logln("key: " + keys.nextElement());
        i++;
    }
    if (i != 4) {
        errln("Did not get the expected number of keys: got " + i + ", expected 4");
    }
    UResourceBundle bundle4 = UResourceBundle.getBundleInstance(baseName, "fr_Latn_FR", testLoader);
    if (bundle4 == null) {
        errln("Could not load bundle fr_Latn_FR");
    }
}
Also used : ICUResourceBundle(android.icu.impl.ICUResourceBundle) UResourceBundle(android.icu.util.UResourceBundle) ULocale(android.icu.util.ULocale) Enumeration(java.util.Enumeration) Test(org.junit.Test)

Example 24 with UResourceBundle

use of android.icu.util.UResourceBundle in project j2objc by google.

the class ICUResourceBundleTest method TestCLDRStyleAliases.

@Test
public void TestCLDRStyleAliases() {
    String result = null;
    String expected = null;
    String[] expects = new String[] { "", "a41", "a12", "a03", "ar4" };
    logln("Testing CLDR style aliases......\n");
    UResourceBundle rb = UResourceBundle.getBundleInstance("android/icu/dev/data/testdata", "te_IN_REVISED", testLoader);
    ICUResourceBundle alias = (ICUResourceBundle) rb.get("a");
    for (int i = 1; i < 5; i++) {
        String resource = "a" + i;
        UResourceBundle a = (alias).getWithFallback(resource);
        result = a.getString();
        if (result.equals(expected)) {
            errln("CLDR style aliases failed resource with name " + resource + "resource, exp " + expects[i] + " , got " + result);
        }
    }
}
Also used : ICUResourceBundle(android.icu.impl.ICUResourceBundle) UResourceBundle(android.icu.util.UResourceBundle) ICUResourceBundle(android.icu.impl.ICUResourceBundle) Test(org.junit.Test)

Example 25 with UResourceBundle

use of android.icu.util.UResourceBundle in project j2objc by google.

the class KeyTypeData method getTypeInfo.

/**
 * Reads:
 *typeInfo{
 *    deprecated{
 *        co{
 *            direct{"true"}
 *        }
 *        tz{
 *            camtr{"true"}
 *        }
 *    }
 *}
 */
private static void getTypeInfo(UResourceBundle typeInfoRes) {
    Map<String, Set<String>> _deprecatedKeyTypes = new LinkedHashMap<String, Set<String>>();
    for (UResourceBundleIterator keyInfoIt = typeInfoRes.getIterator(); keyInfoIt.hasNext(); ) {
        UResourceBundle keyInfoEntry = keyInfoIt.next();
        String key = keyInfoEntry.getKey();
        TypeInfoType typeInfo = TypeInfoType.valueOf(key);
        for (UResourceBundleIterator keyInfoIt2 = keyInfoEntry.getIterator(); keyInfoIt2.hasNext(); ) {
            UResourceBundle keyInfoEntry2 = keyInfoIt2.next();
            String key2 = keyInfoEntry2.getKey();
            Set<String> _deprecatedTypes = new LinkedHashSet<String>();
            for (UResourceBundleIterator keyInfoIt3 = keyInfoEntry2.getIterator(); keyInfoIt3.hasNext(); ) {
                UResourceBundle keyInfoEntry3 = keyInfoIt3.next();
                String key3 = keyInfoEntry3.getKey();
                switch(// allow for expansion
                typeInfo) {
                    case deprecated:
                        _deprecatedTypes.add(key3);
                        break;
                }
            }
            _deprecatedKeyTypes.put(key2, Collections.unmodifiableSet(_deprecatedTypes));
        }
    }
    DEPRECATED_KEY_TYPES = Collections.unmodifiableMap(_deprecatedKeyTypes);
}
Also used : ICUResourceBundle(android.icu.impl.ICUResourceBundle) UResourceBundle(android.icu.util.UResourceBundle) LinkedHashSet(java.util.LinkedHashSet) UResourceBundleIterator(android.icu.util.UResourceBundleIterator) Set(java.util.Set) HashSet(java.util.HashSet) EnumSet(java.util.EnumSet) LinkedHashSet(java.util.LinkedHashSet) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

UResourceBundle (android.icu.util.UResourceBundle)46 ICUResourceBundle (android.icu.impl.ICUResourceBundle)26 MissingResourceException (java.util.MissingResourceException)24 Test (org.junit.Test)17 ULocale (android.icu.util.ULocale)8 UResourceBundleIterator (android.icu.util.UResourceBundleIterator)6 UResourceTypeMismatchException (android.icu.util.UResourceTypeMismatchException)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 LinkedHashMap (java.util.LinkedHashMap)3 LinkedHashSet (java.util.LinkedHashSet)3 SimpleTimeZone (android.icu.util.SimpleTimeZone)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 EnumSet (java.util.EnumSet)2 Locale (java.util.Locale)2 Map (java.util.Map)2 Set (java.util.Set)2 TreeMap (java.util.TreeMap)2 JavaTimeZone (android.icu.impl.JavaTimeZone)1