Esempio n. 1
0
        /// <summary>
        /// Returns the functionally equivalent locale.
        /// </summary>
#pragma warning disable 672
        public override ULocale GetFunctionalEquivalent(ULocale locale, bool[] isAvailable)
#pragma warning restore 672
        {
            if (isAvailable != null && isAvailable.Length > 0)
            {
                string localeId = ULocale.Canonicalize(locale.GetBaseName());
                IDictionary <string, string> idMap = GetLocaleIdToRulesIdMap(PluralType.Cardinal);
                isAvailable[0] = idMap.ContainsKey(localeId);
            }

            string rulesId = GetRulesIdForLocale(locale, PluralType.Cardinal);

            if (rulesId == null || rulesId.Trim().Length == 0)
            {
                return(ULocale.ROOT); // ultimate fallback
            }

            ULocale result;

            GetRulesIdToEquivalentULocaleMap().TryGetValue(rulesId, out result);
            if (result == null)
            {
                return(ULocale.ROOT); // ultimate fallback
            }

            return(result);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the rulesId from the locale,with locale fallback. If there is no
        /// rulesId, return null. The rulesId might be the empty string if the rule
        /// is the default rule.
        /// </summary>
        public virtual string GetRulesIdForLocale(ULocale locale, PluralType type)
        {
            IDictionary <string, string> idMap = GetLocaleIdToRulesIdMap(type);
            string localeId = ULocale.Canonicalize(locale.GetBaseName());
            string rulesId  = null;

            while (!idMap.TryGetValue(localeId, out rulesId) || null == rulesId)
            {
                int ix = localeId.LastIndexOf('_');
                if (ix == -1)
                {
                    break;
                }
                localeId = localeId.Substring(0, ix); // ICU4N: Checked 2nd substring arg
            }
            return(rulesId);
        }
Esempio n. 3
0
#pragma warning restore 612, 618

#pragma warning disable 1591 // No doc comments available
#pragma warning disable 612, 618
        public virtual PluralRanges GetPluralRanges(ULocale locale)
#pragma warning restore 612, 618
        {
            // TODO markdavis Fix the bad fallback, here and elsewhere in this file.
            string localeId = ULocale.Canonicalize(locale.GetBaseName());

#pragma warning disable 612, 618
            PluralRanges result;
#pragma warning restore 612, 618
            while (!localeIdToPluralRanges.TryGetValue(localeId, out result) || null == result)
            {
                int ix = localeId.LastIndexOf('_');
                if (ix == -1)
                {
                    result = UnknownRange;
                    break;
                }
                localeId = localeId.Substring(0, ix); // ICU4N: Checked 2nd arg
            }
            return(result);
        }
Esempio n. 4
0
        public void TestGetWithFallback()
        {
            /*
             * UResourceBundle bundle =(UResourceBundle) UResourceBundle.getBundleInstance("com/ibm/icu/dev/data/testdata","te_IN");
             * String key = bundle.getStringWithFallback("Keys/collation");
             * if(!key.equals("COLLATION")){
             *  Errln("Did not get the expected result from getStringWithFallback method.");
             * }
             * String type = bundle.getStringWithFallback("Types/collation/direct");
             * if(!type.equals("DIRECT")){
             *  Errln("Did not get the expected result form getStringWithFallback method.");
             * }
             */
            ICUResourceBundle bundle = null;
            String            key    = null;

            try
            {
                bundle = (ICUResourceBundle)UResourceBundle.GetBundleInstance(ICUData.IcuCollationBaseName, ULocale.Canonicalize("de__PHONEBOOK"));

                if (!bundle.GetULocale().GetName().Equals("de"))
                {
                    Errln("did not get the expected bundle");
                }
                key = bundle.GetStringWithFallback("collations/collation/default");
                if (!key.Equals("phonebook"))
                {
                    Errln("Did not get the expected result from getStringWithFallback method.");
                }
            }
            catch (MissingManifestResourceException ex)
            {
                Logln("got the expected exception");
            }


            bundle = (ICUResourceBundle)UResourceBundle.GetBundleInstance(ICUData.IcuCollationBaseName, "fr_FR");
            key    = bundle.GetStringWithFallback("collations/default");
            if (!key.Equals("standard"))
            {
                Errln("Did not get the expected result from getStringWithFallback method.");
            }
        }