@@ -20,29 +20,29 @@ discard block |
||
20 | 20 | */ |
21 | 21 | class Localization_Writer |
22 | 22 | { |
23 | - /** |
|
24 | - * @var boolean |
|
25 | - */ |
|
23 | + /** |
|
24 | + * @var boolean |
|
25 | + */ |
|
26 | 26 | private $editable = false; |
27 | 27 | |
28 | - /** |
|
29 | - * @var array<string,string> |
|
30 | - */ |
|
28 | + /** |
|
29 | + * @var array<string,string> |
|
30 | + */ |
|
31 | 31 | private $hashes = array(); |
32 | 32 | |
33 | - /** |
|
34 | - * @var Localization_Locale |
|
35 | - */ |
|
33 | + /** |
|
34 | + * @var Localization_Locale |
|
35 | + */ |
|
36 | 36 | private $locale; |
37 | 37 | |
38 | - /** |
|
39 | - * @var string |
|
40 | - */ |
|
38 | + /** |
|
39 | + * @var string |
|
40 | + */ |
|
41 | 41 | private $fileType; |
42 | 42 | |
43 | - /** |
|
44 | - * @var string |
|
45 | - */ |
|
43 | + /** |
|
44 | + * @var string |
|
45 | + */ |
|
46 | 46 | private $filePath; |
47 | 47 | |
48 | 48 | public function __construct(Localization_Locale $locale, string $fileType, string $filePath) |
@@ -150,16 +150,16 @@ discard block |
||
150 | 150 | return $hashes; |
151 | 151 | } |
152 | 152 | |
153 | - /** |
|
154 | - * Sort the strings to ensure they always appear in the same order: |
|
155 | - * first by text, and same strings by their hashes. This is important |
|
156 | - * for strings that have the same translation to avoid them changing |
|
157 | - * order between sorts. |
|
158 | - * |
|
159 | - * @param array $a |
|
160 | - * @param array $b |
|
161 | - * @return number |
|
162 | - */ |
|
153 | + /** |
|
154 | + * Sort the strings to ensure they always appear in the same order: |
|
155 | + * first by text, and same strings by their hashes. This is important |
|
156 | + * for strings that have the same translation to avoid them changing |
|
157 | + * order between sorts. |
|
158 | + * |
|
159 | + * @param array $a |
|
160 | + * @param array $b |
|
161 | + * @return number |
|
162 | + */ |
|
163 | 163 | public function callback_sortStrings(array $a, array $b) : int |
164 | 164 | { |
165 | 165 | $result = strnatcasecmp($a['text'], $b['text']); |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | |
69 | 69 | public function addHashes(array $hashes) : Localization_Writer |
70 | 70 | { |
71 | - foreach($hashes as $hash => $text) |
|
71 | + foreach ($hashes as $hash => $text) |
|
72 | 72 | { |
73 | 73 | $this->addHash($hash, $text); |
74 | 74 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $hashes = $this->compileHashes(); |
91 | 91 | $lines = array(); |
92 | 92 | |
93 | - foreach($hashes as $entry) |
|
93 | + foreach ($hashes as $entry) |
|
94 | 94 | { |
95 | 95 | $lines[] = sprintf( |
96 | 96 | '%s= "%s"', |
@@ -106,16 +106,16 @@ discard block |
||
106 | 106 | |
107 | 107 | private function renderHead() : string |
108 | 108 | { |
109 | - $title = strtoupper($this->fileType).' TRANSLATION FILE FOR ' . strtoupper($this->locale->getLabel()); |
|
109 | + $title = strtoupper($this->fileType).' TRANSLATION FILE FOR '.strtoupper($this->locale->getLabel()); |
|
110 | 110 | |
111 | 111 | $lines = array(); |
112 | 112 | |
113 | 113 | $lines[] = '; -------------------------------------------------------'; |
114 | - $lines[] = '; '. $title; |
|
114 | + $lines[] = '; '.$title; |
|
115 | 115 | $lines[] = '; -------------------------------------------------------'; |
116 | 116 | $lines[] = '; '; |
117 | 117 | |
118 | - if($this->editable) |
|
118 | + if ($this->editable) |
|
119 | 119 | { |
120 | 120 | $lines[] = '; You may edit text directly in this file under the following conditions:'; |
121 | 121 | $lines[] = '; '; |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | { |
138 | 138 | $hashes = array(); |
139 | 139 | |
140 | - foreach($this->hashes as $hash => $text) |
|
140 | + foreach ($this->hashes as $hash => $text) |
|
141 | 141 | { |
142 | 142 | $hashes[] = array( |
143 | 143 | 'hash' => $hash, |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | { |
165 | 165 | $result = strnatcasecmp($a['text'], $b['text']); |
166 | 166 | |
167 | - if($result === 0) |
|
167 | + if ($result === 0) |
|
168 | 168 | { |
169 | 169 | return strnatcmp($a['hash'], $b['hash']); |
170 | 170 | } |
@@ -121,8 +121,7 @@ |
||
121 | 121 | $lines[] = '; '; |
122 | 122 | $lines[] = '; 1) Do not to modify the keys (left hand side of the = sign)'; |
123 | 123 | $lines[] = '; 2) Save the file as UTF-8 without BOM'; |
124 | - } |
|
125 | - else |
|
124 | + } else |
|
126 | 125 | { |
127 | 126 | $lines[] = '; Do NOT edit this file directly! It depends on the main translation file'; |
128 | 127 | $lines[] = '; and any changes will be lost. Edit the main file instead.'; |
@@ -45,9 +45,9 @@ discard block |
||
45 | 45 | |
46 | 46 | private $targetLocaleName = null; |
47 | 47 | |
48 | - /** |
|
49 | - * @var Localization_Source[] |
|
50 | - */ |
|
48 | + /** |
|
49 | + * @var Localization_Source[] |
|
50 | + */ |
|
51 | 51 | private $sources = array(); |
52 | 52 | |
53 | 53 | public function addSource(Localization_Source $source) |
@@ -175,14 +175,14 @@ discard block |
||
175 | 175 | ); |
176 | 176 | } |
177 | 177 | |
178 | - /** |
|
179 | - * Retrieves all available strings for the specified locale, |
|
180 | - * as hash => text value pairs. |
|
181 | - * |
|
182 | - * @param Localization_Locale $locale |
|
183 | - * @throws Localization_Exception |
|
184 | - * @return string[] |
|
185 | - */ |
|
178 | + /** |
|
179 | + * Retrieves all available strings for the specified locale, |
|
180 | + * as hash => text value pairs. |
|
181 | + * |
|
182 | + * @param Localization_Locale $locale |
|
183 | + * @throws Localization_Exception |
|
184 | + * @return string[] |
|
185 | + */ |
|
186 | 186 | public function getStrings(Localization_Locale $locale) |
187 | 187 | { |
188 | 188 | $this->load($locale); |
@@ -211,14 +211,14 @@ discard block |
||
211 | 211 | return !empty($this->strings[$locale->getName()]); |
212 | 212 | } |
213 | 213 | |
214 | - /** |
|
215 | - * @param string $type |
|
216 | - * @param Localization_Scanner_StringHash[] $hashes |
|
217 | - * @param string $file |
|
218 | - * @param Localization_Locale $locale |
|
219 | - * @param boolean $editable |
|
220 | - * @throws Localization_Exception |
|
221 | - */ |
|
214 | + /** |
|
215 | + * @param string $type |
|
216 | + * @param Localization_Scanner_StringHash[] $hashes |
|
217 | + * @param string $file |
|
218 | + * @param Localization_Locale $locale |
|
219 | + * @param boolean $editable |
|
220 | + * @throws Localization_Exception |
|
221 | + */ |
|
222 | 222 | protected function renderStringsFile($type, Localization_Source $source, $hashes, $file, Localization_Locale $locale, $editable=true) |
223 | 223 | { |
224 | 224 | $writer = new Localization_Writer($locale, $type, $file); |
@@ -265,13 +265,13 @@ discard block |
||
265 | 265 | ); |
266 | 266 | } |
267 | 267 | |
268 | - /** |
|
269 | - * Retrieves the full path to the strings storage ini file |
|
270 | - * for the clientside strings. |
|
271 | - * |
|
272 | - * @param Localization_Locale $locale |
|
273 | - * @return string |
|
274 | - */ |
|
268 | + /** |
|
269 | + * Retrieves the full path to the strings storage ini file |
|
270 | + * for the clientside strings. |
|
271 | + * |
|
272 | + * @param Localization_Locale $locale |
|
273 | + * @return string |
|
274 | + */ |
|
275 | 275 | protected function getClientStorageFile(Localization_Locale $locale, Localization_Source $source) |
276 | 276 | { |
277 | 277 | return sprintf( |
@@ -393,12 +393,12 @@ discard block |
||
393 | 393 | return null; |
394 | 394 | } |
395 | 395 | |
396 | - /** |
|
397 | - * Retrieves only the strings that are available clientside. |
|
398 | - * |
|
399 | - * @param Localization_Locale $locale |
|
400 | - * @return array |
|
401 | - */ |
|
396 | + /** |
|
397 | + * Retrieves only the strings that are available clientside. |
|
398 | + * |
|
399 | + * @param Localization_Locale $locale |
|
400 | + * @return array |
|
401 | + */ |
|
402 | 402 | public function getClientStrings(Localization_Locale $locale) |
403 | 403 | { |
404 | 404 | $result = array(); |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | |
58 | 58 | public function addSources($sources) |
59 | 59 | { |
60 | - foreach($sources as $source) { |
|
60 | + foreach ($sources as $source) { |
|
61 | 61 | $this->addSource($source); |
62 | 62 | } |
63 | 63 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | $this->strings[$localeName] = array(); |
109 | 109 | } |
110 | 110 | |
111 | - foreach($this->sources as $source) |
|
111 | + foreach ($this->sources as $source) |
|
112 | 112 | { |
113 | 113 | $file = $this->resolveStorageFile($locale, $source); |
114 | 114 | if (!file_exists($file)) { |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | |
118 | 118 | $data = parse_ini_file($file, false); |
119 | 119 | |
120 | - if($data === false) |
|
120 | + if ($data === false) |
|
121 | 121 | { |
122 | 122 | throw new Localization_Exception( |
123 | 123 | 'Malformatted localization file', |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | |
190 | 190 | $name = $locale->getName(); |
191 | 191 | |
192 | - if(isset($this->strings[$name])) { |
|
192 | + if (isset($this->strings[$name])) { |
|
193 | 193 | return $this->strings[$name]; |
194 | 194 | } |
195 | 195 | |
@@ -219,11 +219,11 @@ discard block |
||
219 | 219 | * @param boolean $editable |
220 | 220 | * @throws Localization_Exception |
221 | 221 | */ |
222 | - protected function renderStringsFile($type, Localization_Source $source, $hashes, $file, Localization_Locale $locale, $editable=true) |
|
222 | + protected function renderStringsFile($type, Localization_Source $source, $hashes, $file, Localization_Locale $locale, $editable = true) |
|
223 | 223 | { |
224 | 224 | $writer = new Localization_Writer($locale, $type, $file); |
225 | 225 | |
226 | - if($editable) |
|
226 | + if ($editable) |
|
227 | 227 | { |
228 | 228 | $writer->makeEditable(); |
229 | 229 | } |
@@ -232,14 +232,14 @@ discard block |
||
232 | 232 | |
233 | 233 | foreach ($hashes as $hash) |
234 | 234 | { |
235 | - if(!$hash->hasSourceID($sourceID)) { |
|
235 | + if (!$hash->hasSourceID($sourceID)) { |
|
236 | 236 | continue; |
237 | 237 | } |
238 | 238 | |
239 | 239 | $text = $this->getHashTranslation($hash->getHash(), $locale); |
240 | 240 | |
241 | 241 | // skip any empty strings |
242 | - if($text === null || trim($text) == '') { |
|
242 | + if ($text === null || trim($text) == '') { |
|
243 | 243 | continue; |
244 | 244 | } |
245 | 245 | |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | |
318 | 318 | // to avoid re-creating the hash for the same texts over and over, |
319 | 319 | // we keep track of the hashes we created, and re-use them. |
320 | - if(isset($this->reverseStrings[$text])) { |
|
320 | + if (isset($this->reverseStrings[$text])) { |
|
321 | 321 | $hash = $this->reverseStrings[$text]; |
322 | 322 | } else { |
323 | 323 | $hash = md5($text); |
@@ -378,15 +378,15 @@ discard block |
||
378 | 378 | * @param string $hash |
379 | 379 | * @return string|NULL |
380 | 380 | */ |
381 | - public function getHashTranslation($hash, Localization_Locale $locale=null) |
|
381 | + public function getHashTranslation($hash, Localization_Locale $locale = null) |
|
382 | 382 | { |
383 | - if(!$locale) { |
|
383 | + if (!$locale) { |
|
384 | 384 | $locale = $this->targetLocale; |
385 | 385 | } |
386 | 386 | |
387 | 387 | $localeName = $locale->getName(); |
388 | 388 | |
389 | - if(isset($this->strings[$localeName]) && isset($this->strings[$localeName][$hash])) { |
|
389 | + if (isset($this->strings[$localeName]) && isset($this->strings[$localeName][$hash])) { |
|
390 | 390 | return $this->strings[$localeName][$hash]; |
391 | 391 | } |
392 | 392 | |
@@ -403,10 +403,10 @@ discard block |
||
403 | 403 | { |
404 | 404 | $result = array(); |
405 | 405 | |
406 | - foreach($this->sources as $source) |
|
406 | + foreach ($this->sources as $source) |
|
407 | 407 | { |
408 | 408 | $localeFile = self::getClientStorageFile($locale, $source); |
409 | - if(!file_exists($localeFile)) { |
|
409 | + if (!file_exists($localeFile)) { |
|
410 | 410 | continue; |
411 | 411 | } |
412 | 412 |