Пример #1
0
        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
 /// <summary>
 /// Initializes the plugin with a custom default rule provider.
 /// </summary>
 /// <param name="defaultPluralFormatInfo"></param>
 public PluralLocalizationFormatter(PluralFormatInfo defaultPluralFormatInfo)
 {
     this.defaultPluralFormatInfo = defaultPluralFormatInfo;
 }
Пример #3
0
 /// <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);
 }