1 | <?php |
||
31 | class Translator |
||
32 | { |
||
33 | /** |
||
34 | * @readwrite |
||
35 | * @var ZendTranslator |
||
36 | */ |
||
37 | protected $_translatorService; |
||
38 | |||
39 | /** |
||
40 | * @readwrite |
||
41 | * @var DriverInterface |
||
42 | */ |
||
43 | protected $_configuration; |
||
44 | |||
45 | /** |
||
46 | * @readwrite |
||
47 | * @var string The message domain |
||
48 | */ |
||
49 | protected $_domain = 'default'; |
||
50 | |||
51 | /** |
||
52 | * @readwrite |
||
53 | * @var string Default fallback locale |
||
54 | */ |
||
55 | protected $_fallbackLocale = 'en_US'; |
||
56 | |||
57 | /** |
||
58 | * @readwrite |
||
59 | * @var string |
||
60 | */ |
||
61 | protected $_basePath = './I18n'; |
||
62 | |||
63 | /** |
||
64 | * @readwrite |
||
65 | * @var string |
||
66 | */ |
||
67 | protected $_type = 'gettext'; |
||
68 | |||
69 | /** |
||
70 | * @var array |
||
71 | */ |
||
72 | private $_types = [ |
||
73 | 'gettext' => '.mo', |
||
74 | 'phparray' => '.php' |
||
75 | ]; |
||
76 | |||
77 | /** |
||
78 | * @var Translator |
||
79 | */ |
||
80 | private static $_instance; |
||
81 | |||
82 | /** |
||
83 | * Trait with method for base class |
||
84 | */ |
||
85 | use BaseMethods; |
||
86 | |||
87 | /** |
||
88 | * Protected constructor to prevent creating a new instance of the |
||
89 | * *Singleton* via the `new` operator from outside of this class. |
||
90 | * |
||
91 | * @param array $options A list of properties for this connector |
||
92 | */ |
||
93 | 2 | protected function __construct($options = array()) |
|
97 | |||
98 | /** |
||
99 | * Private clone method to prevent cloning of the instance of the |
||
100 | * *Singleton* instance. |
||
101 | * |
||
102 | * @codeCoverageIgnore |
||
103 | * @SuppressWarnings(PHPMD.UnusedPrivateMethod) |
||
104 | * @return void |
||
105 | */ |
||
106 | private function __clone() |
||
109 | |||
110 | /** |
||
111 | * Private unserialize method to prevent unserializing of the *Singleton* |
||
112 | * instance. |
||
113 | * |
||
114 | * @codeCoverageIgnore |
||
115 | * @SuppressWarnings(PHPMD.UnusedPrivateMethod) |
||
116 | * @return void |
||
117 | */ |
||
118 | private function __wakeup() |
||
121 | |||
122 | /** |
||
123 | * Lazy loads configuration |
||
124 | * |
||
125 | * @return DriverInterface |
||
126 | */ |
||
127 | 2 | public function getConfiguration() |
|
134 | |||
135 | /** |
||
136 | * Lazy loads zend translator |
||
137 | * |
||
138 | * @return ZendTranslator |
||
139 | */ |
||
140 | 2 | public function getTranslatorService() |
|
154 | |||
155 | /** |
||
156 | * Returns the messages file name based on domain |
||
157 | * |
||
158 | * @return string |
||
159 | */ |
||
160 | 2 | public function getMessageFile() |
|
166 | |||
167 | /** |
||
168 | * Returns the translation for the provided message |
||
169 | * |
||
170 | * @param string $message |
||
171 | * |
||
172 | * @return string |
||
173 | */ |
||
174 | 2 | public function translate($message) |
|
179 | |||
180 | /** |
||
181 | * Translate a plural message. |
||
182 | * |
||
183 | * @param string $singular |
||
184 | * @param string $plural |
||
185 | * @param int $number |
||
186 | * |
||
187 | * @return string |
||
188 | */ |
||
189 | 2 | public function translatePlural($singular, $plural, $number) |
|
200 | |||
201 | /** |
||
202 | * Returns the *Singleton* instance of this class. |
||
203 | * |
||
204 | * @param array $options The list of property values of this instance. |
||
205 | * |
||
206 | * @return Translator The *Singleton* instance. |
||
207 | */ |
||
208 | 2 | public static function getInstance($options = array()) |
|
215 | |||
216 | /** |
||
217 | * Sets locale |
||
218 | * |
||
219 | * @param $locale |
||
220 | * |
||
221 | * @returns Translator |
||
222 | */ |
||
223 | 2 | public function setLocale($locale) |
|
228 | |||
229 | /** |
||
230 | * Gets current configured locale |
||
231 | * |
||
232 | * @return string |
||
233 | */ |
||
234 | 2 | public function getLocale() |
|
239 | } |
||
240 |