示例#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);
         }
     }
 }
示例#2
0
 private string getLength(JobOfferDOM offer)
 {
     if (OfferType == JobOfferTypeEnum.Normal)
     {
         return(" - ");
     }
     return(string.Format("{0} day{1}", offer.Length, PluralHelper.S(offer.Length)));
 }
示例#3
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) : "");
        }
        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 ?? "");
        }
示例#5
0
        public MethodResult <string> UseEquipmentItem(EquipmentItem item, Entity entity)
        {
            switch (item.GetProductType())
            {
            case ProductTypeEnum.Tea:
            {
                var hpHealed = productService.GetTeaHealedAmount(item.Quality);
                var prevHp   = entity.Citizen.HitPoints;

                entity.Citizen.HitPoints = Math.Min(100, prevHp + hpHealed);
                entity.Citizen.DrankTeas++;

                equipmentRepository.RemoveEquipmentItem(item.EquipmentID, item.ProductID, item.Quality);
                equipmentRepository.SaveChanges();

                hpHealed = entity.Citizen.HitPoints - prevHp;
                return($"You drank tea and healed {hpHealed} hitpoint{PluralHelper.S(hpHealed)}.");
            }

            default:
                throw new Exception("No action defined for " + EquipmentItemExtension.GetProductType(item).ToString());
            }
        }
示例#6
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 ?? "");
        }
示例#7
0
        public void ReceiveRessistanceHeroMedal(Citizen citizen, War war, int battleWonCount, double goldAmount)
        {
            using (var trs = transactionScopeProvider.CreateTransactionScope())
            {
                citizen.RessistanceHeroMedals += 1;


                var warLink = WarLinkCreator.Create(war);
                using (NoSaveChanges)
                    warningService.AddWarning(citizen.ID, $"{warLink} has been won and you received {goldAmount} gold for winning {battleWonCount} battle{PluralHelper.S(battleWonCount)}.");

                ReceiveGoldForMedal(citizen, amount: goldAmount, medalName: "Battle hero");

                trs?.Complete();
            }
        }
示例#8
0
 private string prepareRoomDescription(IEnumerable <HotelRoomInfo> infos)
 {
     return(string.Join(", ",
                        infos.OrderBy(i => i.Quality)
                        .Select(i => $"{i.Count} room{PluralHelper.S(i.Count)} Q{i.Quality}")));
 }
示例#9
0
        public virtual void InformCompanyAboutOfferRemovedDueToMinimalWage(JobOffer offer, int count)
        {
            var message = $"Your offer{PluralHelper.S(count)} {PluralHelper.Else(count, "was", "were")} deleted due to minimal wage change in country.";

            warningService.AddWarning(offer.CompanyID, message);
        }