1 | <?php |
||
33 | class Translator { |
||
34 | |||
35 | /** |
||
36 | * None error |
||
37 | */ |
||
38 | const ERROR_NONE = 0; |
||
39 | /** |
||
40 | * File does not exist |
||
41 | */ |
||
42 | const ERROR_DOES_NOT_EXIST = 1; |
||
43 | /** |
||
44 | * File has bad magic number |
||
45 | */ |
||
46 | const ERROR_BAD_MAGIC = 2; |
||
47 | /** |
||
48 | * Error while reading file, probably too short |
||
49 | */ |
||
50 | const ERROR_READING = 3; |
||
51 | |||
52 | /** |
||
53 | * Big endian mo file magic bytes. |
||
54 | */ |
||
55 | const MAGIC_BE = "\x95\x04\x12\xde"; |
||
56 | /** |
||
57 | * Little endian mo file magic bytes. |
||
58 | */ |
||
59 | const MAGIC_LE = "\xde\x12\x04\x95"; |
||
60 | |||
61 | /** |
||
62 | * Parse error code (0 if no error) |
||
63 | * |
||
64 | * @var int |
||
65 | */ |
||
66 | public $error = Translator::ERROR_NONE; |
||
67 | |||
68 | /** |
||
69 | * Cache header field for plural forms |
||
70 | * |
||
71 | * @var string|null |
||
72 | */ |
||
73 | private $pluralequation = NULL; |
||
74 | /** |
||
75 | * |
||
76 | * |
||
77 | * @var int|null number of plurals |
||
78 | */ |
||
79 | private $pluralcount = NULL; |
||
80 | /** |
||
81 | * Array with original -> translation mapping |
||
82 | * |
||
83 | * @var array |
||
84 | */ |
||
85 | private $cache_translations = array(); |
||
86 | |||
87 | /** |
||
88 | * Constructor |
||
89 | * |
||
90 | * @param string $filename Name of mo file to load |
||
91 | */ |
||
92 | 23 | public function __construct($filename) |
|
132 | |||
133 | /** |
||
134 | * Translates a string |
||
135 | * |
||
136 | * @param string $msgid String to be translated |
||
137 | * |
||
138 | * @return string translated string (or original, if not found) |
||
139 | */ |
||
140 | 20 | public function gettext($msgid) |
|
148 | |||
149 | /** |
||
150 | * Sanitize plural form expression for use in SimpleMath |
||
151 | * |
||
152 | * @param string $expr Expression to sanitize |
||
153 | * |
||
154 | * @return string sanitized plural form expression |
||
155 | */ |
||
156 | 10 | public static function sanitizePluralExpression($expr) |
|
176 | |||
177 | /** |
||
178 | * Extracts number of plurals from plurals form expression |
||
179 | * |
||
180 | * @param string $expr Expression to process |
||
181 | * |
||
182 | * @return int Total number of plurals |
||
183 | */ |
||
184 | 9 | public static function extractPluralCount($expr) |
|
193 | |||
194 | /** |
||
195 | * Parse full PO header and extract only plural forms line. |
||
196 | * |
||
197 | * @param string $header Gettext header |
||
198 | * |
||
199 | * @return string verbatim plural form header field |
||
200 | */ |
||
201 | 8 | public static function extractPluralsForms($header) |
|
212 | |||
213 | /** |
||
214 | * Get possible plural forms from MO header |
||
215 | * |
||
216 | * @return string plural form header |
||
217 | */ |
||
218 | 5 | private function getPluralForms() |
|
233 | |||
234 | /** |
||
235 | * Detects which plural form to take |
||
236 | * |
||
237 | * @param int $n count of objects |
||
238 | * |
||
239 | * @return int array index of the right plural form |
||
240 | */ |
||
241 | 5 | private function selectString($n) |
|
253 | |||
254 | /** |
||
255 | * Plural version of gettext |
||
256 | * |
||
257 | * @param string $msgid Single form |
||
258 | * @param string $msgidPlural Plural form |
||
259 | * @param string $number Number of objects |
||
260 | * |
||
261 | * @return string translated plural form |
||
262 | */ |
||
263 | 12 | public function ngettext($msgid, $msgidPlural, $number) |
|
278 | |||
279 | /** |
||
280 | * Translate with context |
||
281 | * |
||
282 | * @param string $msgctxt Context |
||
283 | * @param string $msgid String to be translated |
||
284 | * |
||
285 | * @return string translated plural form |
||
286 | */ |
||
287 | 10 | public function pgettext($msgctxt, $msgid) |
|
297 | |||
298 | /** |
||
299 | * Plural version of pgettext |
||
300 | * |
||
301 | * @param string $msgctxt Context |
||
302 | * @param string $msgid Single form |
||
303 | * @param string $msgidPlural Plural form |
||
304 | * @param string $number Number of objects |
||
305 | * |
||
306 | * @return string translated plural form |
||
307 | */ |
||
308 | 4 | public function npgettext($msgctxt, $msgid, $msgidPlural, $number) |
|
318 | } |
||
319 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..