Esempio n. 1
0
        public static string GetDefaultLanguage(string territory)
        {
            Guard.ArgumentNotNull(territory, "territory");
            XDocument supplementalData   = LoadXml("Codeless.Ecma.Intl.Data.supplementalData.xml.gz");
            XElement  languagePopulation = supplementalData.XPathSelectElements(String.Format("/supplementalData/territoryInfo/territory[@type = '{0}']/languagePopulation", territory)).FirstOrDefault();

            if (languagePopulation == null)
            {
                throw new ArgumentOutOfRangeException("territoryCode");
            }
            return(IntlUtility.CanonicalizeLanguageTag(languagePopulation.Attribute("type").Value));
        }
Esempio n. 2
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));
            }));
        }