protected override void InitInternal(ICollection <string> locales, PluralRulesOptions options) { LocaleMatcher matcher = options.LocaleMatcher; this.Type = options.Type; this.Digits = options.Digits; this.Locale = ResolveLocale(locales, matcher); this.resolver = CldrPluralRules.Resolve(this.Type, this.Locale); this.PluralCategories = resolver.PluralCategories; }
protected override void InitInternal(ICollection <string> locales, NumberFormatOptions options) { Hashtable ht = new Hashtable(); LocaleMatcher localeMatcher = options.LocaleMatcher; ht["nu"] = options.NumberingSystem; this.Locale = ResolveLocale(locales, localeMatcher, relevantExtensionKeys, ht, out ht); this.NumberingSystem = (string)ht["nu"]; this.Style = options.Style; string currency = options.Currency; if (currency != null) { if (!IntlUtility.IsWellFormedCurrencyCode(currency)) { throw new EcmaRangeErrorException("Invalid currency codes: {0}", currency); } this.Currency = currency; } this.CurrencyDisplay = options.CurrencyDisplay; this.CurrencySign = options.CurrencySign; this.Unit = options.Unit; if (this.Unit != null) { if (!IntlUtility.IsWellFormedUnitIdentifier(this.Unit)) { throw new EcmaRangeErrorException("Invalid unit identifier: {0}", this.Unit); } } this.UnitDisplay = options.UnitDisplay; NumberFormatInfo numberFormat = CultureInfo.GetCultureInfo(this.Locale).NumberFormat; int defaultMinFractionDigits, defaultMaxFractionDigits; if (this.Style == NumberStyle.Currency) { if (currency == null) { throw new EcmaTypeErrorException("Currency code is required with currency style"); } defaultMinFractionDigits = numberFormat.CurrencyDecimalDigits; defaultMaxFractionDigits = numberFormat.CurrencyDecimalDigits; } else { if (this.Style == NumberStyle.Unit && this.Unit == null) { throw new EcmaTypeErrorException("Unit is required with unit style"); } defaultMinFractionDigits = 0; defaultMaxFractionDigits = this.Style == NumberStyle.Percent ? 0 : 3; } this.Notation = options.Notation; this.Digits = options.GetNumberFormatDigitOptions(defaultMinFractionDigits, defaultMaxFractionDigits, this.Notation); NumberCompactDisplayFormat compactDisplay = options.CompactDisplay; if (this.Notation == NumberNotation.Compact) { this.CompactDisplay = compactDisplay; } this.UseGrouping = options.UseGrouping; this.SignDisplay = options.SignDisplay; this.BoundFormat = Literal.FunctionLiteral(this.FormatInternal); this.formatProvider = CldrNumberFormat.GetFormat(this.Locale, this.NumberingSystem); this.pluralRules = CldrPluralRules.Resolve(PluralRuleType.Cardinal, this.Locale); NumberFormatInfo formatter = formatProvider.FormatProvider; this.symbolType = new Dictionary <string, FormattedPartType> { [formatter.PositiveSign] = FormattedPartType.PlusSign, [formatter.NegativeSign] = FormattedPartType.MinusSign, [formatter.NumberGroupSeparator] = FormattedPartType.Group, [formatter.NumberDecimalSeparator] = FormattedPartType.Decimal, [formatter.PercentSymbol] = FormattedPartType.PercentSign, ["E"] = FormattedPartType.ExponentSeparator }; this.styleFormats = GetStyleFormat().ToDictionary(v => v.Key, v => v.Value); if (this.Notation == NumberNotation.Compact) { this.compactNotations = formatProvider.GetCompactNotationFormats(this.CompactDisplay); } else if (this.Notation == NumberNotation.Scientific) { this.notationFormats = formatProvider.GetScientificNotationFormat().ToDisplayFormat(this); } else { this.notationFormats = formatProvider.GetDecimalNotationFormat().ToDisplayFormat(this); } }