@@ -5,8 +5,7 @@ discard block |
||
5 | 5 | use Exception; |
6 | 6 | use Gettext\Translations; |
7 | 7 | |
8 | -abstract class FunctionsScanner |
|
9 | -{ |
|
8 | +abstract class FunctionsScanner { |
|
10 | 9 | /** |
11 | 10 | * Scan and returns the functions and the arguments. |
12 | 11 | * |
@@ -25,8 +24,7 @@ discard block |
||
25 | 24 | * @param array $options The extractor options |
26 | 25 | * @throws Exception |
27 | 26 | */ |
28 | - public function saveGettextFunctions($translations, array $options) |
|
29 | - { |
|
27 | + public function saveGettextFunctions($translations, array $options) { |
|
30 | 28 | $translations = is_array($translations) ? $translations : [$translations]; |
31 | 29 | |
32 | 30 | /** @var Translations[] $translationByDomain [domain => translations, ..] */ |
@@ -107,8 +105,7 @@ discard block |
||
107 | 105 | * @return array|null |
108 | 106 | * @throws Exception |
109 | 107 | */ |
110 | - protected function deconstructArgs($function, $args) |
|
111 | - { |
|
108 | + protected function deconstructArgs($function, $args) { |
|
112 | 109 | $domain = null; |
113 | 110 | $context = null; |
114 | 111 | $original = null; |
@@ -8,8 +8,7 @@ discard block |
||
8 | 8 | * Trait used by all generators that exports the translations to multidimensional arrays |
9 | 9 | * (context => [original => [translation, plural1, pluraln...]]). |
10 | 10 | */ |
11 | -trait MultidimensionalArrayTrait |
|
12 | -{ |
|
11 | +trait MultidimensionalArrayTrait { |
|
13 | 12 | use HeadersGeneratorTrait; |
14 | 13 | use HeadersExtractorTrait; |
15 | 14 | |
@@ -22,8 +21,7 @@ discard block |
||
22 | 21 | * |
23 | 22 | * @return array |
24 | 23 | */ |
25 | - protected static function toArray(Translations $translations, $includeHeaders, $forceArray = false) |
|
26 | - { |
|
24 | + protected static function toArray(Translations $translations, $includeHeaders, $forceArray = false) { |
|
27 | 25 | $pluralForm = $translations->getPluralForms(); |
28 | 26 | $pluralSize = is_array($pluralForm) ? ($pluralForm[0] - 1) : null; |
29 | 27 | $messages = []; |
@@ -69,8 +67,7 @@ discard block |
||
69 | 67 | * @param array $messages |
70 | 68 | * @param Translations $translations |
71 | 69 | */ |
72 | - protected static function fromArray(array $messages, Translations $translations) |
|
73 | - { |
|
70 | + protected static function fromArray(array $messages, Translations $translations) { |
|
74 | 71 | if (!empty($messages['domain'])) { |
75 | 72 | $translations->setDomain($messages['domain']); |
76 | 73 | } |
@@ -5,8 +5,7 @@ discard block |
||
5 | 5 | /** |
6 | 6 | * Static class with merge contants. |
7 | 7 | */ |
8 | -final class Merge |
|
9 | -{ |
|
8 | +final class Merge { |
|
10 | 9 | const ADD = 1; |
11 | 10 | const REMOVE = 2; |
12 | 11 | |
@@ -39,8 +38,7 @@ discard block |
||
39 | 38 | * @param Translation $to |
40 | 39 | * @param int $options |
41 | 40 | */ |
42 | - public static function mergeFlags(Translation $from, Translation $to, $options = self::DEFAULTS) |
|
43 | - { |
|
41 | + public static function mergeFlags(Translation $from, Translation $to, $options = self::DEFAULTS) { |
|
44 | 42 | if ($options & self::FLAGS_THEIRS) { |
45 | 43 | $to->deleteFlags(); |
46 | 44 | } |
@@ -59,8 +57,7 @@ discard block |
||
59 | 57 | * @param Translation $to |
60 | 58 | * @param int $options |
61 | 59 | */ |
62 | - public static function mergeExtractedComments(Translation $from, Translation $to, $options = self::DEFAULTS) |
|
63 | - { |
|
60 | + public static function mergeExtractedComments(Translation $from, Translation $to, $options = self::DEFAULTS) { |
|
64 | 61 | if ($options & self::EXTRACTED_COMMENTS_THEIRS) { |
65 | 62 | $to->deleteExtractedComments(); |
66 | 63 | } |
@@ -79,8 +76,7 @@ discard block |
||
79 | 76 | * @param Translation $to |
80 | 77 | * @param int $options |
81 | 78 | */ |
82 | - public static function mergeComments(Translation $from, Translation $to, $options = self::DEFAULTS) |
|
83 | - { |
|
79 | + public static function mergeComments(Translation $from, Translation $to, $options = self::DEFAULTS) { |
|
84 | 80 | if ($options & self::COMMENTS_THEIRS) { |
85 | 81 | $to->deleteComments(); |
86 | 82 | } |
@@ -99,8 +95,7 @@ discard block |
||
99 | 95 | * @param Translation $to |
100 | 96 | * @param int $options |
101 | 97 | */ |
102 | - public static function mergeReferences(Translation $from, Translation $to, $options = self::DEFAULTS) |
|
103 | - { |
|
98 | + public static function mergeReferences(Translation $from, Translation $to, $options = self::DEFAULTS) { |
|
104 | 99 | if ($options & self::REFERENCES_THEIRS) { |
105 | 100 | $to->deleteReferences(); |
106 | 101 | } |
@@ -119,8 +114,7 @@ discard block |
||
119 | 114 | * @param Translation $to |
120 | 115 | * @param int $options |
121 | 116 | */ |
122 | - public static function mergeTranslation(Translation $from, Translation $to, $options = self::DEFAULTS) |
|
123 | - { |
|
117 | + public static function mergeTranslation(Translation $from, Translation $to, $options = self::DEFAULTS) { |
|
124 | 118 | $override = (boolean) ($options & self::TRANSLATION_OVERRIDE); |
125 | 119 | |
126 | 120 | if (!$to->hasTranslation() || ($from->hasTranslation() && $override)) { |
@@ -143,8 +137,7 @@ discard block |
||
143 | 137 | * @param Translations $to |
144 | 138 | * @param int $options |
145 | 139 | */ |
146 | - public static function mergeTranslations(Translations $from, Translations $to, $options = self::DEFAULTS) |
|
147 | - { |
|
140 | + public static function mergeTranslations(Translations $from, Translations $to, $options = self::DEFAULTS) { |
|
148 | 141 | if ($options & self::REMOVE) { |
149 | 142 | $filtered = []; |
150 | 143 | |
@@ -173,8 +166,7 @@ discard block |
||
173 | 166 | * @param Translations $to |
174 | 167 | * @param int $options |
175 | 168 | */ |
176 | - public static function mergeHeaders(Translations $from, Translations $to, $options = self::DEFAULTS) |
|
177 | - { |
|
169 | + public static function mergeHeaders(Translations $from, Translations $to, $options = self::DEFAULTS) { |
|
178 | 170 | if ($options & self::HEADERS_REMOVE) { |
179 | 171 | foreach (array_keys($to->getHeaders()) as $name) { |
180 | 172 | if ($from->getHeader($name) === null) { |
@@ -4,8 +4,7 @@ discard block |
||
4 | 4 | |
5 | 5 | use Gettext\Generators\PhpArray; |
6 | 6 | |
7 | -class Translator extends BaseTranslator implements TranslatorInterface |
|
8 | -{ |
|
7 | +class Translator extends BaseTranslator implements TranslatorInterface { |
|
9 | 8 | protected $domain; |
10 | 9 | protected $dictionary = []; |
11 | 10 | protected $plurals = []; |
@@ -17,8 +16,7 @@ discard block |
||
17 | 16 | * |
18 | 17 | * @return static |
19 | 18 | */ |
20 | - public function loadTranslations($translations) |
|
21 | - { |
|
19 | + public function loadTranslations($translations) { |
|
22 | 20 | if (is_object($translations) && $translations instanceof Translations) { |
23 | 21 | $translations = PhpArray::generate($translations, ['includeHeaders' => false]); |
24 | 22 | } elseif (is_string($translations) && is_file($translations)) { |
@@ -41,8 +39,7 @@ discard block |
||
41 | 39 | * |
42 | 40 | * @return static |
43 | 41 | */ |
44 | - public function defaultDomain($domain) |
|
45 | - { |
|
42 | + public function defaultDomain($domain) { |
|
46 | 43 | $this->domain = $domain; |
47 | 44 | |
48 | 45 | return $this; |
@@ -53,8 +50,7 @@ discard block |
||
53 | 50 | * |
54 | 51 | * {@inheritdoc} |
55 | 52 | */ |
56 | - public function gettext($original) |
|
57 | - { |
|
53 | + public function gettext($original) { |
|
58 | 54 | return $this->dpgettext($this->domain, null, $original); |
59 | 55 | } |
60 | 56 | |
@@ -63,8 +59,7 @@ discard block |
||
63 | 59 | * |
64 | 60 | * {@inheritdoc} |
65 | 61 | */ |
66 | - public function ngettext($original, $plural, $value) |
|
67 | - { |
|
62 | + public function ngettext($original, $plural, $value) { |
|
68 | 63 | return $this->dnpgettext($this->domain, null, $original, $plural, $value); |
69 | 64 | } |
70 | 65 | |
@@ -73,8 +68,7 @@ discard block |
||
73 | 68 | * |
74 | 69 | * {@inheritdoc} |
75 | 70 | */ |
76 | - public function dngettext($domain, $original, $plural, $value) |
|
77 | - { |
|
71 | + public function dngettext($domain, $original, $plural, $value) { |
|
78 | 72 | return $this->dnpgettext($domain, null, $original, $plural, $value); |
79 | 73 | } |
80 | 74 | |
@@ -83,8 +77,7 @@ discard block |
||
83 | 77 | * |
84 | 78 | * {@inheritdoc} |
85 | 79 | */ |
86 | - public function npgettext($context, $original, $plural, $value) |
|
87 | - { |
|
80 | + public function npgettext($context, $original, $plural, $value) { |
|
88 | 81 | return $this->dnpgettext($this->domain, $context, $original, $plural, $value); |
89 | 82 | } |
90 | 83 | |
@@ -93,8 +86,7 @@ discard block |
||
93 | 86 | * |
94 | 87 | * {@inheritdoc} |
95 | 88 | */ |
96 | - public function pgettext($context, $original) |
|
97 | - { |
|
89 | + public function pgettext($context, $original) { |
|
98 | 90 | return $this->dpgettext($this->domain, $context, $original); |
99 | 91 | } |
100 | 92 | |
@@ -103,8 +95,7 @@ discard block |
||
103 | 95 | * |
104 | 96 | * {@inheritdoc} |
105 | 97 | */ |
106 | - public function dgettext($domain, $original) |
|
107 | - { |
|
98 | + public function dgettext($domain, $original) { |
|
108 | 99 | return $this->dpgettext($domain, null, $original); |
109 | 100 | } |
110 | 101 | |
@@ -113,8 +104,7 @@ discard block |
||
113 | 104 | * |
114 | 105 | * {@inheritdoc} |
115 | 106 | */ |
116 | - public function dpgettext($domain, $context, $original) |
|
117 | - { |
|
107 | + public function dpgettext($domain, $context, $original) { |
|
118 | 108 | $translation = $this->getTranslation($domain, $context, $original); |
119 | 109 | |
120 | 110 | if (isset($translation[0]) && $translation[0] !== '') { |
@@ -129,8 +119,7 @@ discard block |
||
129 | 119 | * |
130 | 120 | * {@inheritdoc} |
131 | 121 | */ |
132 | - public function dnpgettext($domain, $context, $original, $plural, $value) |
|
133 | - { |
|
122 | + public function dnpgettext($domain, $context, $original, $plural, $value) { |
|
134 | 123 | $translation = $this->getTranslation($domain, $context, $original); |
135 | 124 | $key = $this->getPluralIndex($domain, $value, $translation === false); |
136 | 125 | |
@@ -146,8 +135,7 @@ discard block |
||
146 | 135 | * |
147 | 136 | * @param array $translations |
148 | 137 | */ |
149 | - protected function addTranslations(array $translations) |
|
150 | - { |
|
138 | + protected function addTranslations(array $translations) { |
|
151 | 139 | $domain = isset($translations['domain']) ? $translations['domain'] : ''; |
152 | 140 | |
153 | 141 | //Set the first domain loaded as default domain |
@@ -184,8 +172,7 @@ discard block |
||
184 | 172 | * |
185 | 173 | * @return string|false |
186 | 174 | */ |
187 | - protected function getTranslation($domain, $context, $original) |
|
188 | - { |
|
175 | + protected function getTranslation($domain, $context, $original) { |
|
189 | 176 | return isset($this->dictionary[$domain][$context][$original]) |
190 | 177 | ? $this->dictionary[$domain][$context][$original] |
191 | 178 | : false; |
@@ -201,8 +188,7 @@ discard block |
||
201 | 188 | * |
202 | 189 | * @return int |
203 | 190 | */ |
204 | - protected function getPluralIndex($domain, $n, $fallback) |
|
205 | - { |
|
191 | + protected function getPluralIndex($domain, $n, $fallback) { |
|
206 | 192 | //Not loaded domain or translation, use a fallback |
207 | 193 | if (!isset($this->plurals[$domain]) || $fallback === true) { |
208 | 194 | return $n == 1 ? 0 : 1; |
@@ -236,8 +222,7 @@ discard block |
||
236 | 222 | * |
237 | 223 | * @return string A formatted terse If that PHP can work with. |
238 | 224 | */ |
239 | - private static function fixTerseIfs($code, $inner = false) |
|
240 | - { |
|
225 | + private static function fixTerseIfs($code, $inner = false) { |
|
241 | 226 | /* |
242 | 227 | * (?P<expression>[^?]+) Capture everything up to ? as 'expression' |
243 | 228 | * \? ? |
@@ -9,15 +9,13 @@ discard block |
||
9 | 9 | /** |
10 | 10 | * Class to get gettext strings from php files returning arrays. |
11 | 11 | */ |
12 | -class PhpArray extends Extractor implements ExtractorInterface |
|
13 | -{ |
|
12 | +class PhpArray extends Extractor implements ExtractorInterface { |
|
14 | 13 | use MultidimensionalArrayTrait; |
15 | 14 | |
16 | 15 | /** |
17 | 16 | * {@inheritdoc} |
18 | 17 | */ |
19 | - public static function fromFile($file, Translations $translations, array $options = []) |
|
20 | - { |
|
18 | + public static function fromFile($file, Translations $translations, array $options = []) { |
|
21 | 19 | foreach (static::getFiles($file) as $file) { |
22 | 20 | static::fromArray(include($file), $translations); |
23 | 21 | } |
@@ -26,8 +24,7 @@ discard block |
||
26 | 24 | /** |
27 | 25 | * {@inheritdoc} |
28 | 26 | */ |
29 | - public static function fromString($string, Translations $translations, array $options = []) |
|
30 | - { |
|
27 | + public static function fromString($string, Translations $translations, array $options = []) { |
|
31 | 28 | throw new BadMethodCallException('PhpArray::fromString() cannot be called. Use PhpArray::fromFile()'); |
32 | 29 | } |
33 | 30 | } |
@@ -9,8 +9,7 @@ discard block |
||
9 | 9 | /** |
10 | 10 | * Class to get gettext strings from csv. |
11 | 11 | */ |
12 | -class CsvDictionary extends Extractor implements ExtractorInterface |
|
13 | -{ |
|
12 | +class CsvDictionary extends Extractor implements ExtractorInterface { |
|
14 | 13 | use HeadersExtractorTrait; |
15 | 14 | use CsvTrait; |
16 | 15 | |
@@ -23,8 +22,7 @@ discard block |
||
23 | 22 | /** |
24 | 23 | * {@inheritdoc} |
25 | 24 | */ |
26 | - public static function fromString($string, Translations $translations, array $options = []) |
|
27 | - { |
|
25 | + public static function fromString($string, Translations $translations, array $options = []) { |
|
28 | 26 | $options += static::$options; |
29 | 27 | $handle = fopen('php://memory', 'w'); |
30 | 28 |
@@ -42,8 +42,7 @@ discard block |
||
42 | 42 | * @inheritdoc |
43 | 43 | * @throws Exception |
44 | 44 | */ |
45 | - public static function fromString($string, Translations $translations, array $options = []) |
|
46 | - { |
|
45 | + public static function fromString($string, Translations $translations, array $options = []) { |
|
47 | 46 | static::fromStringMultiple($string, [$translations], $options); |
48 | 47 | } |
49 | 48 | |
@@ -51,8 +50,7 @@ discard block |
||
51 | 50 | * @inheritDoc |
52 | 51 | * @throws Exception |
53 | 52 | */ |
54 | - public static function fromStringMultiple($string, array $translations, array $options = []) |
|
55 | - { |
|
53 | + public static function fromStringMultiple($string, array $translations, array $options = []) { |
|
56 | 54 | $options += static::$options; |
57 | 55 | |
58 | 56 | /** @var FunctionsScanner $functions */ |
@@ -64,8 +62,7 @@ discard block |
||
64 | 62 | * @inheritDoc |
65 | 63 | * @throws Exception |
66 | 64 | */ |
67 | - public static function fromFileMultiple($file, array $translations, array $options = []) |
|
68 | - { |
|
65 | + public static function fromFileMultiple($file, array $translations, array $options = []) { |
|
69 | 66 | foreach (static::getFiles($file) as $file) { |
70 | 67 | $options['file'] = $file; |
71 | 68 | static::fromStringMultiple(static::readFile($file), $translations, $options); |
@@ -9,8 +9,7 @@ discard block |
||
9 | 9 | /** |
10 | 10 | * Class to get gettext strings from xliff format. |
11 | 11 | */ |
12 | -class Xliff extends Extractor implements ExtractorInterface |
|
13 | -{ |
|
12 | +class Xliff extends Extractor implements ExtractorInterface { |
|
14 | 13 | |
15 | 14 | public static $options = [ |
16 | 15 | 'unitid_as_id' => false |
@@ -19,8 +18,7 @@ discard block |
||
19 | 18 | /** |
20 | 19 | * {@inheritdoc} |
21 | 20 | */ |
22 | - public static function fromString($string, Translations $translations, array $options = []) |
|
23 | - { |
|
21 | + public static function fromString($string, Translations $translations, array $options = []) { |
|
24 | 22 | $options += static::$options; |
25 | 23 | |
26 | 24 | $xml = new SimpleXMLElement($string, null, false); |
@@ -9,15 +9,13 @@ |
||
9 | 9 | /** |
10 | 10 | * Class to get gettext strings from yaml. |
11 | 11 | */ |
12 | -class YamlDictionary extends Extractor implements ExtractorInterface |
|
13 | -{ |
|
12 | +class YamlDictionary extends Extractor implements ExtractorInterface { |
|
14 | 13 | use DictionaryTrait; |
15 | 14 | |
16 | 15 | /** |
17 | 16 | * {@inheritdoc} |
18 | 17 | */ |
19 | - public static function fromString($string, Translations $translations, array $options = []) |
|
20 | - { |
|
18 | + public static function fromString($string, Translations $translations, array $options = []) { |
|
21 | 19 | $messages = YamlParser::parse($string); |
22 | 20 | |
23 | 21 | if (is_array($messages)) { |