1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: namespace Cake\I18n;
16:
17: 18: 19: 20:
21: class PluralRules
22: {
23:
24: 25: 26: 27: 28: 29:
30: protected static $_rulesMap = [
31: 'af' => 1,
32: 'am' => 2,
33: 'ar' => 13,
34: 'az' => 1,
35: 'be' => 3,
36: 'bg' => 1,
37: 'bh' => 2,
38: 'bn' => 1,
39: 'bo' => 0,
40: 'bs' => 3,
41: 'ca' => 1,
42: 'cs' => 4,
43: 'cy' => 14,
44: 'da' => 1,
45: 'de' => 1,
46: 'dz' => 0,
47: 'el' => 1,
48: 'en' => 1,
49: 'eo' => 1,
50: 'es' => 1,
51: 'et' => 1,
52: 'eu' => 1,
53: 'fa' => 1,
54: 'fi' => 1,
55: 'fil' => 2,
56: 'fo' => 1,
57: 'fr' => 2,
58: 'fur' => 1,
59: 'fy' => 1,
60: 'ga' => 5,
61: 'gl' => 1,
62: 'gu' => 1,
63: 'gun' => 2,
64: 'ha' => 1,
65: 'he' => 1,
66: 'hi' => 2,
67: 'hr' => 3,
68: 'hu' => 1,
69: 'id' => 0,
70: 'is' => 15,
71: 'it' => 1,
72: 'ja' => 0,
73: 'jv' => 0,
74: 'ka' => 0,
75: 'km' => 0,
76: 'kn' => 0,
77: 'ko' => 0,
78: 'ku' => 1,
79: 'lb' => 1,
80: 'ln' => 2,
81: 'lt' => 6,
82: 'lv' => 10,
83: 'mg' => 2,
84: 'mk' => 8,
85: 'ml' => 1,
86: 'mn' => 1,
87: 'mr' => 1,
88: 'ms' => 0,
89: 'mt' => 9,
90: 'nah' => 1,
91: 'nb' => 1,
92: 'ne' => 1,
93: 'nl' => 1,
94: 'nn' => 1,
95: 'no' => 1,
96: 'nso' => 2,
97: 'om' => 1,
98: 'or' => 1,
99: 'pa' => 1,
100: 'pap' => 1,
101: 'pl' => 11,
102: 'ps' => 1,
103: 'pt_pt' => 2,
104: 'pt' => 1,
105: 'ro' => 12,
106: 'ru' => 3,
107: 'sk' => 4,
108: 'sl' => 7,
109: 'so' => 1,
110: 'sq' => 1,
111: 'sr' => 3,
112: 'sv' => 1,
113: 'sw' => 1,
114: 'ta' => 1,
115: 'te' => 1,
116: 'th' => 0,
117: 'ti' => 2,
118: 'tk' => 1,
119: 'tr' => 0,
120: 'uk' => 3,
121: 'ur' => 1,
122: 'vi' => 0,
123: 'wa' => 2,
124: 'zh' => 0,
125: 'zu' => 1,
126: ];
127:
128: 129: 130: 131: 132: 133: 134: 135: 136: 137:
138: public static function calculate($locale, $n)
139: {
140: $locale = strtolower($locale);
141:
142: if (!isset(static::$_rulesMap[$locale])) {
143: $locale = explode('_', $locale)[0];
144: }
145:
146: if (!isset(static::$_rulesMap[$locale])) {
147: return 0;
148: }
149:
150: switch (static::$_rulesMap[$locale]) {
151: case 0:
152: return 0;
153: case 1:
154: return $n == 1 ? 0 : 1;
155: case 2:
156: return $n > 1 ? 1 : 0;
157: case 3:
158: return $n % 10 == 1 && $n % 100 != 11 ? 0 :
159: (($n % 10 >= 2 && $n % 10 <= 4) && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2);
160: case 4:
161: return $n == 1 ? 0 :
162: ($n >= 2 && $n <= 4 ? 1 : 2);
163: case 5:
164: return $n == 1 ? 0 :
165: ($n == 2 ? 1 : ($n < 7 ? 2 : ($n < 11 ? 3 : 4)));
166: case 6:
167: return $n % 10 == 1 && $n % 100 != 11 ? 0 :
168: ($n % 10 >= 2 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2);
169: case 7:
170: return $n % 100 == 1 ? 1 :
171: ($n % 100 == 2 ? 2 : ($n % 100 == 3 || $n % 100 == 4 ? 3 : 0));
172: case 8:
173: return $n % 10 == 1 ? 0 : ($n % 10 == 2 ? 1 : 2);
174: case 9:
175: return $n == 1 ? 0 :
176: ($n == 0 || ($n % 100 > 0 && $n % 100 <= 10) ? 1 :
177: ($n % 100 > 10 && $n % 100 < 20 ? 2 : 3));
178: case 10:
179: return $n % 10 == 1 && $n % 100 != 11 ? 0 : ($n != 0 ? 1 : 2);
180: case 11:
181: return $n == 1 ? 0 :
182: ($n % 10 >= 2 && $n % 10 <= 4 && ($n % 100 < 10 || $n % 100 >= 20) ? 1 : 2);
183: case 12:
184: return $n == 1 ? 0 :
185: ($n == 0 || $n % 100 > 0 && $n % 100 < 20 ? 1 : 2);
186: case 13:
187: return $n == 0 ? 0 :
188: ($n == 1 ? 1 :
189: ($n == 2 ? 2 :
190: ($n % 100 >= 3 && $n % 100 <= 10 ? 3 :
191: ($n % 100 >= 11 ? 4 : 5))));
192: case 14:
193: return $n == 1 ? 0 :
194: ($n == 2 ? 1 :
195: ($n != 8 && $n != 11 ? 2 : 3));
196: case 15:
197: return ($n % 10 != 1 || $n % 100 == 11) ? 1 : 0;
198: }
199: }
200: }
201: