Example #1
0
        /// <summary>
        /// Returns the functionally equivalent locale.
        /// </summary>
#pragma warning disable 672
        public override UCultureInfo GetFunctionalEquivalent(UCultureInfo locale, bool[] isAvailable)
#pragma warning restore 672
        {
            if (isAvailable != null && isAvailable.Length > 0)
            {
                string localeId = UCultureInfo.Canonicalize(locale.Name);
                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(UCultureInfo.InvariantCulture); // ultimate fallback
            }

            UCultureInfo result;

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

            return(result);
        }
Example #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(UCultureInfo locale, PluralType type)
        {
            IDictionary <string, string> idMap = GetLocaleIdToRulesIdMap(type);
            string localeId = UCultureInfo.Canonicalize(locale.Name);
            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);
        }
Example #3
0
#pragma warning restore 612, 618

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

#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);
        }
Example #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, UCultureInfo.Canonicalize("de__PHONEBOOK"));

                if (!bundle.UCulture.FullName.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.");
            }
        }