// This method is for super class's instantiateBundle method
        new public static ResourceBundleWrapper GetBundleInstance(string baseName, string localeID,
                                                                  Assembly root, bool disableFallback)
        {
            if (root == null)
            {
                root = GetAssembly(baseName); // ICU4N: Load the correct assembly based on baseName if not explicitly provided
            }
            ResourceBundleWrapper b;

            if (disableFallback)
            {
                b = InstantiateBundle(baseName, localeID, null, root, disableFallback);
            }
            else
            {
                b = InstantiateBundle(baseName, localeID, ULocale.GetDefault().GetBaseName(),
                                      root, disableFallback);
            }
            if (b == null)
            {
                string separator = "_";
                if (baseName.IndexOf('/') >= 0)
                {
                    separator = "/";
                }
                throw new MissingManifestResourceException("Could not find the bundle " + baseName + separator + localeID);
            }
            return(b);
        }
Exemple #2
0
        public void TestCollation()
        {
            ULocale defLoc = ULocale.GetDefault();

            ULocale.SetDefault(_DEFAULT_LOCALE);
            for (int i = 0; i < _LOCALE_NUMBER; i++)
            {
                ULocale oldLoc = _LOCALES[i][0];
                ULocale newLoc = _LOCALES[i][1];
                if (availableMap.Get(_LOCALES[i][1]) == null)
                {
                    Logln(_LOCALES[i][1] + " is not available. Skipping!");
                    continue;
                }
                Collator c1 = Collator.GetInstance(oldLoc);
                Collator c2 = Collator.GetInstance(newLoc);

                if (!c1.Equals(c2))
                {
                    Errln("CollationTest: c1!=c2: newLoc= " + newLoc + " oldLoc= " + oldLoc);
                }

                Logln("Collation old:" + oldLoc + "   new:" + newLoc);
            }
            ULocale.SetDefault(defLoc);
        }
        // This method is for super class's instantiateBundle method
        new public static ResourceBundleWrapper GetBundleInstance(string baseName, string localeID,
                                                                  Assembly root, bool disableFallback)
        {
            if (root == null)
            {
                // ICU4N TODO: Check this
                root = typeof(ICUData).GetTypeInfo().Assembly; //ClassLoaderUtil.getClassLoader();
            }
            ResourceBundleWrapper b;

            if (disableFallback)
            {
                b = InstantiateBundle(baseName, localeID, null, root, disableFallback);
            }
            else
            {
                b = InstantiateBundle(baseName, localeID, ULocale.GetDefault().GetBaseName(),
                                      root, disableFallback);
            }
            if (b == null)
            {
                string separator = "_";
                if (baseName.IndexOf('/') >= 0)
                {
                    separator = "/";
                }
                throw new MissingManifestResourceException("Could not find the bundle " + baseName + separator + localeID);
            }
            return(b);
        }
Exemple #4
0
 public virtual void SetLocale(ULocale ulocale)
 {
     if (ulocale == null)
     {
         ulocale = ULocale.GetDefault(ULocale.Category.FORMAT);
     }
     Init(null, PluralType.Cardinal, ulocale, null);
 }
Exemple #5
0
        /**
         * Convenience override of getDisplayNames(ULocale, Comparator, string) that
         * uses the current default ULocale as the locale, the default collator for
         * the locale as the comparator to sort the display names, and null for
         * the matchID.
         */
        public SortedDictionary <string, string> GetDisplayNames(ICUService service)
        {
            ULocale locale = ULocale.GetDefault();
            //Collator col = Collator.getInstance(locale.toLocale());
            CompareInfo col = CompareInfo.GetCompareInfo(locale.ToLocale().Name);

            return(service.GetDisplayNames(locale, col, null));
        }
Exemple #6
0
 /**
  * {@icu} Creates a UResourceBundle for the locale specified, from which users can extract
  * resources by using their corresponding keys.
  * @param locale  specifies the locale for which we want to open the resource.
  *                If null the bundle for default locale is opened.
  * @return a resource bundle for the given locale
  * @stable ICU 3.0
  */
 public static UResourceBundle GetBundleInstance(ULocale locale)
 {
     if (locale == null)
     {
         locale = ULocale.GetDefault();
     }
     return(GetBundleInstance(ICUData.ICU_BASE_NAME, locale.GetBaseName(),
                              ICUResourceBundle.ICU_DATA_CLASS_LOADER, false));
 }
            public void TestLocaleGetCode(ULocale testLocaleName, int expected)
            {
                int[] code = UScript.GetCode(testLocaleName);
                if (code == null)
                {
                    if (expected != UScript.InvalidCode)
                    {
                        Errln("Error testing UScript.getCode(). Got: null" + " Expected: " + expected + " for locale "
                              + testLocaleName);
                    }
                }
                else if ((code[0] != expected))
                {
                    Errln("Error testing UScript.getCode(). Got: " + code[0] + " Expected: " + expected + " for locale "
                          + testLocaleName);
                }

                ULocale defaultLoc = ULocale.GetDefault();
                ULocale esperanto  = new ULocale("eo_DE");

                ULocale.SetDefault(esperanto);
                code = UScript.GetCode(esperanto);
                if (code != null)
                {
                    if (code[0] != UScript.Latin)
                    {
                        Errln("Did not get the expected script code for Esperanto");
                    }
                }
                else
                {
                    Warnln("Could not load the locale data.");
                }
                ULocale.SetDefault(defaultLoc);

                // Should work regardless of whether we have locale data for the language.
                AssertEqualScripts("tg script: Cyrl",  // Tajik
                                   new int[] { UScript.Cyrillic }, UScript.GetCode(new ULocale("tg")));
                AssertEqualScripts("xsr script: Deva", // Sherpa
                                   new int[] { UScript.Devanagari }, UScript.GetCode(new ULocale("xsr")));

                // Multi-script languages.
                AssertEqualScripts("ja scripts: Kana Hira Hani",
                                   new int[] { UScript.Katakana, UScript.Hiragana, UScript.Han }, UScript.GetCode(ULocale.JAPANESE));
                AssertEqualScripts("ko scripts: Hang Hani", new int[] { UScript.Hangul, UScript.Han },
                                   UScript.GetCode(ULocale.KOREAN));
                AssertEqualScripts("zh script: Hani", new int[] { UScript.Han }, UScript.GetCode(ULocale.CHINESE));
                AssertEqualScripts("zh-Hant scripts: Hani Bopo", new int[] { UScript.Han, UScript.Bopomofo },
                                   UScript.GetCode(ULocale.TRADITIONAL_CHINESE));
                AssertEqualScripts("zh-TW scripts: Hani Bopo", new int[] { UScript.Han, UScript.Bopomofo },
                                   UScript.GetCode(ULocale.TAIWAN));

                // Ambiguous API, but this probably wants to return Latin rather than Rongorongo (Roro).
                AssertEqualScripts("ro-RO script: Latn", new int[] { UScript.Latin }, UScript.GetCode("ro-RO")); // String
                                                                                                                 // not
                                                                                                                 // ULocale
            }
Exemple #8
0
        /**
         * {@icu} Creates a UResourceBundle for the specified locale and specified base name,
         * from which users can extract resources by using their corresponding keys.
         * @param baseName string containing the name of the data package.
         *                    If null the default ICU package name is used.
         * @param locale  specifies the locale for which we want to open the resource.
         *                If null the bundle for default locale is opened.
         * @param loader  the loader to use
         * @return a resource bundle for the given base name and locale
         * @stable ICU 3.8
         */
        public static UResourceBundle GetBundleInstance(string baseName, CultureInfo locale,
                                                        Assembly loader)
        {
            if (baseName == null)
            {
                baseName = ICUData.ICU_BASE_NAME;
            }
            ULocale uloc = locale == null?ULocale.GetDefault() : ULocale.ForLocale(locale);

            return(GetBundleInstance(baseName, uloc.GetBaseName(), loader, false));
        }
Exemple #9
0
        /**
         * {@icu} Creates a UResourceBundle for the specified locale and specified base name,
         * from which users can extract resources by using their corresponding keys.
         * @param baseName string containing the name of the data package.
         *                    If null the default ICU package name is used.
         * @param locale  specifies the locale for which we want to open the resource.
         *                If null the bundle for default locale is opened.
         * @return a resource bundle for the given base name and locale
         * @stable ICU 3.0
         */

        public static UResourceBundle GetBundleInstance(string baseName, CultureInfo locale)
        {
            if (baseName == null)
            {
                baseName = ICUData.ICU_BASE_NAME;
            }
            ULocale uloc = locale == null?ULocale.GetDefault() : ULocale.ForLocale(locale);

            //return GetBundleInstance(baseName, uloc.GetBaseName(),
            //                         ICUResourceBundle.ICU_DATA_CLASS_LOADER, false);
            return(GetBundleInstance(baseName, uloc.GetBaseName(),
                                     GetAssembly(baseName), false));
        }
Exemple #10
0
 /**
  * {@icu} Creates a UResourceBundle, from which users can extract resources by using
  * their corresponding keys.<br><br>
  * Note: Please use this API for loading non-ICU resources. Java security does not
  * allow loading of resources across jar files. You must provide your class loader
  * to load the resources
  * @param baseName string containing the name of the data package.
  *                    If null the default ICU package name is used.
  * @param locale  specifies the locale for which we want to open the resource.
  *                If null the bundle for default locale is opened.
  * @param loader  the loader to use
  * @return a resource bundle for the given base name and locale
  * @stable ICU 3.8
  */
 public static UResourceBundle GetBundleInstance(string baseName, ULocale locale,
                                                 Assembly loader)
 {
     if (baseName == null)
     {
         baseName = ICUData.ICU_BASE_NAME;
     }
     if (locale == null)
     {
         locale = ULocale.GetDefault();
     }
     return(GetBundleInstance(baseName, locale.GetBaseName(), loader, false));
 }
Exemple #11
0
 /**
  * {@icu} Creates a UResourceBundle, from which users can extract resources by using
  * their corresponding keys.
  * @param baseName string containing the name of the data package.
  *                    If null the default ICU package name is used.
  * @param locale  specifies the locale for which we want to open the resource.
  *                If null the bundle for default locale is opened.
  * @return a resource bundle for the given base name and locale
  * @stable ICU 3.0
  */
 public static UResourceBundle GetBundleInstance(string baseName, ULocale locale)
 {
     if (baseName == null)
     {
         baseName = ICUData.ICU_BASE_NAME;
     }
     if (locale == null)
     {
         locale = ULocale.GetDefault();
     }
     //return GetBundleInstance(baseName, locale.GetBaseName(),
     //                         ICUResourceBundle.ICU_DATA_CLASS_LOADER, false);
     return(GetBundleInstance(baseName, locale.GetBaseName(),
                              GetAssembly(baseName), false));
 }
Exemple #12
0
        /// <summary>
        /// Return the name of the current fallback locale.  If it has changed since this was
        /// last accessed, the service cache is cleared.
        /// </summary>
        public virtual string ValidateFallbackLocale()
        {
            ULocale loc = ULocale.GetDefault();

            if (loc != fallbackLocale)
            {
                lock (this)
                {
                    if (loc != fallbackLocale)
                    {
                        fallbackLocale     = loc;
                        fallbackLocaleName = loc.GetBaseName();
                        ClearServiceCache();
                    }
                }
            }
            return(fallbackLocaleName);
        }
Exemple #13
0
 /// <summary>
 /// Returns the default numbering system for the default <see cref="ULocale.Category.FORMAT"/>
 /// </summary>
 /// <seealso cref="ULocale.Category.FORMAT"/>
 /// <stable>ICU 4.2</stable>
 public static NumberingSystem GetInstance()
 {
     return(GetInstance(ULocale.GetDefault(ULocale.Category.FORMAT)));
 }
Exemple #14
0
        /// <summary>
        /// Convenience override of <see cref="GetDisplayNames(ULocale, IComparer{string}, string)"/> that
        /// uses the current default Locale as the locale, null as
        /// the comparer, and null for the matchID.
        /// </summary>
        public virtual SortedDictionary <string, string> GetDisplayNames()
        {
            ULocale locale = ULocale.GetDefault(Category.DISPLAY);

            return(GetDisplayNames(locale, (IComparer <string>)null, null));
        }
Exemple #15
0
 /// <summary>
 /// Convenience override for <see cref="GetDisplayName(string, ULocale)"/> that
 /// uses the current default locale.
 /// </summary>
 public virtual string GetDisplayName(string id)
 {
     return(GetDisplayName(id, ULocale.GetDefault(Category.DISPLAY)));
 }
Exemple #16
0
        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);

            var ids = service.GetVisibleIDs();

            for (var iter = ids.GetEnumerator(); iter.MoveNext();)
            {
                Logln("id: " + iter.Current);
            }

            ULocale.SetDefault(loc);
            ids = service.GetVisibleIDs();
            for (var iter = ids.GetEnumerator(); iter.MoveNext();)
            {
                Logln("id: " + iter.Current);
            }

            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;
                var factories = service.Factories();
                var iter      = factories.GetEnumerator();
                while (iter.MoveNext())
                {
                    Logln("[" + n++ + "] " + iter.Current);
                }
            }

            // 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
            {
                var map = service.GetDisplayNames(ULocale.US,
                                                  new AnonymousComparer <object>(compare: (lhs, rhs) =>
                {
                    return(-StringComparer.OrdinalIgnoreCase.Compare((string)lhs, (string)rhs));
                }),
                                                  //                    new Comparator() {
                                                  //                            @Override
                                                  //                            public int compare(object lhs, object rhs)
                                                  //    {
                                                  //        return -string.CASE_INSENSITIVE_ORDER.compare((string)lhs, (string)rhs);
                                                  //    }
                                                  //},
                                                  "es");

                Logln("es display names in reverse order " + map);
            }
        }
Exemple #17
0
 /// <summary>
 /// Gets the <see cref="LocaleData"/> object associated with the default <see cref="Category.FORMAT"/> locale.
 /// </summary>
 /// <returns>A locale data object.</returns>
 /// <see cref="Category.FORMAT"/>
 /// <stable>ICU 3.4</stable>
 public static LocaleData GetInstance()
 {
     return(LocaleData.GetInstance(ULocale.GetDefault(Category.FORMAT)));
 }
Exemple #18
0
 /// <summary>
 /// Creates a new cardinal-number <see cref="PluralFormat"/> for the default <see cref="ULocale.Category.FORMAT"/> locale.
 /// This locale will be used to get the set of plural rules and for standard
 /// number formatting.
 /// </summary>
 /// <stable>ICU 3.8</stable>
 public PluralFormat()
 {
     Init(null, PluralType.Cardinal, ULocale.GetDefault(ULocale.Category.FORMAT), null);
 }
Exemple #19
0
 /// <summary>
 /// Creates a new cardinal-number <see cref="PluralFormat"/> for a given set of rules.
 /// The standard number formatting will be done using the default <see cref="ULocale.Category.FORMAT"/> locale.
 /// </summary>
 /// <param name="rules">defines the behavior of the <see cref="PluralFormat"/>
 /// object.</param>
 /// <seealso cref="ULocale.Category.FORMAT"/>
 /// <stable>ICU 3.8</stable>
 public PluralFormat(PluralRules rules)
 {
     Init(rules, PluralType.Cardinal, ULocale.GetDefault(ULocale.Category.FORMAT), null);
 }
Exemple #20
0
 /// <summary>
 /// Creates a new cardinal-number <see cref="PluralFormat"/> for a given set of rules and a
 /// pattern.
 /// The standard number formatting will be done using the default <see cref="ULocale.Category.FORMAT"/> locale.
 /// </summary>
 /// <param name="rules">defines the behavior of the <see cref="PluralFormat"/>
 /// object.</param>
 /// <param name="pattern">the pattern for this <see cref="PluralFormat"/>.</param>
 /// <exception cref="ArgumentException">if the pattern is invalid.</exception>
 /// <stable>ICU 3.8</stable>
 public PluralFormat(PluralRules rules, string pattern)
 {
     Init(rules, PluralType.Cardinal, ULocale.GetDefault(ULocale.Category.FORMAT), null);
     ApplyPattern(pattern);
 }