1 | <?php |
||
36 | class Translator { |
||
37 | /** |
||
38 | * Parse error code (0 if no error) |
||
39 | * |
||
40 | * @var int |
||
41 | */ |
||
42 | public $error = 0; |
||
43 | |||
44 | /** |
||
45 | * Cache header field for plural forms |
||
46 | * |
||
47 | * @var string|null |
||
48 | */ |
||
49 | private $pluralheader = NULL; |
||
50 | /** |
||
51 | * |
||
52 | * |
||
53 | * @var int|null number of plurals |
||
54 | */ |
||
55 | private $pluralcount = NULL; |
||
56 | /** |
||
57 | * Array with original -> translation mapping |
||
58 | * |
||
59 | * @var array |
||
60 | */ |
||
61 | private $cache_translations = array(); |
||
62 | |||
63 | /** |
||
64 | * Constructor |
||
65 | * |
||
66 | * @param string $filename Name of mo file to load |
||
67 | */ |
||
68 | 19 | public function __construct($filename) |
|
103 | |||
104 | /** |
||
105 | * Translates a string |
||
106 | * |
||
107 | * @param string $msgid String to be translated |
||
108 | * |
||
109 | * @return string translated string (or original, if not found) |
||
110 | */ |
||
111 | 16 | public function gettext($msgid) |
|
119 | |||
120 | /** |
||
121 | * Sanitize plural form expression for use in PHP eval call. |
||
122 | * |
||
123 | * @param string $expr Expression to sanitize |
||
124 | * |
||
125 | * @return string sanitized plural form expression |
||
126 | */ |
||
127 | 10 | public static function sanitize_plural_expression($expr) |
|
164 | |||
165 | /** |
||
166 | * Extracts number of plurals from plurals form expression |
||
167 | * |
||
168 | * @param string $expr Expression to process |
||
169 | * |
||
170 | * @return int Total number of plurals |
||
171 | */ |
||
172 | 9 | public static function extract_plural_count($expr) |
|
181 | |||
182 | /** |
||
183 | * Parse full PO header and extract only plural forms line. |
||
184 | * |
||
185 | * @param string $header Gettext header |
||
186 | * |
||
187 | * @return string verbatim plural form header field |
||
188 | */ |
||
189 | 8 | public static function extract_plurals_forms($header) |
|
200 | |||
201 | /** |
||
202 | * Get possible plural forms from MO header |
||
203 | * |
||
204 | * @return string plural form header |
||
205 | */ |
||
206 | 5 | private function get_plural_forms() |
|
220 | |||
221 | /** |
||
222 | * Detects which plural form to take |
||
223 | * |
||
224 | * @param int $n count of objects |
||
225 | * |
||
226 | * @return int array index of the right plural form |
||
227 | */ |
||
228 | 5 | private function select_string($n) |
|
240 | |||
241 | /** |
||
242 | * Plural version of gettext |
||
243 | * |
||
244 | * @param string $msgid Single form |
||
245 | * @param string $msgid_plural Plural form |
||
246 | * @param string $number Number of objects |
||
247 | * |
||
248 | * @return string translated plural form |
||
249 | */ |
||
250 | 8 | public function ngettext($msgid, $msgid_plural, $number) |
|
265 | |||
266 | /** |
||
267 | * Translate with context |
||
268 | * |
||
269 | * @param string $msgctxt Context |
||
270 | * @param string $msgid String to be translated |
||
271 | * |
||
272 | * @return string translated plural form |
||
273 | */ |
||
274 | 6 | public function pgettext($msgctxt, $msgid) |
|
284 | |||
285 | /** |
||
286 | * Plural version of pgettext |
||
287 | * |
||
288 | * @param string $msgctxt Context |
||
289 | * @param string $msgid Single form |
||
290 | * @param string $msgid_plural Plural form |
||
291 | * @param string $number Number of objects |
||
292 | * |
||
293 | * @return string translated plural form |
||
294 | */ |
||
295 | 4 | public function npgettext($msgctxt, $msgid, $msgid_plural, $number) |
|
305 | } |
||
306 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.