Esempio n. 1
0
        private static string GetHourFormat(string locale)
        {
            XElement hourFormat = timeZones.XPathSelectElement(String.Format("/root/timeZoneNames[@locale = '{0}']/hourFormat", locale));

            if (hourFormat != null)
            {
                return(hourFormat.Value);
            }
            return(CldrUtility.GetParentPatterns(locale, GetHourFormat));
        }
Esempio n. 2
0
        public static CldrRelativeTimeFormat Resolve(string locale, string type)
        {
            string key = locale + "/" + type;

            if (resolvedPatterns.TryGetValue(key, out CldrRelativeTimeFormat cached))
            {
                return(cached);
            }
            CldrRelativeTimeFormat formatter = new CldrRelativeTimeFormat(locale, type);
            XElement field = xDocument.XPathSelectElement(String.Format("/root/fields[@locale = '{0}']/field[@type = '{1}']", locale, type));

            if (field == null)
            {
                throw new InvalidOperationException("Unknown locale or type");
            }
            if (CldrUtility.IsAlias(field, out string use))
            {
                return(resolvedPatterns.GetOrAdd(key, Resolve(locale, use)));
            }
            bool hasInheritedValues = field.Attribute("inherits") != null;

            foreach (XElement relative in field.Elements("relative"))
            {
                int amount = Int32.Parse(relative.Attribute("type").Value);
                formatter.relative[amount] = FormattedString.Parse(relative.Value);
            }
            foreach (XElement relativeTime in field.Elements("relativeTime"))
            {
                Dictionary <PluralCategories, FormattedString> dict = relativeTime.Attribute("type").Value == "future" ? formatter.future : formatter.past;
                foreach (XElement child in relativeTime.Elements())
                {
                    PluralCategories category = IntlProviderOptions.ParseEnum <PluralCategories>(child.Attribute("count").Value);
                    dict[category] = FormattedString.Parse(child.Value);
                }
                hasInheritedValues |= relativeTime.Attribute("inherits") != null;
            }
            if (hasInheritedValues)
            {
                CldrRelativeTimeFormat parent = CldrUtility.GetParentPatterns(locale, type, Resolve);
                CldrUtility.CopyPatternFromParent(formatter.relative, parent.relative);
                CldrUtility.CopyPatternFromParent(formatter.future, parent.future);
                CldrUtility.CopyPatternFromParent(formatter.past, parent.past);
            }
            return(resolvedPatterns.GetOrAdd(key, formatter));
        }
Esempio n. 3
0
        private static string GetMetaZoneName(string locale, string metaZone, TimeZoneNameStyle style, bool isDaylightSaving)
        {
            XElement metazoneNames = timeZones.XPathSelectElement(String.Format("/root/timeZoneNames[@locale = '{0}']/*[(local-name() = 'metazone' or local-name() = 'zone') and @type = '{1}']", locale, metaZone));

            if (metazoneNames != null)
            {
                if (style == TimeZoneNameStyle.Short)
                {
                    metazoneNames = metazoneNames.Element("short") ?? metazoneNames.Element("long");
                }
                else
                {
                    metazoneNames = metazoneNames.Element("long");
                }
                XElement name = metazoneNames.Element(isDaylightSaving ? "daylight" : "standard");
                if (name != null)
                {
                    return(name.Value);
                }
            }
            return(CldrUtility.GetParentPatterns(locale, s => GetMetaZoneName(s, metaZone, style, isDaylightSaving)));
        }