1 | <?php |
||
7 | class Translator extends BaseTranslator implements TranslatorInterface |
||
8 | { |
||
9 | private $domain; |
||
10 | private $dictionary = []; |
||
11 | private $plurals = []; |
||
12 | |||
13 | /** |
||
14 | * Loads translation from a Translations instance, a file on an array. |
||
15 | * |
||
16 | * @param Translations|string|array $translations |
||
17 | * |
||
18 | * @return self |
||
19 | */ |
||
20 | public function loadTranslations($translations) |
||
34 | |||
35 | /** |
||
36 | * Set the default domain. |
||
37 | * |
||
38 | * @param string $domain |
||
39 | */ |
||
40 | public function defaultDomain($domain) |
||
44 | |||
45 | /** |
||
46 | * @see TranslatorInterface |
||
47 | * |
||
48 | * {@inheritdoc} |
||
49 | */ |
||
50 | public function gettext($original) |
||
54 | |||
55 | /** |
||
56 | * @see TranslatorInterface |
||
57 | * |
||
58 | * {@inheritdoc} |
||
59 | */ |
||
60 | public function ngettext($original, $plural, $value) |
||
64 | |||
65 | /** |
||
66 | * @see TranslatorInterface |
||
67 | * |
||
68 | * {@inheritdoc} |
||
69 | */ |
||
70 | public function dngettext($domain, $original, $plural, $value) |
||
74 | |||
75 | /** |
||
76 | * @see TranslatorInterface |
||
77 | * |
||
78 | * {@inheritdoc} |
||
79 | */ |
||
80 | public function npgettext($context, $original, $plural, $value) |
||
84 | |||
85 | /** |
||
86 | * @see TranslatorInterface |
||
87 | * |
||
88 | * {@inheritdoc} |
||
89 | */ |
||
90 | public function pgettext($context, $original) |
||
94 | |||
95 | /** |
||
96 | * @see TranslatorInterface |
||
97 | * |
||
98 | * {@inheritdoc} |
||
99 | */ |
||
100 | public function dgettext($domain, $original) |
||
104 | |||
105 | /** |
||
106 | * @see TranslatorInterface |
||
107 | * |
||
108 | * {@inheritdoc} |
||
109 | */ |
||
110 | public function dpgettext($domain, $context, $original) |
||
120 | |||
121 | /** |
||
122 | * @see TranslatorInterface |
||
123 | * |
||
124 | * {@inheritdoc} |
||
125 | */ |
||
126 | public function dnpgettext($domain, $context, $original, $plural, $value) |
||
137 | |||
138 | /** |
||
139 | * Set new translations to the dictionary. |
||
140 | * |
||
141 | * @param array $translations |
||
142 | */ |
||
143 | protected function addTranslations(array $translations) |
||
171 | |||
172 | /** |
||
173 | * Search and returns a translation. |
||
174 | * |
||
175 | * @param string $domain |
||
176 | * @param string $context |
||
177 | * @param string $original |
||
178 | * |
||
179 | * @return string|false |
||
180 | */ |
||
181 | protected function getTranslation($domain, $context, $original) |
||
185 | |||
186 | /** |
||
187 | * Executes the plural decision code given the number to decide which |
||
188 | * plural version to take. |
||
189 | * |
||
190 | * @param string $domain |
||
191 | * @param string $n |
||
192 | * |
||
193 | * @return int |
||
194 | */ |
||
195 | protected function isPlural($domain, $n) |
||
212 | |||
213 | /** |
||
214 | * This function will recursively wrap failure states in brackets if they contain a nested terse if. |
||
215 | * |
||
216 | * This because PHP can not handle nested terse if's unless they are wrapped in brackets. |
||
217 | * |
||
218 | * This code probably only works for the gettext plural decision codes. |
||
219 | * |
||
220 | * return ($n==1 ? 0 : $n%10>=2 && $n%10<=4 && ($n%100<10 || $n%100>=20) ? 1 : 2); |
||
221 | * becomes |
||
222 | * return ($n==1 ? 0 : ($n%10>=2 && $n%10<=4 && ($n%100<10 || $n%100>=20) ? 1 : 2)); |
||
223 | * |
||
224 | * @param string $code the terse if string |
||
225 | * @param bool $inner If inner is true we wrap it in brackets |
||
226 | * |
||
227 | * @return string A formatted terse If that PHP can work with. |
||
228 | */ |
||
229 | private static function fixTerseIfs($code, $inner = false) |
||
260 | } |
||
261 |