@@ -2,15 +2,13 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace Gettext; |
4 | 4 | |
5 | -class GettextTranslator extends BaseTranslator implements TranslatorInterface |
|
6 | -{ |
|
5 | +class GettextTranslator extends BaseTranslator implements TranslatorInterface { |
|
7 | 6 | /** |
8 | 7 | * Constructor. Detects the current language using the environment variables. |
9 | 8 | * |
10 | 9 | * @param string $language |
11 | 10 | */ |
12 | - public function __construct($language = null) |
|
13 | - { |
|
11 | + public function __construct($language = null) { |
|
14 | 12 | if (!function_exists('gettext')) { |
15 | 13 | throw new \RuntimeException('This class require the gettext extension for PHP'); |
16 | 14 | } |
@@ -34,8 +32,7 @@ discard block |
||
34 | 32 | * |
35 | 33 | * @return self |
36 | 34 | */ |
37 | - public function setLanguage($language, $category = null) |
|
38 | - { |
|
35 | + public function setLanguage($language, $category = null) { |
|
39 | 36 | if ($category === null) { |
40 | 37 | $category = defined('LC_MESSAGES') ? LC_MESSAGES : LC_ALL; |
41 | 38 | } |
@@ -55,8 +52,7 @@ discard block |
||
55 | 52 | * |
56 | 53 | * @return self |
57 | 54 | */ |
58 | - public function loadDomain($domain, $path = null, $default = true) |
|
59 | - { |
|
55 | + public function loadDomain($domain, $path = null, $default = true) { |
|
60 | 56 | bindtextdomain($domain, $path); |
61 | 57 | bind_textdomain_codeset($domain, 'UTF-8'); |
62 | 58 | |
@@ -72,8 +68,7 @@ discard block |
||
72 | 68 | * |
73 | 69 | * {@inheritdoc} |
74 | 70 | */ |
75 | - public function gettext($original) |
|
76 | - { |
|
71 | + public function gettext($original) { |
|
77 | 72 | return gettext($original); |
78 | 73 | } |
79 | 74 | |
@@ -82,8 +77,7 @@ discard block |
||
82 | 77 | * |
83 | 78 | * {@inheritdoc} |
84 | 79 | */ |
85 | - public function ngettext($original, $plural, $value) |
|
86 | - { |
|
80 | + public function ngettext($original, $plural, $value) { |
|
87 | 81 | return ngettext($original, $plural, $value); |
88 | 82 | } |
89 | 83 | |
@@ -92,8 +86,7 @@ discard block |
||
92 | 86 | * |
93 | 87 | * {@inheritdoc} |
94 | 88 | */ |
95 | - public function dngettext($domain, $original, $plural, $value) |
|
96 | - { |
|
89 | + public function dngettext($domain, $original, $plural, $value) { |
|
97 | 90 | return dngettext($domain, $original, $plural, $value); |
98 | 91 | } |
99 | 92 | |
@@ -102,8 +95,7 @@ discard block |
||
102 | 95 | * |
103 | 96 | * {@inheritdoc} |
104 | 97 | */ |
105 | - public function npgettext($context, $original, $plural, $value) |
|
106 | - { |
|
98 | + public function npgettext($context, $original, $plural, $value) { |
|
107 | 99 | $message = $context."\x04".$original; |
108 | 100 | $translation = ngettext($message, $plural, $value); |
109 | 101 | |
@@ -115,8 +107,7 @@ discard block |
||
115 | 107 | * |
116 | 108 | * {@inheritdoc} |
117 | 109 | */ |
118 | - public function pgettext($context, $original) |
|
119 | - { |
|
110 | + public function pgettext($context, $original) { |
|
120 | 111 | $message = $context."\x04".$original; |
121 | 112 | $translation = gettext($message); |
122 | 113 | |
@@ -128,8 +119,7 @@ discard block |
||
128 | 119 | * |
129 | 120 | * {@inheritdoc} |
130 | 121 | */ |
131 | - public function dgettext($domain, $original) |
|
132 | - { |
|
122 | + public function dgettext($domain, $original) { |
|
133 | 123 | return dgettext($domain, $original); |
134 | 124 | } |
135 | 125 | |
@@ -138,8 +128,7 @@ discard block |
||
138 | 128 | * |
139 | 129 | * {@inheritdoc} |
140 | 130 | */ |
141 | - public function dpgettext($domain, $context, $original) |
|
142 | - { |
|
131 | + public function dpgettext($domain, $context, $original) { |
|
143 | 132 | $message = $context."\x04".$original; |
144 | 133 | $translation = dgettext($domain, $message); |
145 | 134 | |
@@ -151,8 +140,7 @@ discard block |
||
151 | 140 | * |
152 | 141 | * {@inheritdoc} |
153 | 142 | */ |
154 | - public function dnpgettext($domain, $context, $original, $plural, $value) |
|
155 | - { |
|
143 | + public function dnpgettext($domain, $context, $original, $plural, $value) { |
|
156 | 144 | $message = $context."\x04".$original; |
157 | 145 | $translation = dngettext($domain, $message, $plural, $value); |
158 | 146 |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Trait to provide the functionality of extracting headers. |
9 | 9 | */ |
10 | -trait HeadersGeneratorTrait |
|
11 | -{ |
|
10 | +trait HeadersGeneratorTrait { |
|
12 | 11 | /** |
13 | 12 | * Returns the headers as a string. |
14 | 13 | * |
@@ -16,8 +15,7 @@ discard block |
||
16 | 15 | * |
17 | 16 | * @return string |
18 | 17 | */ |
19 | - protected static function generateHeaders(Translations $translations) |
|
20 | - { |
|
18 | + protected static function generateHeaders(Translations $translations) { |
|
21 | 19 | $headers = ''; |
22 | 20 | |
23 | 21 | foreach ($translations->getHeaders() as $name => $value) { |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Trait used by all generators that exports the translations to plain dictionary (original => singular-translation). |
9 | 9 | */ |
10 | -trait DictionaryTrait |
|
11 | -{ |
|
10 | +trait DictionaryTrait { |
|
12 | 11 | use HeadersGeneratorTrait; |
13 | 12 | use HeadersExtractorTrait; |
14 | 13 | |
@@ -20,8 +19,7 @@ discard block |
||
20 | 19 | * |
21 | 20 | * @return array |
22 | 21 | */ |
23 | - protected static function toArray(Translations $translations, $includeHeaders) |
|
24 | - { |
|
22 | + protected static function toArray(Translations $translations, $includeHeaders) { |
|
25 | 23 | $messages = []; |
26 | 24 | |
27 | 25 | if ($includeHeaders) { |
@@ -45,8 +43,7 @@ discard block |
||
45 | 43 | * @param array $messages |
46 | 44 | * @param Translations $translations |
47 | 45 | */ |
48 | - protected static function fromArray(array $messages, Translations $translations) |
|
49 | - { |
|
46 | + protected static function fromArray(array $messages, Translations $translations) { |
|
50 | 47 | foreach ($messages as $original => $translation) { |
51 | 48 | if ($original === '') { |
52 | 49 | static::extractHeaders($translation, $translations); |
@@ -2,8 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace Gettext\Utils; |
4 | 4 | |
5 | -class JsFunctionsScanner extends FunctionsScanner |
|
6 | -{ |
|
5 | +class JsFunctionsScanner extends FunctionsScanner { |
|
7 | 6 | protected $code; |
8 | 7 | protected $status = []; |
9 | 8 | |
@@ -12,8 +11,7 @@ discard block |
||
12 | 11 | * |
13 | 12 | * @param string $code The php code to scan |
14 | 13 | */ |
15 | - public function __construct($code) |
|
16 | - { |
|
14 | + public function __construct($code) { |
|
17 | 15 | // Normalize newline characters |
18 | 16 | $this->code = str_replace(["\r\n", "\n\r", "\r"], "\n", $code); |
19 | 17 | } |
@@ -21,8 +19,7 @@ discard block |
||
21 | 19 | /** |
22 | 20 | * {@inheritdoc} |
23 | 21 | */ |
24 | - public function getFunctions(array $constants = []) |
|
25 | - { |
|
22 | + public function getFunctions(array $constants = []) { |
|
26 | 23 | $length = strlen($this->code); |
27 | 24 | $line = 1; |
28 | 25 | $buffer = ''; |
@@ -234,8 +231,7 @@ discard block |
||
234 | 231 | * |
235 | 232 | * @return string|bool |
236 | 233 | */ |
237 | - protected function status($match = null) |
|
238 | - { |
|
234 | + protected function status($match = null) { |
|
239 | 235 | $status = isset($this->status[0]) ? $this->status[0] : null; |
240 | 236 | |
241 | 237 | if ($match !== null) { |
@@ -250,8 +246,7 @@ discard block |
||
250 | 246 | * |
251 | 247 | * @param string $status |
252 | 248 | */ |
253 | - protected function downStatus($status) |
|
254 | - { |
|
249 | + protected function downStatus($status) { |
|
255 | 250 | array_unshift($this->status, $status); |
256 | 251 | } |
257 | 252 | |
@@ -260,8 +255,7 @@ discard block |
||
260 | 255 | * |
261 | 256 | * @return string|null |
262 | 257 | */ |
263 | - protected function upStatus() |
|
264 | - { |
|
258 | + protected function upStatus() { |
|
265 | 259 | return array_shift($this->status); |
266 | 260 | } |
267 | 261 | |
@@ -272,8 +266,7 @@ discard block |
||
272 | 266 | * |
273 | 267 | * @return string |
274 | 268 | */ |
275 | - protected static function prepareArgument($argument) |
|
276 | - { |
|
269 | + protected static function prepareArgument($argument) { |
|
277 | 270 | if ($argument && in_array($argument[0], ['"', "'", '`'], true)) { |
278 | 271 | return static::convertString(substr($argument, 1, -1)); |
279 | 272 | } |
@@ -286,8 +279,7 @@ discard block |
||
286 | 279 | * |
287 | 280 | * @return string |
288 | 281 | */ |
289 | - protected static function convertString($value) |
|
290 | - { |
|
282 | + protected static function convertString($value) { |
|
291 | 283 | if (strpos($value, '\\') === false) { |
292 | 284 | return $value; |
293 | 285 | } |
@@ -5,8 +5,7 @@ discard block |
||
5 | 5 | /* |
6 | 6 | * Trait to provide the functionality of read/write csv. |
7 | 7 | */ |
8 | -trait CsvTrait |
|
9 | -{ |
|
8 | +trait CsvTrait { |
|
10 | 9 | protected static $csvEscapeChar; |
11 | 10 | |
12 | 11 | /** |
@@ -14,8 +13,7 @@ discard block |
||
14 | 13 | * |
15 | 14 | * @return bool |
16 | 15 | */ |
17 | - protected static function supportsCsvEscapeChar() |
|
18 | - { |
|
16 | + protected static function supportsCsvEscapeChar() { |
|
19 | 17 | if (static::$csvEscapeChar === null) { |
20 | 18 | static::$csvEscapeChar = version_compare(PHP_VERSION, '5.5.4') >= 0; |
21 | 19 | } |
@@ -29,8 +27,7 @@ discard block |
||
29 | 27 | * |
30 | 28 | * @return array |
31 | 29 | */ |
32 | - protected static function fgetcsv($handle, $options) |
|
33 | - { |
|
30 | + protected static function fgetcsv($handle, $options) { |
|
34 | 31 | if (static::supportsCsvEscapeChar()) { |
35 | 32 | return fgetcsv($handle, 0, $options['delimiter'], $options['enclosure'], $options['escape_char']); |
36 | 33 | } |
@@ -45,8 +42,7 @@ discard block |
||
45 | 42 | * |
46 | 43 | * @return bool|int |
47 | 44 | */ |
48 | - protected static function fputcsv($handle, $fields, $options) |
|
49 | - { |
|
45 | + protected static function fputcsv($handle, $fields, $options) { |
|
50 | 46 | if (static::supportsCsvEscapeChar()) { |
51 | 47 | return fputcsv($handle, $fields, $options['delimiter'], $options['enclosure'], $options['escape_char']); |
52 | 48 | } |
@@ -2,8 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace Gettext\Utils; |
4 | 4 | |
5 | -class StringReader |
|
6 | -{ |
|
5 | +class StringReader { |
|
7 | 6 | public $pos; |
8 | 7 | public $str; |
9 | 8 | public $strlen; |
@@ -13,8 +12,7 @@ discard block |
||
13 | 12 | * |
14 | 13 | * @param string $str The string to read |
15 | 14 | */ |
16 | - public function __construct($str) |
|
17 | - { |
|
15 | + public function __construct($str) { |
|
18 | 16 | $this->str = $str; |
19 | 17 | $this->strlen = strlen($this->str); |
20 | 18 | } |
@@ -26,8 +24,7 @@ discard block |
||
26 | 24 | * |
27 | 25 | * @return string |
28 | 26 | */ |
29 | - public function read($bytes) |
|
30 | - { |
|
27 | + public function read($bytes) { |
|
31 | 28 | $data = substr($this->str, $this->pos, $bytes); |
32 | 29 | |
33 | 30 | $this->seekto($this->pos + $bytes); |
@@ -42,8 +39,7 @@ discard block |
||
42 | 39 | * |
43 | 40 | * @return int The new position |
44 | 41 | */ |
45 | - public function seekto($pos) |
|
46 | - { |
|
42 | + public function seekto($pos) { |
|
47 | 43 | $this->pos = ($this->strlen < $pos) ? $this->strlen : $pos; |
48 | 44 | |
49 | 45 | return $this->pos; |
@@ -5,8 +5,7 @@ discard block |
||
5 | 5 | /** |
6 | 6 | * Function parsed by PhpFunctionsScanner. |
7 | 7 | */ |
8 | -class ParsedFunction |
|
9 | -{ |
|
8 | +class ParsedFunction { |
|
10 | 9 | /** |
11 | 10 | * The function name. |
12 | 11 | * |
@@ -55,8 +54,7 @@ discard block |
||
55 | 54 | * @param string $name The function name. |
56 | 55 | * @param int $line The line where the function starts. |
57 | 56 | */ |
58 | - public function __construct($name, $line) |
|
59 | - { |
|
57 | + public function __construct($name, $line) { |
|
60 | 58 | $this->name = $name; |
61 | 59 | $this->line = $line; |
62 | 60 | $this->arguments = []; |
@@ -68,8 +66,7 @@ discard block |
||
68 | 66 | /** |
69 | 67 | * Stop extracting strings from the current argument (because we found something that's not a string). |
70 | 68 | */ |
71 | - public function stopArgument() |
|
72 | - { |
|
69 | + public function stopArgument() { |
|
73 | 70 | if ($this->argumentIndex === -1) { |
74 | 71 | $this->argumentIndex = 0; |
75 | 72 | } |
@@ -79,8 +76,7 @@ discard block |
||
79 | 76 | /** |
80 | 77 | * Go to the next argument because we a comma was found. |
81 | 78 | */ |
82 | - public function nextArgument() |
|
83 | - { |
|
79 | + public function nextArgument() { |
|
84 | 80 | if ($this->argumentIndex === -1) { |
85 | 81 | // This should neve occur, but let's stay safe - During test/development an Exception should be thrown. |
86 | 82 | $this->argumentIndex = 1; |
@@ -95,8 +91,7 @@ discard block |
||
95 | 91 | * |
96 | 92 | * @param string|null $chunk |
97 | 93 | */ |
98 | - public function addArgumentChunk($chunk) |
|
99 | - { |
|
94 | + public function addArgumentChunk($chunk) { |
|
100 | 95 | if ($this->argumentStopped === false) { |
101 | 96 | if ($this->argumentIndex === -1) { |
102 | 97 | $this->argumentIndex = 0; |
@@ -114,8 +109,7 @@ discard block |
||
114 | 109 | * |
115 | 110 | * @param ParsedComment $comment |
116 | 111 | */ |
117 | - public function addComment($comment) |
|
118 | - { |
|
112 | + public function addComment($comment) { |
|
119 | 113 | if ($this->comments === null) { |
120 | 114 | $this->comments = []; |
121 | 115 | } |
@@ -127,8 +121,7 @@ discard block |
||
127 | 121 | * |
128 | 122 | * @return int Line number. |
129 | 123 | */ |
130 | - public function getLine() |
|
131 | - { |
|
124 | + public function getLine() { |
|
132 | 125 | return $this->line; |
133 | 126 | } |
134 | 127 | |
@@ -142,8 +135,7 @@ discard block |
||
142 | 135 | * |
143 | 136 | * @return array |
144 | 137 | */ |
145 | - public function close() |
|
146 | - { |
|
138 | + public function close() { |
|
147 | 139 | $arguments = []; |
148 | 140 | for ($i = 0; $i <= $this->argumentIndex; ++$i) { |
149 | 141 | $arguments[$i] = isset($this->arguments[$i]) ? $this->arguments[$i] : null; |
@@ -4,8 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | use Gettext\Extractors\PhpCode; |
6 | 6 | |
7 | -class PhpFunctionsScanner extends FunctionsScanner |
|
8 | -{ |
|
7 | +class PhpFunctionsScanner extends FunctionsScanner { |
|
9 | 8 | /** |
10 | 9 | * PHP tokens of the code to be parsed. |
11 | 10 | * |
@@ -25,16 +24,14 @@ discard block |
||
25 | 24 | * |
26 | 25 | * @param mixed $tag |
27 | 26 | */ |
28 | - public function enableCommentsExtraction($tag = '') |
|
29 | - { |
|
27 | + public function enableCommentsExtraction($tag = '') { |
|
30 | 28 | $this->extractComments = $tag; |
31 | 29 | } |
32 | 30 | |
33 | 31 | /** |
34 | 32 | * Disable comments extraction. |
35 | 33 | */ |
36 | - public function disableCommentsExtraction() |
|
37 | - { |
|
34 | + public function disableCommentsExtraction() { |
|
38 | 35 | $this->extractComments = false; |
39 | 36 | } |
40 | 37 | |
@@ -43,8 +40,7 @@ discard block |
||
43 | 40 | * |
44 | 41 | * @param string $code The php code to scan |
45 | 42 | */ |
46 | - public function __construct($code) |
|
47 | - { |
|
43 | + public function __construct($code) { |
|
48 | 44 | $this->tokens = array_values( |
49 | 45 | array_filter( |
50 | 46 | token_get_all($code), |
@@ -58,8 +54,7 @@ discard block |
||
58 | 54 | /** |
59 | 55 | * {@inheritdoc} |
60 | 56 | */ |
61 | - public function getFunctions(array $constants = []) |
|
62 | - { |
|
57 | + public function getFunctions(array $constants = []) { |
|
63 | 58 | $count = count($this->tokens); |
64 | 59 | /* @var ParsedFunction[] $bufferFunctions */ |
65 | 60 | $bufferFunctions = []; |
@@ -174,8 +169,7 @@ discard block |
||
174 | 169 | * |
175 | 170 | * @return null|ParsedComment Comment or null if comment extraction is disabled or if there is a prefix mismatch. |
176 | 171 | */ |
177 | - protected function parsePhpComment($value, $line) |
|
178 | - { |
|
172 | + protected function parsePhpComment($value, $line) { |
|
179 | 173 | if ($this->extractComments === false) { |
180 | 174 | return null; |
181 | 175 | } |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Trait to provide the functionality of extracting headers. |
9 | 9 | */ |
10 | -trait HeadersExtractorTrait |
|
11 | -{ |
|
10 | +trait HeadersExtractorTrait { |
|
12 | 11 | /** |
13 | 12 | * Add the headers found to the translations instance. |
14 | 13 | * |
@@ -17,8 +16,7 @@ discard block |
||
17 | 16 | * |
18 | 17 | * @return array |
19 | 18 | */ |
20 | - protected static function extractHeaders($headers, Translations $translations) |
|
21 | - { |
|
19 | + protected static function extractHeaders($headers, Translations $translations) { |
|
22 | 20 | $headers = explode("\n", $headers); |
23 | 21 | $currentHeader = null; |
24 | 22 | |
@@ -48,8 +46,7 @@ discard block |
||
48 | 46 | * |
49 | 47 | * @return bool |
50 | 48 | */ |
51 | - protected static function isHeaderDefinition($line) |
|
52 | - { |
|
49 | + protected static function isHeaderDefinition($line) { |
|
53 | 50 | return (bool) preg_match('/^[\w-]+:/', $line); |
54 | 51 | } |
55 | 52 | |
@@ -60,8 +57,7 @@ discard block |
||
60 | 57 | * |
61 | 58 | * @return string |
62 | 59 | */ |
63 | - public static function convertString($value) |
|
64 | - { |
|
60 | + public static function convertString($value) { |
|
65 | 61 | return $value; |
66 | 62 | } |
67 | 63 | } |