1 | <?php |
||
37 | class Translator |
||
38 | { |
||
39 | |||
40 | const TYPE_PHP_ARRAY = 'phparray'; |
||
41 | const TYPE_GETTEXT = 'gettext'; |
||
42 | |||
43 | /** |
||
44 | * @readwrite |
||
45 | * @var ZendTranslator |
||
46 | */ |
||
47 | protected $translatorService; |
||
48 | |||
49 | /** |
||
50 | * @readwrite |
||
51 | * @var string The message domain |
||
52 | */ |
||
53 | protected $domain = 'default'; |
||
54 | |||
55 | /** |
||
56 | * @readwrite |
||
57 | * @var string |
||
58 | */ |
||
59 | protected $basePath = './I18n'; |
||
60 | |||
61 | /** |
||
62 | * @readwrite |
||
63 | * @var string |
||
64 | */ |
||
65 | protected $type = self::TYPE_PHP_ARRAY; |
||
66 | |||
67 | /** |
||
68 | * @readwrite |
||
69 | * @var string |
||
70 | */ |
||
71 | protected $locale = 'en_US'; |
||
72 | |||
73 | /** |
||
74 | * @var array |
||
75 | */ |
||
76 | private $types = [ |
||
77 | self::TYPE_GETTEXT => '.mo', |
||
78 | self::TYPE_PHP_ARRAY => '.php' |
||
79 | ]; |
||
80 | |||
81 | /** |
||
82 | * @var Translator |
||
83 | */ |
||
84 | private static $instance; |
||
85 | |||
86 | /** |
||
87 | * @var array |
||
88 | */ |
||
89 | private $loadedFiles = []; |
||
90 | |||
91 | /** |
||
92 | * Trait with method for base class |
||
93 | */ |
||
94 | use BaseMethods; |
||
95 | |||
96 | /** |
||
97 | * Protected constructor to prevent creating a new instance of the |
||
98 | * *Singleton* via the `new` operator from outside of this class. |
||
99 | * |
||
100 | * @param array $options A list of properties for this connector |
||
101 | */ |
||
102 | 2 | protected function __construct($options = array()) |
|
106 | |||
107 | /** |
||
108 | * Private clone method to prevent cloning of the instance of the |
||
109 | * *Singleton* instance. |
||
110 | * |
||
111 | * @codeCoverageIgnore |
||
112 | * @SuppressWarnings(PHPMD.UnusedPrivateMethod) |
||
113 | * @return void |
||
114 | */ |
||
115 | private function __clone() |
||
118 | |||
119 | /** |
||
120 | * Lazy loads zend translator |
||
121 | * |
||
122 | * @return ZendTranslator |
||
123 | */ |
||
124 | 6 | public function getTranslatorService() |
|
131 | |||
132 | /** |
||
133 | * Returns the messages file name based on domain |
||
134 | * |
||
135 | * @param string $domain |
||
136 | * @param string $locale |
||
137 | * |
||
138 | * @return array |
||
139 | */ |
||
140 | 4 | protected function loadFile($domain = null, $locale = null) |
|
160 | |||
161 | /** |
||
162 | * Returns the translation for the provided message |
||
163 | * |
||
164 | * @param string $message |
||
165 | * @param string $domain |
||
166 | * @param string $locale |
||
167 | * |
||
168 | * @return string |
||
169 | */ |
||
170 | 2 | public function translate($message, $domain = null, $locale = null) |
|
176 | |||
177 | /** |
||
178 | * Translate a plural message. |
||
179 | * |
||
180 | * @param string $singular |
||
181 | * @param string $plural |
||
182 | * @param int $number |
||
183 | * @param string $domain |
||
184 | * @param string $locale |
||
185 | * |
||
186 | * @return string |
||
187 | */ |
||
188 | 2 | public function translatePlural( |
|
195 | |||
196 | /** |
||
197 | * Returns the *Singleton* instance of this class. |
||
198 | * |
||
199 | * @param array $options The list of property values of this instance. |
||
200 | * |
||
201 | * @return Translator The *Singleton* instance. |
||
202 | */ |
||
203 | 6 | public static function getInstance($options = array()) |
|
210 | } |
||
211 |