1 | <?php namespace Fisharebest\Localization; |
||
12 | class Translator |
||
13 | { |
||
14 | /** @var array An association of English -> translated messages */ |
||
15 | private $translations; |
||
16 | |||
17 | /** @var PluralRuleInterface */ |
||
18 | private $plural_rule; |
||
19 | |||
20 | /** |
||
21 | * Create a translator |
||
22 | * |
||
23 | * @param array $translations |
||
24 | * @param PluralRuleInterface $plural_rule |
||
25 | */ |
||
26 | public function __construct(array $translations, $plural_rule) |
||
31 | |||
32 | /** |
||
33 | * Translate a message into another language. |
||
34 | * Works the same as gettext(). |
||
35 | * |
||
36 | * @param string $message English text to translate |
||
37 | * |
||
38 | * @return string Translated text |
||
39 | */ |
||
40 | public function translate($message) |
||
48 | |||
49 | /** |
||
50 | * Translate a context-sensitive message into another language. |
||
51 | * Works the same as pgettext(). |
||
52 | * |
||
53 | * @param string $context Context of the message, e.g. "verb" or "noun" |
||
54 | * @param string $message English text to translate |
||
55 | * |
||
56 | * @return string Translated text |
||
57 | */ |
||
58 | public function translateContext($context, $message) |
||
67 | |||
68 | /** |
||
69 | * Translate a plural message into another language. |
||
70 | * Works the same as ngettext(). |
||
71 | * |
||
72 | * @param string $message1 English text for singular |
||
73 | * @param string $message2 English text for plural |
||
74 | * @param int $number Number of entities |
||
75 | * |
||
76 | * @return string Translated text |
||
77 | */ |
||
78 | public function translatePlural($message1, $message2, $number) |
||
90 | } |
||
91 |