|
ILIAS
trunk Revision v13.0_alpha-62-g3b72d83f2e5
|
The plural rule of a language, as declared by the "Plural-Forms" header of a gettext catalog (nplurals=<count>; plural=<C expression of n>;), and the one place deciding which plural form a message serves.
More...
Collaboration diagram for ILIAS\Language\ComponentTranslation\PluralForms:Public Member Functions | |
| getCount () | |
| getHeader () | |
| formIndexFor (int $n) | |
| The index of the form for the quantity $n. More... | |
| defaultFormIndex () | |
| The form serving a plural message where only one value can be used: the last one, msgstr[nplurals - 1]. More... | |
| defaultValueOf (array $forms) | |
| The value of the default form (see defaultFormIndex()) of a message with $forms (msgstr[0], ...); if that is missing or empty the closest non-empty form before it, '' if all are empty. More... | |
| selectsSameFormsAs (PluralForms $other) | |
| Whether $other has as many forms and selects the same form for every sampled n, e.g. More... | |
| previousFormsOf (PluralForms $previous) | |
| For every form of this rule, the forms of $previous serving the same quantities: $previous->formIndexFor(n) for every sampled n this rule serves with that form. More... | |
| isOneSingularOtherPlural () | |
| Whether the rule is "n == 1 -> form 0, every other n -> form 1" (English, German) for every sampled n. More... | |
Static Public Member Functions | |
| static | fromHeader (string $header) |
| static | fromHeaderOrGermanic (?string $header, ?callable $on_invalid=null) |
| fromHeader(), or the Germanic rule (GERMANIC_HEADER) if $header is missing or invalid - reported through $on_invalid then. More... | |
| static | germanic () |
| static | defaultFormIndexForCount (int $count) |
| static | defaultValueForCount (array $forms, int $count) |
Data Fields | |
| const string | GERMANIC_HEADER = 'nplurals=2; plural=(n != 1);' |
| The fallback for a missing or invalid header: the rule of the Germanic languages. More... | |
Private Member Functions | |
| __construct (private readonly int $count, private readonly string $formula, private readonly array $tree) | |
| evaluate (int $n) | |
Static Private Member Functions | |
| static | evaluateNode (array $node, int $n) |
| static | parse (string $formula) |
| static | tokenize (string $formula) |
| static | parseTernary (array $tokens, int &$position, int $depth) |
| ternary := or ( "?" ternary ":" ternary )? More... | |
| static | parseBinary (array $tokens, int &$position, int $depth, int $level) |
| static | parseUnary (array $tokens, int &$position, int $depth) |
| unary := "!" unary | "n" | integer | "(" ternary ")" More... | |
| static | expect (array $tokens, int &$position, string $token) |
| static | assertDepth (int $depth) |
Private Attributes | |
| const int | MAX_COUNT = 10 |
| const int | MAX_FORMULA_LENGTH = 512 |
| const int | MAX_DEPTH = 64 |
| const int | MAX_INTEGER_DIGITS = 9 |
| const array | EXTRA_SAMPLES = [1000, 1001, 1011, 100000, 1000000, 1000001, 2000000] |
| const int | SAMPLED_UP_TO = 200 |
| const array | BINARY_LEVELS |
| The binary operators by precedence, lowest first (C rules; all left-associative). More... | |
Static Private Attributes | |
| static array | $parsed = [] |
The plural rule of a language, as declared by the "Plural-Forms" header of a gettext catalog (nplurals=<count>; plural=<C expression of n>;), and the one place deciding which plural form a message serves.
The expression is parsed by a small recursive descent parser for the subset gettext/CLDR formulas use (n, non-negative integers, ?:, ||, &&, !, ==, !=, <, <=, >, >=, %, parentheses) into a tree evaluated without eval(): a header comes from a file (shipped .po, overlay, plugin) and is untrusted. Anything else (other operators, very long or deeply nested formulas, an index outside 0..count-1 for a sampled n) makes the header invalid.
For callers that need one value of a plural message (txt(), the database fallback, a plugin's database write) the default form is the last one, msgstr[nplurals - 1] - CLDR's "other", the most general category (msgstr[1] is e.g. the 2-4 form in cs/pl/ru, the dual in sl). If it is empty, the closest non-empty form before it is used, see defaultFormIndex() and defaultValueOf().
Definition at line 41 of file PluralForms.php.
|
private |
|
staticprivate |
Definition at line 450 of file PluralForms.php.
Referenced by ILIAS\Language\ComponentTranslation\PluralForms\parseTernary(), and ILIAS\Language\ComponentTranslation\PluralForms\parseUnary().
Here is the caller graph for this function:| ILIAS\Language\ComponentTranslation\PluralForms::defaultFormIndex | ( | ) |
The form serving a plural message where only one value can be used: the last one, msgstr[nplurals - 1].
Definition at line 184 of file PluralForms.php.
References ILIAS\Language\ComponentTranslation\PluralForms\defaultFormIndexForCount().
Referenced by ILIAS\Language\ComponentTranslation\PluralForms\formIndexFor(), and ILIAS\Language\ComponentTranslation\MigratedLanguageFileSync\mapPluralForms().
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Definition at line 189 of file PluralForms.php.
Referenced by ILIAS\Language\ComponentTranslation\PluralForms\defaultFormIndex(), and ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testDefaultFormIndexForCountIsTheLastForm().
Here is the caller graph for this function:
|
static |
| array<int,string> | $forms |
Definition at line 206 of file PluralForms.php.
Referenced by ILIAS\Language\ComponentTranslation\PluralForms\defaultValueOf().
Here is the caller graph for this function:| ILIAS\Language\ComponentTranslation\PluralForms::defaultValueOf | ( | array | $forms | ) |
The value of the default form (see defaultFormIndex()) of a message with $forms (msgstr[0], ...); if that is missing or empty the closest non-empty form before it, '' if all are empty.
| array<int,string> | $forms |
Definition at line 200 of file PluralForms.php.
References ILIAS\Language\ComponentTranslation\PluralForms\defaultValueForCount().
Here is the call graph for this function:
|
private |
Definition at line 274 of file PluralForms.php.
References ILIAS\Language\ComponentTranslation\PluralForms\evaluateNode().
Referenced by ILIAS\Language\ComponentTranslation\PluralForms\formIndexFor().
Here is the call graph for this function:
Here is the caller graph for this function:
|
staticprivate |
| array<int,mixed> | $node |
Definition at line 286 of file PluralForms.php.
References ILIAS\Language\ComponentTranslation\PluralForms\evaluateNode(), and ILIAS\Repository\int().
Referenced by ILIAS\Language\ComponentTranslation\PluralForms\evaluate(), and ILIAS\Language\ComponentTranslation\PluralForms\evaluateNode().
Here is the call graph for this function:
Here is the caller graph for this function:
|
staticprivate |
| list<string> | $tokens |
Definition at line 442 of file PluralForms.php.
References $token.
Referenced by ILIAS\Language\ComponentTranslation\PluralForms\parseTernary(), and ILIAS\Language\ComponentTranslation\PluralForms\parseUnary().
Here is the caller graph for this function:| ILIAS\Language\ComponentTranslation\PluralForms::formIndexFor | ( | int | $n | ) |
The index of the form for the quantity $n.
A negative $n counts as its absolute value (gettext takes an unsigned number). If the expression fails for $n (e.g. a modulo by zero), the default form.
Definition at line 172 of file PluralForms.php.
References ILIAS\Language\ComponentTranslation\PluralForms\defaultFormIndex(), and ILIAS\Language\ComponentTranslation\PluralForms\evaluate().
Referenced by ILIAS\Language\ComponentTranslation\PluralForms\isOneSingularOtherPlural(), ILIAS\Language\ComponentTranslation\PluralForms\previousFormsOf(), and ILIAS\Language\ComponentTranslation\PluralForms\selectsSameFormsAs().
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
| InvalidArgumentException | if $header is no valid "Plural-Forms" value, see the class docblock |
Definition at line 90 of file PluralForms.php.
References ILIAS\Repository\int(), and ILIAS\Language\ComponentTranslation\PluralForms\parse().
Referenced by ILIAS\Language\ComponentTranslation\PluralForms\fromHeaderOrGermanic(), ILIAS\Language\ComponentTranslation\PluralForms\germanic(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testAnOverlongHeaderIsRejectedBeforeTheRegularExpressionRunsOnIt(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testBinaryOperatorsAreLeftAssociative(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testDefaultValueOfFallsBackDownwardsWhenTheLastFormIsEmpty(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testDefaultValueOfFallsBackDownwardsWhenTheLastFormIsMissingEntirely(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testDefaultValueOfIsEmptyWhenEveryFormIsEmpty(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testDefaultValueOfPrefersTheLastFormWhenItIsNotEmpty(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testDefaultValueOfPrefersTheLastOfThreeForms(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testDefaultValueOfSkipsAnEmptyFormInTheMiddleWhileSearchingDownwards(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testDefaultValueOfUsesFormZeroForASingleFormLanguage(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testDefaultValueOfWithNoFormsAtAllIsEmpty(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testFormIndexForFallsBackToTheDefaultFormWhenTheFormulaDividesByZeroForThisN(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testFormIndexForFallsBackToTheLastFormOnEvaluationFailureForAMultiFormLanguage(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testFormIndexForHandlesPhpIntMinWithoutOverflowing(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testFormIndexForMatchesTheKnownRuleOfTheLanguage(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testFormIndexForTreatsANegativeNAsItsAbsoluteValueLikeGettext(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testFromHeaderAcceptsMaximumNplurals(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testFromHeaderThrowsForAnInvalidHeader(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testGetHeaderRoundTripsTheParsedHeader(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testIsOneSingularOtherPluralIsFalseForAnyNonTwoFormCount(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testIsOneSingularOtherPluralIsFalseForFrenchWhichTreatsZeroAsSingular(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testModuloBindsTighterThanComparisonsAndComparisonsTighterThanLogicalAnd(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testPreviousFormsOfListsThePreviousFormsServingTheSameQuantities(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testSelectsSameFormsAsComparesTheSelectedFormsNotTheSpelling(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsShippedRulesTest\testShippedHeaderSelectsTheCldrCategoryForEveryInteger(), and ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testTernaryIsRightAssociativeAndBindsLooserThanComparisons().
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
fromHeader(), or the Germanic rule (GERMANIC_HEADER) if $header is missing or invalid - reported through $on_invalid then.
| (callable(string | $message): void)|null $on_invalid |
Definition at line 135 of file PluralForms.php.
References Vendor\Package\$e, $message, ILIAS\Language\ComponentTranslation\PluralForms\fromHeader(), ILIAS\Language\ComponentTranslation\PluralForms\germanic(), and ILIAS\Language\ComponentTranslation\PlainLogText\of().
Referenced by ILIAS\Language\ComponentTranslation\Catalog\TranslationCatalog\prepareMoPluralForms(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testFromHeaderOrGermanicFallsBackAndReportsForABlankHeader(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testFromHeaderOrGermanicFallsBackAndReportsForAnInvalidHeader(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testFromHeaderOrGermanicFallsBackAndReportsForANullHeader(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testFromHeaderOrGermanicReturnsTheParsedRuleForAValidHeader(), and ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testFromHeaderOrGermanicWorksWithoutACallback().
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Definition at line 153 of file PluralForms.php.
References ILIAS\Language\ComponentTranslation\PluralForms\fromHeader().
Referenced by ILIAS\Language\ComponentTranslation\PluralForms\fromHeaderOrGermanic(), ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testGermanicIsTheDocumentedFallbackHeader(), and ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testIsOneSingularOtherPluralIsTrueForTheGermanicRule().
Here is the call graph for this function:
Here is the caller graph for this function:| ILIAS\Language\ComponentTranslation\PluralForms::getCount | ( | ) |
Definition at line 158 of file PluralForms.php.
Referenced by ILIAS\Language\ComponentTranslation\MigratedLanguageFileSync\formsOf().
Here is the caller graph for this function:| ILIAS\Language\ComponentTranslation\PluralForms::getHeader | ( | ) |
Definition at line 163 of file PluralForms.php.
| ILIAS\Language\ComponentTranslation\PluralForms::isOneSingularOtherPlural | ( | ) |
Whether the rule is "n == 1 -> form 0, every other n -> form 1" (English, German) for every sampled n.
Definition at line 260 of file PluralForms.php.
References ILIAS\Language\ComponentTranslation\PluralForms\formIndexFor().
Here is the call graph for this function:
|
staticprivate |
| InvalidArgumentException |
Definition at line 326 of file PluralForms.php.
References ILIAS\Language\ComponentTranslation\PluralForms\parseTernary(), and ILIAS\Language\ComponentTranslation\PluralForms\tokenize().
Referenced by ILIAS\Language\ComponentTranslation\PluralForms\fromHeader().
Here is the call graph for this function:
Here is the caller graph for this function:
|
staticprivate |
| list<string> | $tokens |
Definition at line 392 of file PluralForms.php.
References ILIAS\Language\ComponentTranslation\PluralForms\parseBinary(), and ILIAS\Language\ComponentTranslation\PluralForms\parseUnary().
Referenced by ILIAS\Language\ComponentTranslation\PluralForms\parseBinary(), and ILIAS\Language\ComponentTranslation\PluralForms\parseTernary().
Here is the call graph for this function:
Here is the caller graph for this function:
|
staticprivate |
ternary := or ( "?" ternary ":" ternary )?
| list<string> | $tokens |
Definition at line 373 of file PluralForms.php.
References ILIAS\Language\ComponentTranslation\PluralForms\assertDepth(), ILIAS\Language\ComponentTranslation\PluralForms\expect(), ILIAS\Language\ComponentTranslation\PluralForms\parseBinary(), and ILIAS\Language\ComponentTranslation\PluralForms\parseTernary().
Referenced by ILIAS\Language\ComponentTranslation\PluralForms\parse(), ILIAS\Language\ComponentTranslation\PluralForms\parseTernary(), and ILIAS\Language\ComponentTranslation\PluralForms\parseUnary().
Here is the call graph for this function:
Here is the caller graph for this function:
|
staticprivate |
unary := "!" unary | "n" | integer | "(" ternary ")"
| list<string> | $tokens |
Definition at line 413 of file PluralForms.php.
References $token, ILIAS\Language\ComponentTranslation\PluralForms\assertDepth(), ILIAS\Language\ComponentTranslation\PluralForms\expect(), ILIAS\Repository\int(), ILIAS\Language\ComponentTranslation\PluralForms\parseTernary(), and ILIAS\Language\ComponentTranslation\PluralForms\parseUnary().
Referenced by ILIAS\Language\ComponentTranslation\PluralForms\parseBinary(), and ILIAS\Language\ComponentTranslation\PluralForms\parseUnary().
Here is the call graph for this function:
Here is the caller graph for this function:| ILIAS\Language\ComponentTranslation\PluralForms::previousFormsOf | ( | PluralForms | $previous | ) |
For every form of this rule, the forms of $previous serving the same quantities: $previous->formIndexFor(n) for every sampled n this rule serves with that form.
One: same meaning under both rules; several: it covers quantities of several former forms; none: no sampled n selects it.
Definition at line 243 of file PluralForms.php.
References ILIAS\Language\ComponentTranslation\PluralForms\formIndexFor(), and ILIAS\UI\examples\Symbol\Glyph\Sort\sort().
Referenced by ILIAS\Language\ComponentTranslation\MigratedLanguageFileSync\mapPluralForms().
Here is the call graph for this function:
Here is the caller graph for this function:| ILIAS\Language\ComponentTranslation\PluralForms::selectsSameFormsAs | ( | PluralForms | $other | ) |
Whether $other has as many forms and selects the same form for every sampled n, e.g.
a header differing only in white space or parentheses.
Definition at line 222 of file PluralForms.php.
References ILIAS\Language\ComponentTranslation\PluralForms\formIndexFor().
Here is the call graph for this function:
|
staticprivate |
| InvalidArgumentException |
Definition at line 342 of file PluralForms.php.
References $token.
Referenced by ILIAS\Language\ComponentTranslation\PluralForms\parse().
Here is the caller graph for this function:
|
staticprivate |
Definition at line 74 of file PluralForms.php.
|
private |
The binary operators by precedence, lowest first (C rules; all left-associative).
Definition at line 65 of file PluralForms.php.
|
private |
Definition at line 59 of file PluralForms.php.
| const string ILIAS\Language\ComponentTranslation\PluralForms::GERMANIC_HEADER = 'nplurals=2; plural=(n != 1);' |
The fallback for a missing or invalid header: the rule of the Germanic languages.
Definition at line 46 of file PluralForms.php.
Referenced by ILIAS\Language\Tests\ComponentTranslation\PluralFormsTest\testGermanicIsTheDocumentedFallbackHeader().
|
private |
Definition at line 48 of file PluralForms.php.
|
private |
Definition at line 50 of file PluralForms.php.
|
private |
Definition at line 49 of file PluralForms.php.
|
private |
Definition at line 51 of file PluralForms.php.
|
private |
Definition at line 60 of file PluralForms.php.