/// <summary> /// GetCurrencyDisplayName gets the localized display name of a currency in a given language /// </summary> /// <param name="currencyName">The currency to get the localized display name for</param> /// <param name="languageId">The language in which to get the localized display name</param> /// <returns>The localized display name of a currency in a given language</returns> public static string GetCurrencyDisplayName(string currencyName, string languageId) { Culture culture = Culture.GetCulture(languageId); if (culture == null || culture.Numbers == null || culture.Numbers.CurrencyDisplayNameSets == null) { return(null); } CurrencyDisplayNameSet currencyDisplayNameSet = (from cdns in culture.Numbers.CurrencyDisplayNameSets where string.Compare(cdns.Id, currencyName, StringComparison.InvariantCulture) == 0 select cdns).FirstOrDefault(); if (currencyDisplayNameSet != null) { CurrencyDisplayName currencyDisplayName = (from cdn in currencyDisplayNameSet.CurrencyDisplayNames where cdn.Id == null select cdn).FirstOrDefault(); if (currencyDisplayName != null) { return(currencyDisplayName.Name); } } 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); }