1 | <?php |
||
23 | class Translator |
||
24 | { |
||
25 | use Options; |
||
26 | |||
27 | /** |
||
28 | * Locale |
||
29 | * |
||
30 | * @var string |
||
31 | * @link http://www.loc.gov/standards/iso639-2/php/code_list.php |
||
32 | */ |
||
33 | protected $locale = 'en_US'; |
||
34 | |||
35 | /** |
||
36 | * @var string text domain |
||
37 | */ |
||
38 | protected $domain = 'messages'; |
||
39 | |||
40 | /** |
||
41 | * @var string path to text domain files |
||
42 | */ |
||
43 | protected $path; |
||
44 | |||
45 | /** |
||
46 | * Set domain |
||
47 | * |
||
48 | * @param string $domain |
||
49 | * |
||
50 | * @return self |
||
51 | */ |
||
52 | 604 | public function setDomain($domain) |
|
57 | |||
58 | /** |
||
59 | * Set locale |
||
60 | * |
||
61 | * @param string $locale |
||
62 | * |
||
63 | * @return self |
||
64 | */ |
||
65 | 604 | public function setLocale($locale) |
|
70 | |||
71 | /** |
||
72 | * Set path to l10n |
||
73 | * |
||
74 | * @param string $path |
||
75 | * |
||
76 | * @return self |
||
77 | */ |
||
78 | 604 | public function setPath($path) |
|
83 | |||
84 | /** |
||
85 | * Initialization |
||
86 | * |
||
87 | * @return void |
||
88 | * @throws ConfigurationException |
||
89 | * @throw \Bluz\Config\ConfigException |
||
90 | */ |
||
91 | 604 | public function init() : void |
|
112 | |||
113 | /** |
||
114 | * Add text domain for gettext |
||
115 | * |
||
116 | * @param string $domain of text for gettext setup |
||
117 | * @param string $path on filesystem |
||
118 | * |
||
119 | * @return void |
||
120 | * @throws ConfigurationException |
||
121 | */ |
||
122 | 604 | public function addTextDomain($domain, $path) : void |
|
134 | |||
135 | /** |
||
136 | * Translate message |
||
137 | * |
||
138 | * Simple example of usage |
||
139 | * equal to gettext('Message') |
||
140 | * |
||
141 | * Translator::translate('Message'); |
||
142 | * |
||
143 | * Simple replace of one or more argument(s) |
||
144 | * equal to sprintf(gettext('Message to %s'), 'Username') |
||
145 | * |
||
146 | * Translator::translate('Message to %s', 'Username'); |
||
147 | * |
||
148 | * @param string $message |
||
149 | * @param string[] ...$text |
||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | 458 | public static function translate(string $message, ...$text) : string |
|
169 | |||
170 | /** |
||
171 | * Translate plural form |
||
172 | * |
||
173 | * Example of usage plural form + sprintf |
||
174 | * equal to sprintf(ngettext('%d comment', '%d comments', 4), 4) |
||
175 | * Translator::translatePlural('%d comment', '%d comments', 4) |
||
176 | * |
||
177 | * Example of usage plural form + sprintf |
||
178 | * equal to sprintf(ngettext('%d comment', '%d comments', 4), 4, 'Topic') |
||
179 | * Translator::translatePlural('%d comment to %s', '%d comments to %s', 4, 'Topic') |
||
180 | * |
||
181 | * @param string $singular |
||
182 | * @param string $plural |
||
183 | * @param integer $number |
||
184 | * @param string[] ...$text |
||
185 | * |
||
186 | * @return string |
||
187 | * @link http://docs.translatehouse.org/projects/localization-guide/en/latest/l10n/pluralforms.html |
||
188 | */ |
||
189 | 2 | public static function translatePlural(string $singular, string $plural, $number, ...$text) : string |
|
205 | } |
||
206 |