Exemplo n.º 1
0
        internal static NumberingSystem LookupInstanceByLocale(LocaleLookupData localeLookupData)
        {
            ULocale           locale = localeLookupData.locale;
            ICUResourceBundle rb;

            try
            {
                rb = (ICUResourceBundle)UResourceBundle.GetBundleInstance(ICUData.IcuBaseName, locale);
                rb = rb.GetWithFallback("NumberElements");
            }
            catch (MissingManifestResourceException)
            {
                return(new NumberingSystem());
            }

            string numbersKeyword          = localeLookupData.numbersKeyword;
            string resolvedNumberingSystem = null;

            for (; ;)
            {
                try
                {
                    resolvedNumberingSystem = rb.GetStringWithFallback(numbersKeyword);
                    break;
                }
                catch (MissingManifestResourceException)
                { // Fall back behavior as defined in TR35
                    if (numbersKeyword.Equals("native") || numbersKeyword.Equals("finance"))
                    {
                        numbersKeyword = "default";
                    }
                    else if (numbersKeyword.Equals("traditional"))
                    {
                        numbersKeyword = "native";
                    }
                    else
                    {
                        break;
                    }
                }
            }

            NumberingSystem ns = null;

            if (resolvedNumberingSystem != null)
            {
                ns = GetInstanceByName(resolvedNumberingSystem);
            }

            if (ns == null)
            {
                ns = new NumberingSystem();
            }
            return(ns);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns the default numbering system for the specified <see cref="ULocale"/>.
        /// </summary>
        /// <stable>ICU 4.2</stable>
        public static NumberingSystem GetInstance(ULocale locale)
        {
            // Check for @numbers
            bool   nsResolved     = true;
            string numbersKeyword = locale.GetKeywordValue("numbers");

            if (numbersKeyword != null)
            {
                foreach (string keyword in OTHER_NS_KEYWORDS)
                {
                    if (numbersKeyword.Equals(keyword))
                    {
                        nsResolved = false;
                        break;
                    }
                }
            }
            else
            {
                numbersKeyword = "default";
                nsResolved     = false;
            }

            if (nsResolved)
            {
                NumberingSystem ns = GetInstanceByName(numbersKeyword);
                if (ns != null)
                {
                    return(ns);
                }
                // If the @numbers keyword points to a bogus numbering system name,
                // we return the default for the locale.
                numbersKeyword = "default";
            }

            // Attempt to get the numbering system from the cache
            string baseName = locale.GetBaseName();
            // TODO: Caching by locale+numbersKeyword could yield a large cache.
            // Try to load for each locale the mappings from OTHER_NS_KEYWORDS and default
            // to real numbering system names; can we get those from supplemental data?
            // Then look up those mappings for the locale and resolve the keyword.
            string           key = baseName + "@numbers=" + numbersKeyword;
            LocaleLookupData localeLookupData = new LocaleLookupData(locale, numbersKeyword);

            return(cachedLocaleData.GetOrCreate(key, (k) => LookupInstanceByLocale(localeLookupData)));
        }