private static NumberingSystemType[] GetNumberingSystems() { if (options != null && !options.IncludeNumberingSystems) { return(null); } XDocument document = GetXmlDocument(@"common\supplemental\numberingSystems.xml"); IEnumerable <XElement> ldmlElements = document.Elements("supplementalData"); List <XElement> numberingSystemDatas = (from item in ldmlElements.Elements("numberingSystems") .Elements("numberingSystem") select item).ToList(); if (numberingSystemDatas != null && numberingSystemDatas.Count > 0) { List <NumberingSystemType> numberingSystems = new List <NumberingSystemType>(); foreach (XElement data in numberingSystemDatas) { string id = data.Attribute("id").Value.ToString(); Progress("Adding numbering system", id); NumberingSystemType numberingSystem = new NumberingSystemType(); numberingSystem.Id = id; numberingSystem.DigitsOrRules = GetNumberingSystemType(data.Attribute("type").Value.ToString()); if (data.Attribute("rules") != null) { numberingSystem.Rules = data.Attribute("rules").Value.ToString(); } if (data.Attribute("digits") != null) { numberingSystem.Digits = data.Attribute("digits").Value.ToString(); } numberingSystems.Add(numberingSystem); Progress("Added numbering system", id, ProgressEventType.Added, numberingSystem); } UpdateDescriptions(numberingSystems); return(numberingSystems.ToArray()); } return(null); }
/// <summary> /// CreateNumberFormatInfo creates a .NET NumberFormatInfo for the CLDR Culture /// </summary> /// <param name="culture">The Culture to get the NumberFormatInfo for</param> /// <returns>A .NET NumberFormatInfo for the CLDR Culture</returns> private static NumberFormatInfo CreateNumberFormatInfo(Culture culture) { if (culture.Numbers == null) { return(null); } NumberFormatInfo numberFormatInfo = new NumberFormatInfo(); if (culture.Numbers.CurrentCurrencyPeriod != null) { string currencyId = culture.Numbers.CurrentCurrencyPeriod.Id; CurrencyFraction currencyFraction = NCldr.GetCurrencyFraction(currencyId); if (currencyFraction != null) { numberFormatInfo.CurrencyDecimalDigits = currencyFraction.Digits; } } if (culture.Numbers.DefaultNumberingSystem != null && culture.Numbers.DefaultNumberingSystem.Symbols != null) { NumberingSystem numberingSystem = culture.Numbers.DefaultNumberingSystem; NumberingSystemSymbols symbols = numberingSystem.Symbols; NumberingSystemType numberingSystemType = numberingSystem.NumberingSystemType; CurrencyPeriod currentCurrencyPeriod = culture.Numbers.CurrentCurrencyPeriod; if (!string.IsNullOrEmpty(symbols.Nan)) { numberFormatInfo.NaNSymbol = symbols.Nan; } if (!string.IsNullOrEmpty(symbols.Infinity)) { string minusSign = "-"; if (!string.IsNullOrEmpty(symbols.MinusSign)) { minusSign = symbols.MinusSign; } numberFormatInfo.NegativeInfinitySymbol = minusSign + symbols.Infinity; } if (!string.IsNullOrEmpty(symbols.MinusSign)) { numberFormatInfo.NegativeSign = symbols.MinusSign; } if (!string.IsNullOrEmpty(symbols.Infinity)) { numberFormatInfo.PositiveInfinitySymbol = symbols.Infinity; } if (!string.IsNullOrEmpty(symbols.PercentSign)) { numberFormatInfo.PercentSymbol = symbols.PercentSign; } if (!string.IsNullOrEmpty(symbols.PerMille)) { numberFormatInfo.PerMilleSymbol = symbols.PerMille; } if (!string.IsNullOrEmpty(symbols.PlusSign)) { numberFormatInfo.PositiveSign = symbols.PlusSign; } if (!string.IsNullOrEmpty(symbols.Decimal)) { numberFormatInfo.CurrencyDecimalSeparator = symbols.Decimal; numberFormatInfo.NumberDecimalSeparator = symbols.Decimal; numberFormatInfo.PercentDecimalSeparator = symbols.Decimal; } if (!string.IsNullOrEmpty(symbols.Group)) { numberFormatInfo.CurrencyGroupSeparator = symbols.Group; numberFormatInfo.NumberGroupSeparator = symbols.Group; numberFormatInfo.PercentGroupSeparator = symbols.Group; } if (numberingSystemType != null && numberingSystemType.DigitsOrRules == NumberingSystemDigitsOrRules.Numeric) { numberFormatInfo.NativeDigits = numberingSystemType.DigitsArray; } if (currentCurrencyPeriod != null) { CurrencyDisplayNameSet currencyDisplayNameSet = (from cdns in culture.Numbers.CurrencyDisplayNameSets where string.Compare(cdns.Id, currentCurrencyPeriod.Id, StringComparison.InvariantCulture) == 0 select cdns).FirstOrDefault(); if (currencyDisplayNameSet != null && !string.IsNullOrEmpty(currencyDisplayNameSet.Symbol)) { numberFormatInfo.CurrencySymbol = currencyDisplayNameSet.Symbol; } } if (numberingSystemType == null) { numberFormatInfo.DigitSubstitution = DigitShapes.None; } else { numberFormatInfo.DigitSubstitution = numberingSystemType.DigitShapes; } if (!string.IsNullOrEmpty(numberingSystem.CurrencyFormatPattern)) { numberFormatInfo.CurrencyPositivePattern = numberingSystem.CurrencyPositivePattern; numberFormatInfo.CurrencyNegativePattern = numberingSystem.CurrencyNegativePattern; numberFormatInfo.CurrencyGroupSizes = numberingSystem.CurrencyGroupSizes; } if (!string.IsNullOrEmpty(numberingSystem.PercentFormatPattern)) { numberFormatInfo.PercentDecimalDigits = numberingSystem.PercentDecimalDigits; numberFormatInfo.PercentGroupSizes = numberingSystem.PercentGroupSizes; numberFormatInfo.PercentNegativePattern = numberingSystem.PercentNegativePattern; numberFormatInfo.PercentPositivePattern = numberingSystem.PercentPositivePattern; } if (!string.IsNullOrEmpty(numberingSystem.DecimalFormatPattern)) { numberFormatInfo.NumberDecimalDigits = numberingSystem.NumberDecimalDigits; numberFormatInfo.NumberGroupSizes = numberingSystem.NumberGroupSizes; numberFormatInfo.NumberNegativePattern = numberingSystem.NumberNegativePattern; } } return(numberFormatInfo); }