private PluralFormatInfo.PluralRuleDelegate GetPluralRule(IFormatProvider provider)
        {
            // Let's retirm the correct Plural Rule to use:
            PluralFormatInfo pluralFormatInfo = null;

            // See if a custom PluralFormatInfo is available from the FormatProvider:
            if (provider != null)
            {
                pluralFormatInfo = (PluralFormatInfo)provider.GetFormat(typeof(PluralFormatInfo));
            }

            // If no custom PluralFormatInfo, let's use our default:
            if (pluralFormatInfo == null)
            {
                pluralFormatInfo = defaultPluralFormatInfo;
            }

            // Only continue if we have a PluralFormatInfo:
            if (pluralFormatInfo == null)
            {
                return(null);
            }


            // Get the culture, only if it was provided:
            var cultureInfo = provider as CultureInfo;

            // Retrieve the plural rule from the PluralFormatInfo:
            return(pluralFormatInfo.GetPluralRule(cultureInfo));
        }
Пример #2
0
 private static string getValue(PluralFormatInfo.PluralRuleDelegate pluralRule, int value, string[] units)
 {
     // Get the plural index from the plural rule,
     // unless there's only 1 unit in the first place:
     var pluralIndex = (units.Length == 1) ? 0 : pluralRule(value, units.Length);
     return string.Format(units[pluralIndex], value);
 }
Пример #3
0
        public TimeTextInfo(PluralFormatInfo.PluralRuleDelegate pluralRule, string[] week, string[] day, string[] hour, string[] minute, string[] second, string[] millisecond, string[] w, string[] d, string[] h, string[] m, string[] s, string[] ms, string lessThan)
        {
            this.PluralRule = pluralRule;
            
            this.week = week;
            this.day = day;
            this.hour = hour;
            this.minute = minute;
            this.second = second;
            this.millisecond = millisecond;

            this.w = w;
            this.d = d;
            this.h = h;
            this.m = m;
            this.s = s;
            this.ms = ms;

            this.lessThan = lessThan;
        }
 /// <summary>
 /// Initializes the plugin with a custom default rule provider.
 /// </summary>
 /// <param name="defaultPluralFormatInfo"></param>
 public PluralLocalizationFormatter(PluralFormatInfo defaultPluralFormatInfo)
 {
     this.defaultPluralFormatInfo = defaultPluralFormatInfo;
 }
 /// <summary>
 /// Initializes the plugin with rules for many common languages.
 /// If no CultureInfo is supplied to the formatter, the
 /// default language rules will be used by default.
 /// </summary>
 public PluralLocalizationFormatter(string defaultTwoLetterISOLanguageName)
 {
     this.defaultPluralFormatInfo = new CommonLanguagesPluralFormatInfo(defaultTwoLetterISOLanguageName);
 }
 /// <summary>
 /// Initializes the plugin with a custom default rule provider.
 /// </summary>
 /// <param name="defaultPluralFormatInfo"></param>
 public PluralLocalizationFormatter(PluralFormatInfo defaultPluralFormatInfo)
 {
     this.defaultPluralFormatInfo = defaultPluralFormatInfo;
 }
 /// <summary>
 /// Initializes the plugin with rules for many common languages.
 /// If no CultureInfo is supplied to the formatter, the
 /// default language rules will be used by default.
 /// </summary>
 public PluralLocalizationFormatter(string defaultTwoLetterISOLanguageName)
 {
     this.defaultPluralFormatInfo = new CommonLanguagesPluralFormatInfo(defaultTwoLetterISOLanguageName);
 }