PluralRules
in package
PluralRules
Die verschiedenen Sprachen haben unterschiedliche Formen der Pluralbildung. Das Englische kennt zwei, das polnische kennt vier Pluralformen. Diese Klasse bildet die Pluralregeln ab. Die angegebenen Schlüsselwörter sind nur Platzhalter, denen eine Kategorie zugewisen wird.
// Polnische Regeln.
$locale = \Alvine\I18n\Locale::getInstance('pl');
$rule = \Alvine\I18n\Util\PluralRules::getInstance($locale);
$rule->getKeyword(1); // ist ONE;
$rule->getKeyword(2); // ist FEW;
Beispiel für das Wort Auto in polnisch
0 aut
1 auto
2-4 auta
5-19 aut
20-21 aut
22-24 auta
25-29 aut
x0-x1 aut
x2-x4 auta
x5-x9 aut
Tags
Table of Contents
Constants
- FEW = 'FEW'
- Einige
- MANY = 'MANY'
- Viele
- ONE = 'ONE'
- ein oder singular
- OTHER = 'OTHER'
- Alle restlichen Formen
- TWO = 'TWO'
- zwei / dual
- ZERO = 'ZERO'
- Null, oder kein.
Properties
- $constraint : Constraint
- Regelwerk für die Ermittlung des Schlüsselwortes.
- $instanceMap : array
- Alle Instanzen des Regelwerks nach Localen gemapped.
- $rulemap : array
- Liste mit ISO-Codes der Sprachen und eine Referenz auf die für die Locale definierte Mehrzahlregel.
- $rules : array
- Definition der einzelnen Regeln zur Mehrzahlbildung.
- $locale : string
Methods
- getInstance() : PluralRules
- getInstance
- getKeyword() : string
- Diese Funktion gibt das Schlüsselwort für die Mehrzahlbildung zurück.
- parse() : mixed
- Zerlegen einer Plural-Regel
- __construct() : mixed
- Neues Objekt
- getRule() : array
- Diese Funktion ermittelt die für diese Locale gültige Regel und gibt diese zurück. Wird keine Regel gefunden, so wird ein leeres Array zurückgegeben.
Constants
FEW
Einige
public
mixed
FEW
= 'FEW'
MANY
Viele
public
mixed
MANY
= 'MANY'
ONE
ein oder singular
public
mixed
ONE
= 'ONE'
OTHER
Alle restlichen Formen
public
mixed
OTHER
= 'OTHER'
TWO
zwei / dual
public
mixed
TWO
= 'TWO'
ZERO
Null, oder kein.
public
mixed
ZERO
= 'ZERO'
Properties
$constraint
Regelwerk für die Ermittlung des Schlüsselwortes.
protected
Constraint
$constraint
= null
Regelwerk
$instanceMap
Alle Instanzen des Regelwerks nach Localen gemapped.
protected
static array
$instanceMap
= array()
Map
$rulemap
Liste mit ISO-Codes der Sprachen und eine Referenz auf die für die Locale definierte Mehrzahlregel.
protected
static array
$rulemap
= array('az' => 1, 'bm' => 1, 'bo' => 1, 'dz' => 1, 'fa' => 1, 'id' => 1, 'ig' => 1, 'ii' => 1, 'hu' => 1, 'ja' => 1, 'jv' => 1, 'ka' => 1, 'kde' => 1, 'kea' => 1, 'km' => 1, 'kn' => 1, 'ko' => 1, 'lo' => 1, 'ms' => 1, 'my' => 1, 'sah' => 1, 'ses' => 1, 'sg' => 1, 'th' => 1, 'to' => 1, 'tr' => 1, 'vi' => 1, 'wo' => 1, 'yo' => 1, 'zh' => 1, 'ar' => 2, 'he' => 3, 'asa' => 4, 'ast' => 4, 'af' => 4, 'bem' => 4, 'bez' => 4, 'bg' => 4, 'bn' => 4, 'brx' => 4, 'ca' => 4, 'cgg' => 4, 'chr' => 4, 'ckb' => 4, 'da' => 4, 'de' => 4, 'dv' => 4, 'ee' => 4, 'el' => 4, 'en' => 4, 'eo' => 4, 'es' => 4, 'et' => 4, 'eu' => 4, 'fi' => 4, 'fo' => 4, 'fur' => 4, 'fy' => 4, 'gl' => 4, 'gsw' => 4, 'gu' => 4, 'ha' => 4, 'haw' => 4, 'hy' => 4, 'is' => 4, 'it' => 4, 'jgo' => 4, 'jmc' => 4, 'kaj' => 4, 'kcg' => 4, 'kk' => 4, 'kkj' => 4, 'kl' => 4, 'ks' => 4, 'ksb' => 4, 'ku' => 4, 'ky' => 4, 'lb' => 4, 'lg' => 4, 'mas' => 4, 'mgo' => 4, 'ml' => 4, 'mn' => 4, 'mr' => 4, 'nah' => 4, 'nb' => 4, 'nd' => 4, 'ne' => 4, 'nl' => 4, 'nn' => 4, 'nnh' => 4, 'no' => 4, 'nr' => 4, 'ny' => 4, 'nyn' => 4, 'om' => 4, 'or' => 4, 'os' => 4, 'pa' => 4, 'pap' => 4, 'ps' => 4, 'pt' => 4, 'rof' => 4, 'rm' => 4, 'rwk' => 4, 'saq' => 4, 'seh' => 4, 'sn' => 4, 'so' => 4, 'sq' => 4, 'ss' => 4, 'ssy' => 4, 'st' => 4, 'sv' => 4, 'sw' => 4, 'syr' => 4, 'ta' => 4, 'te' => 4, 'teo' => 4, 'tig' => 4, 'tk' => 4, 'tn' => 4, 'ts' => 4, 'ur' => 4, 'vo' => 4, 'wae' => 4, 've' => 4, 'vun' => 4, 'xh' => 4, 'xog' => 4, 'zu' => 4, 'ak' => 5, 'am' => 5, 'bh' => 5, 'fil' => 5, 'tl' => 5, 'guw' => 5, 'hi' => 5, 'ln' => 5, 'mg' => 5, 'nso' => 5, 'ti' => 5, 'wa' => 5, 'ff' => 6, 'fr' => 6, 'kab' => 6, 'lv' => 7, 'iu' => 8, 'kw' => 8, 'naq' => 8, 'se' => 8, 'sma' => 8, 'smi' => 8, 'smj' => 8, 'smn' => 8, 'sms' => 8, 'ga' => 9, 'ro' => 10, 'mo' => 10, 'lt' => 11, 'be' => 12, 'bs' => 12, 'hr' => 12, 'ru' => 12, 'sh' => 12, 'sr' => 12, 'uk' => 12, 'cs' => 13, 'sk' => 13, 'pl' => 14, 'sl' => 15, 'mt' => 16, 'mk' => 17, 'cy' => 18, 'lag' => 19, 'shi' => 20, 'br' => 21, 'ksh' => 22, 'tzm' => 23, 'gv' => 24, 'gd' => 25)
ISO --> Mehrzahlregel
Tags
$rules
Definition der einzelnen Regeln zur Mehrzahlbildung.
protected
static array
$rules
= array(1 => array(), 2 => array('ZERO' => 'n is 0', 'ONE' => 'n is 1', 'TWO' => 'n is 2', 'FEW' => 'n mod 100 in 3..10', 'MANY' => 'n mod 100 in 11..99'), 3 => array('ONE' => 'n is 1', 'TWO' => 'n is 2', 'MANY' => 'n is not 0 AND n mod 10 is 0'), 4 => array('ONE' => 'n is 1'), 5 => array('ONE' => 'n in 0..1'), 6 => array('ONE' => 'n within 0..2 and n is not 2'), 7 => array('ZERO' => 'n is 0', 'ONE' => 'n mod 10 is 1 and n mod 100 is not 11'), 8 => array('ONE' => 'n is 1', 'TWO' => 'n is 2'), 9 => array('ONE' => 'n is 1', 'TWO' => 'n is 2', 'FEW' => 'n in 3..6', 'MANY' => 'n in 7..10'), 10 => array('ONE' => 'n is 1', 'FEW' => 'n is 0 OR n is not 1 AND n mod 100 in 1..19'), 11 => array('ONE' => 'n mod 10 is 1 and n mod 100 not in 11..19', 'FEW' => 'n mod 10 in 2..9 and n mod 100 not in 11..19'), 12 => array('ONE' => 'n mod 10 is 1 and n mod 100 is not 11', 'FEW' => 'n mod 10 in 2..4 and n mod 100 not in 12..14', 'MANY' => 'n mod 10 is 0 or n mod 10 in 5..9 or n mod 100 in 11..14'), 13 => array('ONE' => 'n is 1', 'FEW' => 'n in 2..4'), 14 => array('ONE' => 'n is 1', 'FEW' => 'n mod 10 in 2..4 and n mod 100 not in 12..14', 'MANY' => 'n is not 1 and n mod 10 in 0..1 or n mod 10 in 5..9 or n mod 100 in 12..14'), 15 => array('ONE' => 'n mod 100 is 1', 'TWO' => 'n mod 100 is 2', 'FEW' => 'n mod 100 in 3..4'), 16 => array('ONE' => 'n is 1', 'FEW' => 'n is 0 or n mod 100 in 2..10', 'MANY' => 'n mod 100 in 11..19'), 17 => array('ONE' => 'n mod 10 is 1 and n is not 11'), 18 => array('ZERO' => 'n is 0', 'ONE' => 'n is 1', 'TWO' => 'n is 2', 'FEW' => 'n is 3', 'MANY' => 'n is 6'), 19 => array('ZERO' => 'n is 0', 'ONE' => 'n within 0..2 and n is not 0 and n is not 2'), 20 => array('ONE' => 'n within 0..1', 'FEW' => 'n in 2..10'), 21 => array('ONE' => 'n mod 10 is 1 and n mod 100 not in 11,71,91', 'TWO' => 'n mod 10 is 2 and n mod 100 not in 12,72,92', 'FEW' => 'n mod 10 in 3..4,9 and n mod 100 not in 10..19,70..79,90..99', 'MANY' => 'n is not 0 and n mod 1000000 is 0'), 22 => array('ZERO' => 'n is 0', 'ONE' => 'n is 1'), 23 => array('ONE' => 'n in 0..1 or n in 11..99'), 24 => array('ONE' => 'n mod 10 in 1..2 or n mod 20 is 0'), 25 => array('ONE' => 'n in 1,11', 'TWO' => 'n in 2,12', 'FEW' => 'n in 3..10,13..19'))
Regel --> Vorschrift
Tags
$locale
private
string
$locale
= null
Locale
Methods
getInstance()
getInstance
public
static getInstance([Locale $locale = null ]) : PluralRules
Die Plural-Regeln sollen pro Locale nur einmal erstellt werden. Aus diesem Grund ist der Konstruktor protected und kann nur über diese Methode indirekt aufgerufen werden.
Parameters
- $locale : Locale = null
-
Locale
Return values
PluralRules —Bestehendes oder neues Objekt.
getKeyword()
Diese Funktion gibt das Schlüsselwort für die Mehrzahlbildung zurück.
public
getKeyword(integer $n) : string
Parameters
- $n : integer
-
Zahl
Return values
string —Schlüsselwort ZERO,ONE,TWO,FEW,MANY,OTHER
parse()
Zerlegen einer Plural-Regel
public
static parse(type $rule) : mixed
condition : or_condition
and_condition
or_condition : and_condition 'or' condition
and_condition : relation
relation 'and' relation
relation : is_relation
in_relation
within_relation
'n' EOL
is_relation : expr 'is' value
expr 'is' 'not' value
in_relation : expr 'in' range
expr 'not' 'in' range
within_relation : expr 'within' range
expr 'not' 'within' range
expr : 'n'
'n' 'mod' value
value : digit+
digit : 0|1|2|3|4|5|6|7|8|9
range : value'..'value
Parameters
- $rule : type
Tags
__construct()
Neues Objekt
protected
__construct([Locale $locale = null ]) : mixed
Neues Objekt für Locale anlegen und das Regelwerk initialisieren.
Parameters
- $locale : Locale = null
-
Locale
getRule()
Diese Funktion ermittelt die für diese Locale gültige Regel und gibt diese zurück. Wird keine Regel gefunden, so wird ein leeres Array zurückgegeben.
protected
static getRule(type $iso) : array
Parameters
- $iso : type
-
Iso-Code der Locale (z.B. de)
Return values
array —Liste mit den Regeln