Esempio n. 1
0
 private static void CreatePluralProvider(string forcedCultureName = null)
 {
     lock (_objLock)
     {
         if (_pluralProvider == null)
         {
             var cultureToUse = CultureInfo.CurrentUICulture.TwoLetterISOLanguageName;
             if (!string.IsNullOrEmpty(forcedCultureName))
             {
                 try
                 {
                     var forcedCulture = new CultureInfo(forcedCultureName)?.TwoLetterISOLanguageName;
                     if (!string.IsNullOrEmpty(forcedCulture))
                     {
                         cultureToUse = forcedCulture;
                     }
                 }
                 catch
                 {
                 }
             }
             _pluralProvider = PluralHelper.GetPluralChooser(cultureToUse);
         }
     }
 }
Esempio n. 2
0
        public static string Plural(this IViewLocalizer localizer, string key, int number)
        {
            var    provider         = PluralHelper.GetPluralChooser(CultureInfo.CurrentCulture);
            var    pluralType       = provider.ComputePlural(number);
            string selectedSentence = null;

            try
            {
                switch (pluralType)
                {
                case PluralTypeEnum.ZERO:
                    selectedSentence = localizer.GetString(key + "_Zero");
                    break;

                case PluralTypeEnum.ONE:
                    selectedSentence = localizer.GetString(key + "_One");
                    break;

                case PluralTypeEnum.OTHER:
                    selectedSentence = localizer.GetString(key + "_Other");
                    break;

                case PluralTypeEnum.TWO:
                    selectedSentence = localizer.GetString(key + "_Two");
                    break;

                case PluralTypeEnum.FEW:
                    selectedSentence = localizer.GetString(key + "_Few");
                    break;

                case PluralTypeEnum.MANY:
                    selectedSentence = localizer.GetString(key + "_Many");
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch
            {
                // ignored
            }
            return(selectedSentence != null?string.Format(selectedSentence, number) : "");
        }
Esempio n. 3
0
        public static string GetPlural(this ResourceManager resource, string key, decimal number)
#endif
        {
            if (_pluralProvider == null)
            {
                _pluralProvider = PluralHelper.GetPluralChooser(new CultureInfo(resource.GetString("ResourceLanguage")));
            }
            string selectedSentence = null;
            var    pluralType       = _pluralProvider.ComputePlural(number);

            try
            {
                switch (pluralType)
                {
                case PluralTypeEnum.ZERO:
                    selectedSentence = resource.GetString(key + "_Zero");
                    break;

                case PluralTypeEnum.ONE:
                    selectedSentence = resource.GetString(key + "_One");
                    break;

                case PluralTypeEnum.OTHER:
                    selectedSentence = resource.GetString(key + "_Other");
                    break;

                case PluralTypeEnum.TWO:
                    selectedSentence = resource.GetString(key + "_Two");
                    break;

                case PluralTypeEnum.FEW:
                    selectedSentence = resource.GetString(key + "_Few");
                    break;

                case PluralTypeEnum.MANY:
                    selectedSentence = resource.GetString(key + "_Many");
                    break;
                }
            }
            catch { }
            return(selectedSentence ?? "");
        }
Esempio n. 4
0
        public static string GetPlural(this ResourceManager resource, string key, decimal number)
#endif
        {
            if (_pluralProvider == null)
            {
                lock (_objLock)
                {
                    if (_pluralProvider == null)
                    {
                        CultureInfo cultureToUse  = null;
                        var         forcedCulture = resource.GetString("ResourceLanguage");
                        if (!string.IsNullOrEmpty(forcedCulture))
                        {
                            try
                            {
                                cultureToUse = new CultureInfo(forcedCulture);
                            }
                            catch
                            {
                                cultureToUse = new CultureInfo(CultureInfo.CurrentUICulture.Name);
                            }
                        }
                        else
                        {
                            cultureToUse = new CultureInfo(CultureInfo.CurrentUICulture.Name);
                        }

                        _pluralProvider = PluralHelper.GetPluralChooser(cultureToUse);
                    }
                }
            }
            string selectedSentence = null;
            var    pluralType       = _pluralProvider.ComputePlural(number);

            try
            {
                switch (pluralType)
                {
                case PluralTypeEnum.ZERO:
                    selectedSentence = resource.GetString(key + "_Zero");
                    break;

                case PluralTypeEnum.ONE:
                    selectedSentence = resource.GetString(key + "_One");
                    break;

                case PluralTypeEnum.OTHER:
                    selectedSentence = resource.GetString(key + "_Other");
                    break;

                case PluralTypeEnum.TWO:
                    selectedSentence = resource.GetString(key + "_Two");
                    break;

                case PluralTypeEnum.FEW:
                    selectedSentence = resource.GetString(key + "_Few");
                    break;

                case PluralTypeEnum.MANY:
                    selectedSentence = resource.GetString(key + "_Many");
                    break;
                }
            }
            catch { }
            return(selectedSentence ?? "");
        }