Exemplo n.º 1
0
        public static CldrPluralRules Resolve(PluralRuleType type, string locale)
        {
            string normalizedLocale = IntlUtility.RemoveUnicodeExtensions(locale);
            ConcurrentDictionary <string, CldrPluralRules> cache = type == PluralRuleType.Cardinal ? cardinalRules : ordinalRules;

            return(cache.GetOrAdd(normalizedLocale, _ => {
                XDocument doc = CldrUtility.LoadXml(type == PluralRuleType.Cardinal ? CardinalFileName : OrdinalFileName);
                foreach (XElement node in doc.XPathSelectElements(Xpath))
                {
                    string[] locales = node.Attribute("locales").Value.Split(' ');
                    if (locales.Contains(normalizedLocale))
                    {
                        CldrPluralRules rule = new CldrPluralRules(node);
                        foreach (string v in locales)
                        {
                            cache.TryAdd(v, rule);
                        }
                        return rule;
                    }
                }
                return Resolve(type, CldrUtility.GetParentLocale(normalizedLocale));
            }));
        }