コード例 #1
0
        public PluralForm [] SelectPluralForms(IFormatProvider provider, FormatString formatString, object [] arguments)
        {
            var selection = new PluralForm [arguments.Length];
            var length    = Math.Min(formatString.Arguments.Length,
                                     arguments.Length);

            for (var index = 0; index < length; index++)
            {
                var argument = formatString.Arguments [index];
                if (argument.NumberArgumentHole == null)
                {
                    continue;
                }

                var number = FormattedNumber.Parse(provider ?? Culture, argument.NumberArgumentHole, arguments [index]);
                if (number == null)
                {
                    continue;
                }

                var numberForm = CardinalForm;
                if (argument.NumberForm == NumberForm.Ordinal)
                {
                    numberForm = OrdinalForm;
                }

                selection [index] = numberForm.SelectPluralForm(number.Value, argument.AvailablePluralForms);
            }

            return(selection);
        }
コード例 #2
0
        public override PluralForm SelectPluralForm(decimal number, PluralForm availablePluralForms)
        {
            if (availablePluralForms.HasBitMask(PluralForm.ExplicitZero))
            {
                if (ExplicitZeroRule.AppliesTo(number))
                {
                    return(ExplicitZeroRule.PluralForm);
                }
            }
            else if (!hasZeroForm && availablePluralForms.HasBitMask(PluralForm.Zero))
            {
                if (ExplicitZeroRule.AppliesTo(number))
                {
                    return(PluralForm.Zero);
                }
            }

            if (availablePluralForms.HasBitMask(PluralForm.ExplicitOne))
            {
                if (ExplicitOneRule.AppliesTo(number))
                {
                    return(ExplicitOneRule.PluralForm);
                }
            }
            else if (!hasOneForm && availablePluralForms.HasBitMask(PluralForm.One))
            {
                if (ExplicitOneRule.AppliesTo(number))
                {
                    return(PluralForm.One);
                }
            }

            return(base.SelectPluralForm(number, availablePluralForms));
        }
コード例 #3
0
        void OnGUI()
        {
            GUILayout.Label("How many apples do you have?");
            int.TryParse(GUILayout.TextField(numberOfApples.ToString(), GUILayout.Width(100)), out numberOfApples);

            var pluralForm = PluralForm.GetPluralForm(localeCode);

            if (pluralForm != null)
            {
                // NumberOfPlurals is the number of possible plural forms a language can contain. In English we would expect 2.
                if (pluralForm.NumberOfPlurals != pluralVersions.Length)
                {
                    GUILayout.Label(string.Format("Incorrect number of plurals in pluralVersions. Expected {0} but found {1}", pluralForm.NumberOfPlurals, pluralVersions.Length));
                    return;
                }

                // Evaluate the value to determine which plural we should use
                int pluralToUse = pluralForm.Evaluate(numberOfApples);

                // Now use the plural form and pass in the value as am argument so it can be added to the string.
                GUILayout.Label(string.Format(pluralVersions[pluralToUse], numberOfApples));
            }
            else
            {
                GUILayout.Label("Could not find a plural form for code: " + localeCode);
            }
        }
コード例 #4
0
        protected static int DeleteAll(Type t, ICollection pks)
        {
            const string CouldNotDeleteMessage =
                "Não foi possível excluir o[:s] registro[:s] selecionado[:s].\n" +
                "Verifique se esse[:s] registro[:s] est[á:ão] relacionado[:s] " +
                "a outro[:s] dado[:s] do sistema.";

            try
            {
                return(ActiveRecordBase.DeleteAll(t, pks));
            }
            catch (TargetInvocationException ex)
            {
                if (ex.InnerException is ActiveRecordException)
                {
                    throw new CouldNotDeleteException(PluralForm.Format(pks.Count, CouldNotDeleteMessage), ex);
                }

                throw;
            }
            catch (ActiveRecordException ex)
            {
                throw new CouldNotDeleteException(PluralForm.Format(pks.Count, CouldNotDeleteMessage), ex);
            }
#if !DO_NOT_USE_CUSTOM_MESSAGES
            catch (CouldNotDeleteException ex)
            {
                throw new CouldNotDeleteException(PluralForm.Format(pks.Count, CouldNotDeleteMessage), ex);
            }
#endif
        }
コード例 #5
0
        public void Test1()
        {
            var format = "[Só uma] vez";

            Assert.AreEqual("Só uma vez", PluralForm.Format(0, format));
            Assert.AreEqual("Só uma vez", PluralForm.Format(1, format));
            Assert.AreEqual("Só uma vez", PluralForm.Format(5, format));
        }
コード例 #6
0
        public void Test3()
        {
            var format = "[Só uma:Mais de uma:Nenhuma] vez";

            Assert.AreEqual("Nenhuma vez", PluralForm.Format(0, format));
            Assert.AreEqual("Só uma vez", PluralForm.Format(1, format));
            Assert.AreEqual("Mais de uma vez", PluralForm.Format(5, format));
        }
コード例 #7
0
        private static bool Matches(PluralForm availablePluralForms, PluralForm pluralForm)
        {
            if (pluralForm == PluralForm.Other)
            {
                return(availablePluralForms == PluralForm.Other);
            }

            return(availablePluralForms.HasBitMask(pluralForm));
        }
コード例 #8
0
        public override PluralForm SelectPluralForm(decimal number, PluralForm availablePluralForms)
        {
            foreach (var rule in rules)
            {
                if (rule.AppliesTo(number))
                {
                    return(rule.PluralForm & availablePluralForms);
                }
            }

            return(PluralRule.Default.PluralForm);
        }
コード例 #9
0
        public static TextObject GetCooldownText(Type decisionType, float elapsedDaysUntilNow)
        {
            int        RemainingDays = (int)Math.Ceiling(AOCooldownManager.GetRequiredDecisionCooldown(decisionType) - elapsedDaysUntilNow);
            PluralForm pluralForm    = GetPluralForm(RemainingDays);
            var        attributes    = new Dictionary <string, TextObject>()
            {
                [PLURAL_FORM_TAG] = new TextObject(pluralForm == PluralForm.Plural ? 1 : 0), [OTHER_PLURAL_FORM_TAG] = new TextObject(pluralForm != PluralForm.Singular ? 1 : 0)
            };

            return(new TextObject(DECISION_IS_ON_COOLDOWN,
                                  new Dictionary <string, TextObject>()
            {
                ["NUMBER_OF_DAYS"] = new TextObject(RemainingDays, attributes)
            }));
        }
コード例 #10
0
        public static void SetNumericVariable(TextObject textObject, string tag, float variableValue, string format = null)
        {
            if (string.IsNullOrEmpty(tag))
            {
                return;
            }
            PluralForm pluralForm = GetPluralForm(variableValue);
            var        attributes = new Dictionary <string, TextObject>()
            {
                [PLURAL_FORM_TAG] = new TextObject(pluralForm == PluralForm.Plural ? 1 : 0), [OTHER_PLURAL_FORM_TAG] = new TextObject(pluralForm != PluralForm.Singular ? 1 : 0)
            };
            TextObject explainedTextObject = string.IsNullOrEmpty(format) ? new TextObject(variableValue, attributes) : new TextObject(variableValue.ToString(format), attributes);

            if (textObject is null)
            {
                MBTextManager.SetTextVariable(tag, explainedTextObject);
            }
            else
            {
                textObject.SetTextVariable(tag, explainedTextObject);
            }
        }
コード例 #11
0
        public static string TryParse(string text, out PluralForm count)
        {
            const string Count = "count-";
            int          idx   = text.IndexOf(Count, StringComparison.OrdinalIgnoreCase);

            if (idx >= 0)
            {
                int    last = text.IndexOf('-', idx + Count.Length);
                string ptext;
                if (last >= 0)
                {
                    ptext = text.Substring(idx + Count.Length, last - idx + Count.Length);
                }
                else
                {
                    ptext = text.Substring(idx + Count.Length);
                }
                if (Enum.TryParse(ptext, true, out count))
                {
                    if (last >= 0)
                    {
                        ptext = text.Substring(last);
                    }
                    else
                    {
                        ptext = "";
                    }
                    if (idx > 0)
                    {
                        ptext = text.Substring(0, idx) + ptext;
                    }
                    return(ptext);
                }
            }
            count = 0;
            return(null);
        }
コード例 #12
0
        protected bool TryExtractPluralForm(ref string name, out PluralForm pluralForm, out NumberForm numberForm)
        {
            pluralForm = PluralForm.Other;
            numberForm = NumberForm.Cardinal;

            var match = (string)null;

            if (Match(name, zero, comparison))
            {
                match = zero;    pluralForm = PluralForm.Zero;
            }
            else if (Match(name, one, comparison))
            {
                match = one;     pluralForm = PluralForm.One;
            }
            else if (Match(name, two, comparison))
            {
                match = two;     pluralForm = PluralForm.Two;
            }
            else if (Match(name, few, comparison))
            {
                match = few;     pluralForm = PluralForm.Few;
            }
            else if (Match(name, many, comparison))
            {
                match = many;    pluralForm = PluralForm.Many;
            }
            else if (Match(name, other, comparison))
            {
                match = other;   pluralForm = PluralForm.Other;
            }
            else if (Match(name, explicitZero, comparison))
            {
                match = other;   pluralForm = PluralForm.ExplicitZero;
            }
            else if (Match(name, explicitOne, comparison))
            {
                match = other;   pluralForm = PluralForm.ExplicitOne;
            }
            else if (Match(name, discard, comparison))
            {
                match = discard; pluralForm = PluralForm.Other;
            }
            else
            {
                if (Match(name, ordinalZero, comparison))
                {
                    match = ordinalZero;  pluralForm = PluralForm.Zero;
                }
                else if (Match(name, ordinalOne, comparison))
                {
                    match = ordinalOne;   pluralForm = PluralForm.One;
                }
                else if (Match(name, ordinalTwo, comparison))
                {
                    match = ordinalTwo;   pluralForm = PluralForm.Two;
                }
                else if (Match(name, ordinalFew, comparison))
                {
                    match = ordinalFew;   pluralForm = PluralForm.Few;
                }
                else if (Match(name, ordinalMany, comparison))
                {
                    match = ordinalMany;  pluralForm = PluralForm.Many;
                }
                else if (Match(name, ordinalOther, comparison))
                {
                    match = ordinalOther; pluralForm = PluralForm.Other;
                }

                if (match != null)
                {
                    numberForm = NumberForm.Ordinal;
                }
            }

            if (match == null)
            {
                return(false);
            }

            name = Trim(name, match);

            return(true);
        }
コード例 #13
0
 public PluralRange(PluralForm start, PluralForm end, PluralForm result)
 {
     Start  = start;
     End    = end;
     Result = result;
 }
コード例 #14
0
 public PluralEntry(PluralForm type, string text)
 {
     Type = type;
     Text = text;
 }
コード例 #15
0
 public override PluralForm SelectPluralForm(PluralForm start, PluralForm end) => end;
コード例 #16
0
 public abstract PluralForm SelectPluralForm(PluralForm start, PluralForm end);
コード例 #17
0
 public static void ParseReturnsTheCorrectPluralForm(string count, string rule, PluralForm expectedPluralForm)
 {
     Assert.Equal(expectedPluralForm, PluralRule.Parse(count, rule, out _).PluralForm);
 }
コード例 #18
0
 /// <inheritdoc />
 public override bool IsNamed(string[] tokens)
 {
     return(SingularForm.SameAs(tokens) || PluralForm.SameAs(tokens));
 }
コード例 #19
0
        private static string PrintFlatRelations(Graph.Edge parent, int level, IEnumerable <Graph.Edge> relations, TiskEnum typ,
                                                 List <string> renderedIds, bool withStats = true, string highlightSubjId = null)
        {
            int    space     = 2;
            string horizLine = "--"; //new string('\u2500',2);
            string vertLine  = "|";  //new string('\u2502',1);
            string cross     = "+";  //new string('\u251C', 1);

            if (renderedIds == null)
            {
                renderedIds = new List <string>();
            }

            var rels = relations
                       .Where(m =>
                              (
                                  (parent != null && m.From?.UniqId == parent.To?.UniqId)
                                  ||
                                  (parent == null && !relations.Any(r => r.To?.UniqId == m.From?.UniqId)) //do root urovne pridej vazby, ktere jsou sirotci bez parenta
                              )
                              )
                       .Distinct()
                       .GroupBy(k => new { id = k.To.UniqId, type = k.To.Type }, (k, v) =>
            {
                Graph.Edge withChildren = v.Where(r => relations.Any(m => m.From?.UniqId == r.To?.UniqId)).FirstOrDefault();
                if (withChildren == null)
                {
                    withChildren = v.First();
                }

                return(withChildren);
            })
                       .OrderBy(m => m.To.PrintName(typ == TiskEnum.Html))
                       .ToArray();

            if (rels.Count() == 0)
            {
                return(string.Empty);
            }

            StringBuilder     sb       = new StringBuilder(512);
            List <Graph.Edge> deepRels = new List <Graph.Edge>();

            switch (typ)
            {
            case TiskEnum.Text:
                break;

            case TiskEnum.Html:
            case TiskEnum.Checkbox:
                sb.AppendLine("<ul>");
                break;

            case TiskEnum.Json:
                break;
            }
            for (int i = 0; i < rels.Count(); i++)
            {
                var rel = rels[i];
                if (renderedIds.Contains(rel.To.UniqId))
                {
                    continue;
                }

                var last = i == (rels.Count() - 1);
                Analysis.SubjectStatistic stat = null;
                if (withStats && rel.To.Type == Graph.Node.NodeType.Company)
                {
                    stat = new Analysis.SubjectStatistic(rel.To.Id);
                }
                string subjId   = rel.To.Type == Graph.Node.NodeType.Company ? rel.To.Id : "Osoba";
                string subjName = rel.To.PrintName();
                renderedIds.Add(rel.To.UniqId);
                switch (typ)
                {
                case TiskEnum.Text:
                    sb.AppendLine(string.Concat(Enumerable.Repeat(vertLine + new string(' ', space), level + 1)));
                    sb.Append(
                        string.Concat(
                            Enumerable.Repeat(
                                vertLine + new string(' ', space)
                                , (level))
                            )
                        );
                    if (rel.To.Highlighted)
                    {
                        subjName = string.Format("!!{0}!!", subjName);
                    }

                    sb.AppendFormat("{0}{1}:{2} {3}\n",
                                    cross + horizLine + " ",
                                    subjId,
                                    subjName,
                                    rel.Doba()
                                    );
                    sb.Append(PrintFlatRelations(rel, level + 1, relations, typ, renderedIds, withStats));
                    break;

                case TiskEnum.Html:
                    if (withStats && stat != null)
                    {
                        sb.AppendFormat("<li class='{3} {6}'><a href='/subjekt/{0}'>{0}:{1}</a>{7}; {4}, celkem {5}.   {2}</li>",
                                        subjId,
                                        subjName,
                                        PrintFlatRelations(rel, level + 1, relations, typ, renderedIds, withStats),
                                        last ? "" : "connect",
                                        PluralForm.Get((int)stat.BasicStatPerYear.Summary.Pocet, "{0} smlouva;{0} smlouvy;{0} smluv"),
                                        Smlouva.NicePrice(stat.BasicStatPerYear.Summary.CelkemCena, html: true, shortFormat: true),
                                        "aktualnost" + ((int)rel.Aktualnost).ToString(),
                                        (rel.Aktualnost < AktualnostType.Aktualni) ? rel.Doba("/{0}/") : string.Empty
                                        );
                    }
                    else
                    {
                        sb.AppendFormat("<li class='{3} {4}'><a href='/subjekt/{0}'><span class=''>{0}:{1}</span></a>{5}.  {2}</li>",
                                        subjId,
                                        subjName,
                                        PrintFlatRelations(rel, level + 1, relations, typ, renderedIds, withStats),
                                        last ? "" : "connect",
                                        "aktualnost" + ((int)rel.Aktualnost).ToString(),
                                        (rel.Aktualnost < AktualnostType.Aktualni) ? rel.Doba("/{0}/") : string.Empty,
                                        (!string.IsNullOrEmpty(highlightSubjId) && subjId == highlightSubjId) ? "highlighted" : ""
                                        );
                    }

                    break;

                case TiskEnum.Checkbox:
                    sb.AppendFormat(@"<li class=""{0} {1}""><input type=""checkbox"" name=""ico"" value=""{2}"" /> <span><b>{2}</b> {3}</span>{4}</li>"
                                    , (last ? "" : "connect"),
                                    ("aktualnost" + ((int)rel.Aktualnost).ToString()),
                                    subjId, subjName,
                                    PrintFlatRelations(rel, level + 1, relations, typ, renderedIds, withStats)
                                    );

                    break;

                case TiskEnum.Json:
                    break;
                }
            }
            switch (typ)
            {
            case TiskEnum.Text:
                break;

            case TiskEnum.Html:
            case TiskEnum.Checkbox:
                sb.AppendLine("</ul>");
                break;

            case TiskEnum.Json:
                break;
            }

            return(sb.ToString());
        }
コード例 #20
0
        public static void ArgumentHasCorrectStringRepresentation(int?index, int alignment, string format, int startOffset, int endOffset, NumberForm numberForm, PluralForm availablePluralForms, PluralForm?pluralRangeForm, string expectedString)
        {
            var argumentHole = index.HasValue ? new FormatString.ArgumentHole(index.Value, alignment, format, startOffset, endOffset) : null;
            var argument     = new FormatString.Argument(argumentHole, numberForm, availablePluralForms, pluralRangeForm);

            Assert.Equal(expectedString, argument.ToString( ));
        }
コード例 #21
0
 public abstract PluralForm SelectPluralForm(decimal number, PluralForm availablePluralForms);
コード例 #22
0
 public static bool HasBitMask(this PluralForm pluralForm, PluralForm bitMask)
 {
     return((pluralForm & bitMask) == bitMask);
 }
コード例 #23
0
 protected PluralFormSelector(PluralForm pluralForms)
 {
     PluralForms = pluralForms;
 }