private ReadOnlyDictionary <PluralCategories, string> GetCurrencyName(string code, CurrencyDisplayFormat format) { if (format == CurrencyDisplayFormat.Code) { return(CreateSingleResult(code)); } XElement currencies = elements.FirstOrDefault(v => v.Name.LocalName == "currencies"); XElement symbol = currencies?.XPathSelectElement(String.Format("currency[@type = '{0}']/symbol[@alt = 'narrow']/symbol", code)); if (symbol == null) { return(locale == "root" ? CreateSingleResult(code) : this.Parent.GetCurrencyName(code, format)); } return(CreateSingleResult(symbol.Value)); }
public ReadOnlyDictionary <PluralCategories, NumberFormatPattern> GetCurrencyStyleFormat(string code, CurrencyDisplayFormat format, CurrencySignFormat sign) { Dictionary <PluralCategories, NumberFormatPattern> dict = new Dictionary <PluralCategories, NumberFormatPattern>(); NumberFormatPattern pattern = GetCurrencyStyleFormat(sign); FormattedString[] src = new[] { pattern.PositivePattern, pattern.NegativePattern, pattern.ZeroPattern }; FormattedString[] dst = new FormattedString[3]; foreach (KeyValuePair <PluralCategories, string> e in GetCurrencyName(code, format)) { Array.Clear(dst, 0, 3); for (int i = 0; i < 3; i++) { if (src[i] != dst[0]) { FormattedPart[] parts = src[i].GetParts(); int index = Array.FindIndex(parts, v => v.Type == FormattedPartType.Currency); parts[index] = new FormattedPart(FormattedPartType.Currency, e.Value); dst[i] = new FormattedString(parts); } } dict.Add(e.Key, new NumberFormatPattern(dst[0], dst[1] ?? dst[0], dst[2] ?? dst[0])); } return(new ReadOnlyDictionary <PluralCategories, NumberFormatPattern>(dict)); }