1 | <?php |
||
7 | class Translator extends BaseTranslator implements TranslatorInterface |
||
8 | { |
||
9 | protected $domain; |
||
10 | protected $dictionary = []; |
||
11 | protected $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 static |
||
19 | */ |
||
20 | public function loadTranslations($translations) |
||
36 | |||
37 | /** |
||
38 | * Set the default domain. |
||
39 | * |
||
40 | * @param string $domain |
||
41 | * |
||
42 | * @return static |
||
43 | */ |
||
44 | public function defaultDomain($domain) |
||
50 | |||
51 | /** |
||
52 | * @see TranslatorInterface |
||
53 | * |
||
54 | * {@inheritdoc} |
||
55 | */ |
||
56 | public function gettext($original) |
||
60 | |||
61 | /** |
||
62 | * @see TranslatorInterface |
||
63 | * |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | public function ngettext($original, $plural, $value) |
||
70 | |||
71 | /** |
||
72 | * @see TranslatorInterface |
||
73 | * |
||
74 | * {@inheritdoc} |
||
75 | */ |
||
76 | public function dngettext($domain, $original, $plural, $value) |
||
80 | |||
81 | /** |
||
82 | * @see TranslatorInterface |
||
83 | * |
||
84 | * {@inheritdoc} |
||
85 | */ |
||
86 | public function npgettext($context, $original, $plural, $value) |
||
90 | |||
91 | /** |
||
92 | * @see TranslatorInterface |
||
93 | * |
||
94 | * {@inheritdoc} |
||
95 | */ |
||
96 | public function pgettext($context, $original) |
||
100 | |||
101 | /** |
||
102 | * @see TranslatorInterface |
||
103 | * |
||
104 | * {@inheritdoc} |
||
105 | */ |
||
106 | public function dgettext($domain, $original) |
||
110 | |||
111 | /** |
||
112 | * @see TranslatorInterface |
||
113 | * |
||
114 | * {@inheritdoc} |
||
115 | */ |
||
116 | public function dpgettext($domain, $context, $original) |
||
126 | |||
127 | /** |
||
128 | * @see TranslatorInterface |
||
129 | * |
||
130 | * {@inheritdoc} |
||
131 | */ |
||
132 | public function dnpgettext($domain, $context, $original, $plural, $value) |
||
143 | |||
144 | /** |
||
145 | * Set new translations to the dictionary. |
||
146 | * |
||
147 | * @param array $translations |
||
148 | */ |
||
149 | protected function addTranslations(array $translations) |
||
177 | |||
178 | /** |
||
179 | * Search and returns a translation. |
||
180 | * |
||
181 | * @param string $domain |
||
182 | * @param string $context |
||
183 | * @param string $original |
||
184 | * |
||
185 | * @return string|false |
||
186 | */ |
||
187 | protected function getTranslation($domain, $context, $original) |
||
193 | |||
194 | /** |
||
195 | * Executes the plural decision code given the number to decide which |
||
196 | * plural version to take. |
||
197 | * |
||
198 | * @param string $domain |
||
199 | * @param string $n |
||
200 | * @param bool $fallback set to true to get fallback plural index |
||
201 | * |
||
202 | * @return int |
||
203 | */ |
||
204 | protected function getPluralIndex($domain, $n, $fallback) |
||
222 | |||
223 | /** |
||
224 | * This function will recursively wrap failure states in brackets if they contain a nested terse if. |
||
225 | * |
||
226 | * This because PHP can not handle nested terse if's unless they are wrapped in brackets. |
||
227 | * |
||
228 | * This code probably only works for the gettext plural decision codes. |
||
229 | * |
||
230 | * return ($n==1 ? 0 : $n%10>=2 && $n%10<=4 && ($n%100<10 || $n%100>=20) ? 1 : 2); |
||
231 | * becomes |
||
232 | * return ($n==1 ? 0 : ($n%10>=2 && $n%10<=4 && ($n%100<10 || $n%100>=20) ? 1 : 2)); |
||
233 | * |
||
234 | * @param string $code the terse if string |
||
235 | * @param bool $inner If inner is true we wrap it in brackets |
||
236 | * |
||
237 | * @return string A formatted terse If that PHP can work with. |
||
238 | */ |
||
239 | private static function fixTerseIfs($code, $inner = false) |
||
270 | } |
||
271 |
Let’s assume you have a class which uses late-static binding:
}
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: