@@ -6,27 +6,27 @@ |
||
6 | 6 | |
7 | 7 | class Prettyjson extends Json |
8 | 8 | { |
9 | - /** |
|
10 | - * {@inheritdoc} |
|
11 | - * |
|
12 | - * @see \Gettext\Languages\Exporter\Exporter::getDescription() |
|
13 | - */ |
|
14 | - public static function getDescription() |
|
15 | - { |
|
16 | - return 'Build an uncompressed JSON-encoded file (PHP 5.4 or later is needed)'; |
|
17 | - } |
|
9 | + /** |
|
10 | + * {@inheritdoc} |
|
11 | + * |
|
12 | + * @see \Gettext\Languages\Exporter\Exporter::getDescription() |
|
13 | + */ |
|
14 | + public static function getDescription() |
|
15 | + { |
|
16 | + return 'Build an uncompressed JSON-encoded file (PHP 5.4 or later is needed)'; |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * {@inheritdoc} |
|
21 | - * |
|
22 | - * @see \Gettext\Languages\Exporter\Json::getEncodeOptions() |
|
23 | - */ |
|
24 | - protected static function getEncodeOptions() |
|
25 | - { |
|
26 | - if (!(defined('\JSON_PRETTY_PRINT') && defined('\JSON_UNESCAPED_SLASHES') && defined('\JSON_UNESCAPED_UNICODE'))) { |
|
27 | - throw new Exception('PHP 5.4 or later is required to export uncompressed JSON'); |
|
28 | - } |
|
19 | + /** |
|
20 | + * {@inheritdoc} |
|
21 | + * |
|
22 | + * @see \Gettext\Languages\Exporter\Json::getEncodeOptions() |
|
23 | + */ |
|
24 | + protected static function getEncodeOptions() |
|
25 | + { |
|
26 | + if (!(defined('\JSON_PRETTY_PRINT') && defined('\JSON_UNESCAPED_SLASHES') && defined('\JSON_UNESCAPED_UNICODE'))) { |
|
27 | + throw new Exception('PHP 5.4 or later is required to export uncompressed JSON'); |
|
28 | + } |
|
29 | 29 | |
30 | - return \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE; |
|
31 | - } |
|
30 | + return \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE; |
|
31 | + } |
|
32 | 32 | } |
@@ -23,8 +23,8 @@ |
||
23 | 23 | */ |
24 | 24 | protected static function getEncodeOptions() |
25 | 25 | { |
26 | - if (!(defined('\JSON_PRETTY_PRINT') && defined('\JSON_UNESCAPED_SLASHES') && defined('\JSON_UNESCAPED_UNICODE'))) { |
|
27 | - throw new Exception('PHP 5.4 or later is required to export uncompressed JSON'); |
|
26 | + if ( ! ( defined( '\JSON_PRETTY_PRINT' ) && defined( '\JSON_UNESCAPED_SLASHES' ) && defined( '\JSON_UNESCAPED_UNICODE' ) ) ) { |
|
27 | + throw new Exception( 'PHP 5.4 or later is required to export uncompressed JSON' ); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | return \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE; |
@@ -4,15 +4,13 @@ discard block |
||
4 | 4 | |
5 | 5 | use Exception; |
6 | 6 | |
7 | -class Prettyjson extends Json |
|
8 | -{ |
|
7 | +class Prettyjson extends Json { |
|
9 | 8 | /** |
10 | 9 | * {@inheritdoc} |
11 | 10 | * |
12 | 11 | * @see \Gettext\Languages\Exporter\Exporter::getDescription() |
13 | 12 | */ |
14 | - public static function getDescription() |
|
15 | - { |
|
13 | + public static function getDescription() { |
|
16 | 14 | return 'Build an uncompressed JSON-encoded file (PHP 5.4 or later is needed)'; |
17 | 15 | } |
18 | 16 | |
@@ -21,8 +19,7 @@ discard block |
||
21 | 19 | * |
22 | 20 | * @see \Gettext\Languages\Exporter\Json::getEncodeOptions() |
23 | 21 | */ |
24 | - protected static function getEncodeOptions() |
|
25 | - { |
|
22 | + protected static function getEncodeOptions() { |
|
26 | 23 | if (!(defined('\JSON_PRETTY_PRINT') && defined('\JSON_UNESCAPED_SLASHES') && defined('\JSON_UNESCAPED_UNICODE'))) { |
27 | 24 | throw new Exception('PHP 5.4 or later is required to export uncompressed JSON'); |
28 | 25 | } |
@@ -4,57 +4,57 @@ |
||
4 | 4 | |
5 | 5 | class Ruby extends Exporter |
6 | 6 | { |
7 | - /** |
|
8 | - * {@inheritdoc} |
|
9 | - * |
|
10 | - * @see \Gettext\Languages\Exporter\Exporter::getDescription() |
|
11 | - */ |
|
12 | - public static function getDescription() |
|
13 | - { |
|
14 | - return 'Build a Ruby hash'; |
|
15 | - } |
|
7 | + /** |
|
8 | + * {@inheritdoc} |
|
9 | + * |
|
10 | + * @see \Gettext\Languages\Exporter\Exporter::getDescription() |
|
11 | + */ |
|
12 | + public static function getDescription() |
|
13 | + { |
|
14 | + return 'Build a Ruby hash'; |
|
15 | + } |
|
16 | 16 | |
17 | - /** |
|
18 | - * {@inheritdoc} |
|
19 | - * |
|
20 | - * @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
|
21 | - */ |
|
22 | - protected static function toStringDo($languages) |
|
23 | - { |
|
24 | - $lines = array(); |
|
25 | - $lines[] = 'PLURAL_RULES = {'; |
|
26 | - foreach ($languages as $lc) { |
|
27 | - $lines[] = ' \'' . $lc->id . '\' => {'; |
|
28 | - $lines[] = ' \'name\' => \'' . addslashes($lc->name) . '\','; |
|
29 | - if (isset($lc->supersededBy)) { |
|
30 | - $lines[] = ' \'supersededBy\' => \'' . $lc->supersededBy . '\','; |
|
31 | - } |
|
32 | - if (isset($lc->script)) { |
|
33 | - $lines[] = ' \'script\' => \'' . addslashes($lc->script) . '\','; |
|
34 | - } |
|
35 | - if (isset($lc->territory)) { |
|
36 | - $lines[] = ' \'territory\' => \'' . addslashes($lc->territory) . '\','; |
|
37 | - } |
|
38 | - if (isset($lc->baseLanguage)) { |
|
39 | - $lines[] = ' \'baseLanguage\' => \'' . addslashes($lc->baseLanguage) . '\','; |
|
40 | - } |
|
41 | - $lines[] = ' \'formula\' => \'' . $lc->formula . '\','; |
|
42 | - $lines[] = ' \'plurals\' => ' . count($lc->categories) . ','; |
|
43 | - $catNames = array(); |
|
44 | - foreach ($lc->categories as $c) { |
|
45 | - $catNames[] = "'{$c->id}'"; |
|
46 | - } |
|
47 | - $lines[] = ' \'cases\' => [' . implode(', ', $catNames) . '],'; |
|
48 | - $lines[] = ' \'examples\' => {'; |
|
49 | - foreach ($lc->categories as $c) { |
|
50 | - $lines[] = ' \'' . $c->id . '\' => \'' . $c->examples . '\','; |
|
51 | - } |
|
52 | - $lines[] = ' },'; |
|
53 | - $lines[] = ' },'; |
|
54 | - } |
|
55 | - $lines[] = '}'; |
|
56 | - $lines[] = ''; |
|
17 | + /** |
|
18 | + * {@inheritdoc} |
|
19 | + * |
|
20 | + * @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
|
21 | + */ |
|
22 | + protected static function toStringDo($languages) |
|
23 | + { |
|
24 | + $lines = array(); |
|
25 | + $lines[] = 'PLURAL_RULES = {'; |
|
26 | + foreach ($languages as $lc) { |
|
27 | + $lines[] = ' \'' . $lc->id . '\' => {'; |
|
28 | + $lines[] = ' \'name\' => \'' . addslashes($lc->name) . '\','; |
|
29 | + if (isset($lc->supersededBy)) { |
|
30 | + $lines[] = ' \'supersededBy\' => \'' . $lc->supersededBy . '\','; |
|
31 | + } |
|
32 | + if (isset($lc->script)) { |
|
33 | + $lines[] = ' \'script\' => \'' . addslashes($lc->script) . '\','; |
|
34 | + } |
|
35 | + if (isset($lc->territory)) { |
|
36 | + $lines[] = ' \'territory\' => \'' . addslashes($lc->territory) . '\','; |
|
37 | + } |
|
38 | + if (isset($lc->baseLanguage)) { |
|
39 | + $lines[] = ' \'baseLanguage\' => \'' . addslashes($lc->baseLanguage) . '\','; |
|
40 | + } |
|
41 | + $lines[] = ' \'formula\' => \'' . $lc->formula . '\','; |
|
42 | + $lines[] = ' \'plurals\' => ' . count($lc->categories) . ','; |
|
43 | + $catNames = array(); |
|
44 | + foreach ($lc->categories as $c) { |
|
45 | + $catNames[] = "'{$c->id}'"; |
|
46 | + } |
|
47 | + $lines[] = ' \'cases\' => [' . implode(', ', $catNames) . '],'; |
|
48 | + $lines[] = ' \'examples\' => {'; |
|
49 | + foreach ($lc->categories as $c) { |
|
50 | + $lines[] = ' \'' . $c->id . '\' => \'' . $c->examples . '\','; |
|
51 | + } |
|
52 | + $lines[] = ' },'; |
|
53 | + $lines[] = ' },'; |
|
54 | + } |
|
55 | + $lines[] = '}'; |
|
56 | + $lines[] = ''; |
|
57 | 57 | |
58 | - return implode("\n", $lines); |
|
59 | - } |
|
58 | + return implode("\n", $lines); |
|
59 | + } |
|
60 | 60 | } |
@@ -19,42 +19,42 @@ |
||
19 | 19 | * |
20 | 20 | * @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
21 | 21 | */ |
22 | - protected static function toStringDo($languages) |
|
22 | + protected static function toStringDo( $languages ) |
|
23 | 23 | { |
24 | 24 | $lines = array(); |
25 | - $lines[] = 'PLURAL_RULES = {'; |
|
26 | - foreach ($languages as $lc) { |
|
27 | - $lines[] = ' \'' . $lc->id . '\' => {'; |
|
28 | - $lines[] = ' \'name\' => \'' . addslashes($lc->name) . '\','; |
|
29 | - if (isset($lc->supersededBy)) { |
|
30 | - $lines[] = ' \'supersededBy\' => \'' . $lc->supersededBy . '\','; |
|
25 | + $lines[ ] = 'PLURAL_RULES = {'; |
|
26 | + foreach ( $languages as $lc ) { |
|
27 | + $lines[ ] = ' \'' . $lc->id . '\' => {'; |
|
28 | + $lines[ ] = ' \'name\' => \'' . addslashes( $lc->name ) . '\','; |
|
29 | + if ( isset( $lc->supersededBy ) ) { |
|
30 | + $lines[ ] = ' \'supersededBy\' => \'' . $lc->supersededBy . '\','; |
|
31 | 31 | } |
32 | - if (isset($lc->script)) { |
|
33 | - $lines[] = ' \'script\' => \'' . addslashes($lc->script) . '\','; |
|
32 | + if ( isset( $lc->script ) ) { |
|
33 | + $lines[ ] = ' \'script\' => \'' . addslashes( $lc->script ) . '\','; |
|
34 | 34 | } |
35 | - if (isset($lc->territory)) { |
|
36 | - $lines[] = ' \'territory\' => \'' . addslashes($lc->territory) . '\','; |
|
35 | + if ( isset( $lc->territory ) ) { |
|
36 | + $lines[ ] = ' \'territory\' => \'' . addslashes( $lc->territory ) . '\','; |
|
37 | 37 | } |
38 | - if (isset($lc->baseLanguage)) { |
|
39 | - $lines[] = ' \'baseLanguage\' => \'' . addslashes($lc->baseLanguage) . '\','; |
|
38 | + if ( isset( $lc->baseLanguage ) ) { |
|
39 | + $lines[ ] = ' \'baseLanguage\' => \'' . addslashes( $lc->baseLanguage ) . '\','; |
|
40 | 40 | } |
41 | - $lines[] = ' \'formula\' => \'' . $lc->formula . '\','; |
|
42 | - $lines[] = ' \'plurals\' => ' . count($lc->categories) . ','; |
|
41 | + $lines[ ] = ' \'formula\' => \'' . $lc->formula . '\','; |
|
42 | + $lines[ ] = ' \'plurals\' => ' . count( $lc->categories ) . ','; |
|
43 | 43 | $catNames = array(); |
44 | - foreach ($lc->categories as $c) { |
|
45 | - $catNames[] = "'{$c->id}'"; |
|
44 | + foreach ( $lc->categories as $c ) { |
|
45 | + $catNames[ ] = "'{$c->id}'"; |
|
46 | 46 | } |
47 | - $lines[] = ' \'cases\' => [' . implode(', ', $catNames) . '],'; |
|
48 | - $lines[] = ' \'examples\' => {'; |
|
49 | - foreach ($lc->categories as $c) { |
|
50 | - $lines[] = ' \'' . $c->id . '\' => \'' . $c->examples . '\','; |
|
47 | + $lines[ ] = ' \'cases\' => [' . implode( ', ', $catNames ) . '],'; |
|
48 | + $lines[ ] = ' \'examples\' => {'; |
|
49 | + foreach ( $lc->categories as $c ) { |
|
50 | + $lines[ ] = ' \'' . $c->id . '\' => \'' . $c->examples . '\','; |
|
51 | 51 | } |
52 | - $lines[] = ' },'; |
|
53 | - $lines[] = ' },'; |
|
52 | + $lines[ ] = ' },'; |
|
53 | + $lines[ ] = ' },'; |
|
54 | 54 | } |
55 | - $lines[] = '}'; |
|
56 | - $lines[] = ''; |
|
55 | + $lines[ ] = '}'; |
|
56 | + $lines[ ] = ''; |
|
57 | 57 | |
58 | - return implode("\n", $lines); |
|
58 | + return implode( "\n", $lines ); |
|
59 | 59 | } |
60 | 60 | } |
@@ -2,15 +2,13 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace Gettext\Languages\Exporter; |
4 | 4 | |
5 | -class Ruby extends Exporter |
|
6 | -{ |
|
5 | +class Ruby extends Exporter { |
|
7 | 6 | /** |
8 | 7 | * {@inheritdoc} |
9 | 8 | * |
10 | 9 | * @see \Gettext\Languages\Exporter\Exporter::getDescription() |
11 | 10 | */ |
12 | - public static function getDescription() |
|
13 | - { |
|
11 | + public static function getDescription() { |
|
14 | 12 | return 'Build a Ruby hash'; |
15 | 13 | } |
16 | 14 | |
@@ -19,8 +17,7 @@ discard block |
||
19 | 17 | * |
20 | 18 | * @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
21 | 19 | */ |
22 | - protected static function toStringDo($languages) |
|
23 | - { |
|
20 | + protected static function toStringDo($languages) { |
|
24 | 21 | $lines = array(); |
25 | 22 | $lines[] = 'PLURAL_RULES = {'; |
26 | 23 | foreach ($languages as $lc) { |
@@ -9,116 +9,116 @@ |
||
9 | 9 | */ |
10 | 10 | class Category |
11 | 11 | { |
12 | - /** |
|
13 | - * The category identifier (eg 'zero', 'one', ..., 'other'). |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - public $id; |
|
12 | + /** |
|
13 | + * The category identifier (eg 'zero', 'one', ..., 'other'). |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + public $id; |
|
18 | 18 | |
19 | - /** |
|
20 | - * The gettext formula that identifies this category (null if and only if the category is 'other'). |
|
21 | - * |
|
22 | - * @var string|null |
|
23 | - */ |
|
24 | - public $formula; |
|
19 | + /** |
|
20 | + * The gettext formula that identifies this category (null if and only if the category is 'other'). |
|
21 | + * |
|
22 | + * @var string|null |
|
23 | + */ |
|
24 | + public $formula; |
|
25 | 25 | |
26 | - /** |
|
27 | - * The CLDR representation of some exemplar numeric ranges that satisfy this category. |
|
28 | - * |
|
29 | - * @var string|null |
|
30 | - */ |
|
31 | - public $examples; |
|
26 | + /** |
|
27 | + * The CLDR representation of some exemplar numeric ranges that satisfy this category. |
|
28 | + * |
|
29 | + * @var string|null |
|
30 | + */ |
|
31 | + public $examples; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Initialize the instance and parse the formula. |
|
35 | - * |
|
36 | - * @param string $cldrCategoryId the CLDR category identifier (eg 'pluralRule-count-one') |
|
37 | - * @param string $cldrFormulaAndExamples the CLDR formula and examples (eg 'i = 1 and v = 0 @integer 1') |
|
38 | - * |
|
39 | - * @throws \Exception |
|
40 | - */ |
|
41 | - public function __construct($cldrCategoryId, $cldrFormulaAndExamples) |
|
42 | - { |
|
43 | - $matches = array(); |
|
44 | - if (!preg_match('/^pluralRule-count-(.+)$/', $cldrCategoryId, $matches)) { |
|
45 | - throw new Exception("Invalid CLDR category: '{$cldrCategoryId}'"); |
|
46 | - } |
|
47 | - if (!in_array($matches[1], CldrData::$categories)) { |
|
48 | - throw new Exception("Invalid CLDR category: '{$cldrCategoryId}'"); |
|
49 | - } |
|
50 | - $this->id = $matches[1]; |
|
51 | - $cldrFormulaAndExamplesNormalized = trim(preg_replace('/\s+/', ' ', $cldrFormulaAndExamples)); |
|
52 | - if (!preg_match('/^([^@]*)(?:@integer([^@]+))?(?:@decimal(?:[^@]+))?$/', $cldrFormulaAndExamplesNormalized, $matches)) { |
|
53 | - throw new Exception("Invalid CLDR category rule: {$cldrFormulaAndExamples}"); |
|
54 | - } |
|
55 | - $cldrFormula = trim($matches[1]); |
|
56 | - $s = isset($matches[2]) ? trim($matches[2]) : ''; |
|
57 | - $this->examples = ($s === '') ? null : $s; |
|
58 | - switch ($this->id) { |
|
59 | - case CldrData::OTHER_CATEGORY: |
|
60 | - if ($cldrFormula !== '') { |
|
61 | - throw new Exception("The '" . CldrData::OTHER_CATEGORY . "' category should not have any formula, but it has '{$cldrFormula}'"); |
|
62 | - } |
|
63 | - $this->formula = null; |
|
64 | - break; |
|
65 | - default: |
|
66 | - if ($cldrFormula === '') { |
|
67 | - throw new Exception("The '{$this->id}' category does not have a formula"); |
|
68 | - } |
|
69 | - $this->formula = FormulaConverter::convertFormula($cldrFormula); |
|
70 | - break; |
|
71 | - } |
|
72 | - } |
|
33 | + /** |
|
34 | + * Initialize the instance and parse the formula. |
|
35 | + * |
|
36 | + * @param string $cldrCategoryId the CLDR category identifier (eg 'pluralRule-count-one') |
|
37 | + * @param string $cldrFormulaAndExamples the CLDR formula and examples (eg 'i = 1 and v = 0 @integer 1') |
|
38 | + * |
|
39 | + * @throws \Exception |
|
40 | + */ |
|
41 | + public function __construct($cldrCategoryId, $cldrFormulaAndExamples) |
|
42 | + { |
|
43 | + $matches = array(); |
|
44 | + if (!preg_match('/^pluralRule-count-(.+)$/', $cldrCategoryId, $matches)) { |
|
45 | + throw new Exception("Invalid CLDR category: '{$cldrCategoryId}'"); |
|
46 | + } |
|
47 | + if (!in_array($matches[1], CldrData::$categories)) { |
|
48 | + throw new Exception("Invalid CLDR category: '{$cldrCategoryId}'"); |
|
49 | + } |
|
50 | + $this->id = $matches[1]; |
|
51 | + $cldrFormulaAndExamplesNormalized = trim(preg_replace('/\s+/', ' ', $cldrFormulaAndExamples)); |
|
52 | + if (!preg_match('/^([^@]*)(?:@integer([^@]+))?(?:@decimal(?:[^@]+))?$/', $cldrFormulaAndExamplesNormalized, $matches)) { |
|
53 | + throw new Exception("Invalid CLDR category rule: {$cldrFormulaAndExamples}"); |
|
54 | + } |
|
55 | + $cldrFormula = trim($matches[1]); |
|
56 | + $s = isset($matches[2]) ? trim($matches[2]) : ''; |
|
57 | + $this->examples = ($s === '') ? null : $s; |
|
58 | + switch ($this->id) { |
|
59 | + case CldrData::OTHER_CATEGORY: |
|
60 | + if ($cldrFormula !== '') { |
|
61 | + throw new Exception("The '" . CldrData::OTHER_CATEGORY . "' category should not have any formula, but it has '{$cldrFormula}'"); |
|
62 | + } |
|
63 | + $this->formula = null; |
|
64 | + break; |
|
65 | + default: |
|
66 | + if ($cldrFormula === '') { |
|
67 | + throw new Exception("The '{$this->id}' category does not have a formula"); |
|
68 | + } |
|
69 | + $this->formula = FormulaConverter::convertFormula($cldrFormula); |
|
70 | + break; |
|
71 | + } |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Return a list of numbers corresponding to the $examples value. |
|
76 | - * |
|
77 | - * @throws \Exception throws an Exception if we weren't able to expand the examples |
|
78 | - * |
|
79 | - * @return int[] |
|
80 | - */ |
|
81 | - public function getExampleIntegers() |
|
82 | - { |
|
83 | - return self::expandExamples($this->examples); |
|
84 | - } |
|
74 | + /** |
|
75 | + * Return a list of numbers corresponding to the $examples value. |
|
76 | + * |
|
77 | + * @throws \Exception throws an Exception if we weren't able to expand the examples |
|
78 | + * |
|
79 | + * @return int[] |
|
80 | + */ |
|
81 | + public function getExampleIntegers() |
|
82 | + { |
|
83 | + return self::expandExamples($this->examples); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Expand a list of examples as defined by CLDR. |
|
88 | - * |
|
89 | - * @param string $examples A string like '1, 2, 5...7, …'. |
|
90 | - * |
|
91 | - * @throws \Exception throws an Exception if we weren't able to expand $examples |
|
92 | - * |
|
93 | - * @return int[] |
|
94 | - */ |
|
95 | - public static function expandExamples($examples) |
|
96 | - { |
|
97 | - $result = array(); |
|
98 | - $m = null; |
|
99 | - if (substr($examples, -strlen(', …')) === ', …') { |
|
100 | - $examples = substr($examples, 0, strlen($examples) - strlen(', …')); |
|
101 | - } |
|
102 | - foreach (explode(',', str_replace(' ', '', $examples)) as $range) { |
|
103 | - if (preg_match('/^(?<num>\d+)((c|e)(?<exp>\d+))?$/', $range, $m)) { |
|
104 | - $result[] = (int) (isset($m['exp']) ? ($m['num'] . str_repeat('0', (int) $m['exp'])) : $range); |
|
105 | - } elseif (preg_match('/^(\d+)~(\d+)$/', $range, $m)) { |
|
106 | - $from = (int) $m[1]; |
|
107 | - $to = (int) $m[2]; |
|
108 | - $delta = $to - $from; |
|
109 | - $step = (int) max(1, $delta / 100); |
|
110 | - for ($i = $from; $i < $to; $i += $step) { |
|
111 | - $result[] = $i; |
|
112 | - } |
|
113 | - $result[] = $to; |
|
114 | - } else { |
|
115 | - throw new Exception("Unhandled test range '{$range}' in '{$examples}'"); |
|
116 | - } |
|
117 | - } |
|
118 | - if (empty($result)) { |
|
119 | - throw new Exception("No test numbers from '{$examples}'"); |
|
120 | - } |
|
86 | + /** |
|
87 | + * Expand a list of examples as defined by CLDR. |
|
88 | + * |
|
89 | + * @param string $examples A string like '1, 2, 5...7, …'. |
|
90 | + * |
|
91 | + * @throws \Exception throws an Exception if we weren't able to expand $examples |
|
92 | + * |
|
93 | + * @return int[] |
|
94 | + */ |
|
95 | + public static function expandExamples($examples) |
|
96 | + { |
|
97 | + $result = array(); |
|
98 | + $m = null; |
|
99 | + if (substr($examples, -strlen(', …')) === ', …') { |
|
100 | + $examples = substr($examples, 0, strlen($examples) - strlen(', …')); |
|
101 | + } |
|
102 | + foreach (explode(',', str_replace(' ', '', $examples)) as $range) { |
|
103 | + if (preg_match('/^(?<num>\d+)((c|e)(?<exp>\d+))?$/', $range, $m)) { |
|
104 | + $result[] = (int) (isset($m['exp']) ? ($m['num'] . str_repeat('0', (int) $m['exp'])) : $range); |
|
105 | + } elseif (preg_match('/^(\d+)~(\d+)$/', $range, $m)) { |
|
106 | + $from = (int) $m[1]; |
|
107 | + $to = (int) $m[2]; |
|
108 | + $delta = $to - $from; |
|
109 | + $step = (int) max(1, $delta / 100); |
|
110 | + for ($i = $from; $i < $to; $i += $step) { |
|
111 | + $result[] = $i; |
|
112 | + } |
|
113 | + $result[] = $to; |
|
114 | + } else { |
|
115 | + throw new Exception("Unhandled test range '{$range}' in '{$examples}'"); |
|
116 | + } |
|
117 | + } |
|
118 | + if (empty($result)) { |
|
119 | + throw new Exception("No test numbers from '{$examples}'"); |
|
120 | + } |
|
121 | 121 | |
122 | - return $result; |
|
123 | - } |
|
122 | + return $result; |
|
123 | + } |
|
124 | 124 | } |
@@ -38,35 +38,35 @@ discard block |
||
38 | 38 | * |
39 | 39 | * @throws \Exception |
40 | 40 | */ |
41 | - public function __construct($cldrCategoryId, $cldrFormulaAndExamples) |
|
41 | + public function __construct( $cldrCategoryId, $cldrFormulaAndExamples ) |
|
42 | 42 | { |
43 | 43 | $matches = array(); |
44 | - if (!preg_match('/^pluralRule-count-(.+)$/', $cldrCategoryId, $matches)) { |
|
45 | - throw new Exception("Invalid CLDR category: '{$cldrCategoryId}'"); |
|
44 | + if ( ! preg_match( '/^pluralRule-count-(.+)$/', $cldrCategoryId, $matches ) ) { |
|
45 | + throw new Exception( "Invalid CLDR category: '{$cldrCategoryId}'" ); |
|
46 | 46 | } |
47 | - if (!in_array($matches[1], CldrData::$categories)) { |
|
48 | - throw new Exception("Invalid CLDR category: '{$cldrCategoryId}'"); |
|
47 | + if ( ! in_array( $matches[ 1 ], CldrData::$categories ) ) { |
|
48 | + throw new Exception( "Invalid CLDR category: '{$cldrCategoryId}'" ); |
|
49 | 49 | } |
50 | - $this->id = $matches[1]; |
|
51 | - $cldrFormulaAndExamplesNormalized = trim(preg_replace('/\s+/', ' ', $cldrFormulaAndExamples)); |
|
52 | - if (!preg_match('/^([^@]*)(?:@integer([^@]+))?(?:@decimal(?:[^@]+))?$/', $cldrFormulaAndExamplesNormalized, $matches)) { |
|
53 | - throw new Exception("Invalid CLDR category rule: {$cldrFormulaAndExamples}"); |
|
50 | + $this->id = $matches[ 1 ]; |
|
51 | + $cldrFormulaAndExamplesNormalized = trim( preg_replace( '/\s+/', ' ', $cldrFormulaAndExamples ) ); |
|
52 | + if ( ! preg_match( '/^([^@]*)(?:@integer([^@]+))?(?:@decimal(?:[^@]+))?$/', $cldrFormulaAndExamplesNormalized, $matches ) ) { |
|
53 | + throw new Exception( "Invalid CLDR category rule: {$cldrFormulaAndExamples}" ); |
|
54 | 54 | } |
55 | - $cldrFormula = trim($matches[1]); |
|
56 | - $s = isset($matches[2]) ? trim($matches[2]) : ''; |
|
57 | - $this->examples = ($s === '') ? null : $s; |
|
58 | - switch ($this->id) { |
|
55 | + $cldrFormula = trim( $matches[ 1 ] ); |
|
56 | + $s = isset( $matches[ 2 ] ) ? trim( $matches[ 2 ] ) : ''; |
|
57 | + $this->examples = ( $s === '' ) ? null : $s; |
|
58 | + switch ( $this->id ) { |
|
59 | 59 | case CldrData::OTHER_CATEGORY: |
60 | - if ($cldrFormula !== '') { |
|
61 | - throw new Exception("The '" . CldrData::OTHER_CATEGORY . "' category should not have any formula, but it has '{$cldrFormula}'"); |
|
60 | + if ( $cldrFormula !== '' ) { |
|
61 | + throw new Exception( "The '" . CldrData::OTHER_CATEGORY . "' category should not have any formula, but it has '{$cldrFormula}'" ); |
|
62 | 62 | } |
63 | 63 | $this->formula = null; |
64 | 64 | break; |
65 | 65 | default: |
66 | - if ($cldrFormula === '') { |
|
67 | - throw new Exception("The '{$this->id}' category does not have a formula"); |
|
66 | + if ( $cldrFormula === '' ) { |
|
67 | + throw new Exception( "The '{$this->id}' category does not have a formula" ); |
|
68 | 68 | } |
69 | - $this->formula = FormulaConverter::convertFormula($cldrFormula); |
|
69 | + $this->formula = FormulaConverter::convertFormula( $cldrFormula ); |
|
70 | 70 | break; |
71 | 71 | } |
72 | 72 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public function getExampleIntegers() |
82 | 82 | { |
83 | - return self::expandExamples($this->examples); |
|
83 | + return self::expandExamples( $this->examples ); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | /** |
@@ -92,31 +92,31 @@ discard block |
||
92 | 92 | * |
93 | 93 | * @return int[] |
94 | 94 | */ |
95 | - public static function expandExamples($examples) |
|
95 | + public static function expandExamples( $examples ) |
|
96 | 96 | { |
97 | 97 | $result = array(); |
98 | 98 | $m = null; |
99 | - if (substr($examples, -strlen(', …')) === ', …') { |
|
100 | - $examples = substr($examples, 0, strlen($examples) - strlen(', …')); |
|
99 | + if ( substr( $examples, -strlen( ', …' ) ) === ', …' ) { |
|
100 | + $examples = substr( $examples, 0, strlen( $examples ) - strlen( ', …' ) ); |
|
101 | 101 | } |
102 | - foreach (explode(',', str_replace(' ', '', $examples)) as $range) { |
|
103 | - if (preg_match('/^(?<num>\d+)((c|e)(?<exp>\d+))?$/', $range, $m)) { |
|
104 | - $result[] = (int) (isset($m['exp']) ? ($m['num'] . str_repeat('0', (int) $m['exp'])) : $range); |
|
105 | - } elseif (preg_match('/^(\d+)~(\d+)$/', $range, $m)) { |
|
106 | - $from = (int) $m[1]; |
|
107 | - $to = (int) $m[2]; |
|
102 | + foreach ( explode( ',', str_replace( ' ', '', $examples ) ) as $range ) { |
|
103 | + if ( preg_match( '/^(?<num>\d+)((c|e)(?<exp>\d+))?$/', $range, $m ) ) { |
|
104 | + $result[ ] = (int)( isset( $m[ 'exp' ] ) ? ( $m[ 'num' ] . str_repeat( '0', (int)$m[ 'exp' ] ) ) : $range ); |
|
105 | + } elseif ( preg_match( '/^(\d+)~(\d+)$/', $range, $m ) ) { |
|
106 | + $from = (int)$m[ 1 ]; |
|
107 | + $to = (int)$m[ 2 ]; |
|
108 | 108 | $delta = $to - $from; |
109 | - $step = (int) max(1, $delta / 100); |
|
110 | - for ($i = $from; $i < $to; $i += $step) { |
|
111 | - $result[] = $i; |
|
109 | + $step = (int)max( 1, $delta / 100 ); |
|
110 | + for ( $i = $from; $i < $to; $i += $step ) { |
|
111 | + $result[ ] = $i; |
|
112 | 112 | } |
113 | - $result[] = $to; |
|
113 | + $result[ ] = $to; |
|
114 | 114 | } else { |
115 | - throw new Exception("Unhandled test range '{$range}' in '{$examples}'"); |
|
115 | + throw new Exception( "Unhandled test range '{$range}' in '{$examples}'" ); |
|
116 | 116 | } |
117 | 117 | } |
118 | - if (empty($result)) { |
|
119 | - throw new Exception("No test numbers from '{$examples}'"); |
|
118 | + if ( empty( $result ) ) { |
|
119 | + throw new Exception( "No test numbers from '{$examples}'" ); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | return $result; |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * A helper class that handles a single category rules (eg 'zero', 'one', ...) and its formula and examples. |
9 | 9 | */ |
10 | -class Category |
|
11 | -{ |
|
10 | +class Category { |
|
12 | 11 | /** |
13 | 12 | * The category identifier (eg 'zero', 'one', ..., 'other'). |
14 | 13 | * |
@@ -38,8 +37,7 @@ discard block |
||
38 | 37 | * |
39 | 38 | * @throws \Exception |
40 | 39 | */ |
41 | - public function __construct($cldrCategoryId, $cldrFormulaAndExamples) |
|
42 | - { |
|
40 | + public function __construct($cldrCategoryId, $cldrFormulaAndExamples) { |
|
43 | 41 | $matches = array(); |
44 | 42 | if (!preg_match('/^pluralRule-count-(.+)$/', $cldrCategoryId, $matches)) { |
45 | 43 | throw new Exception("Invalid CLDR category: '{$cldrCategoryId}'"); |
@@ -78,8 +76,7 @@ discard block |
||
78 | 76 | * |
79 | 77 | * @return int[] |
80 | 78 | */ |
81 | - public function getExampleIntegers() |
|
82 | - { |
|
79 | + public function getExampleIntegers() { |
|
83 | 80 | return self::expandExamples($this->examples); |
84 | 81 | } |
85 | 82 | |
@@ -92,8 +89,7 @@ discard block |
||
92 | 89 | * |
93 | 90 | * @return int[] |
94 | 91 | */ |
95 | - public static function expandExamples($examples) |
|
96 | - { |
|
92 | + public static function expandExamples($examples) { |
|
97 | 93 | $result = array(); |
98 | 94 | $m = null; |
99 | 95 | if (substr($examples, -strlen(', …')) === ', …') { |
@@ -1,13 +1,13 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | spl_autoload_register( |
4 | - function ($class) { |
|
5 | - if (strpos($class, 'Gettext\\Languages\\') !== 0) { |
|
6 | - return; |
|
7 | - } |
|
8 | - $file = __DIR__ . str_replace('\\', DIRECTORY_SEPARATOR, substr($class, strlen('Gettext\\Languages'))) . '.php'; |
|
9 | - if (is_file($file)) { |
|
10 | - require_once $file; |
|
11 | - } |
|
12 | - } |
|
4 | + function ($class) { |
|
5 | + if (strpos($class, 'Gettext\\Languages\\') !== 0) { |
|
6 | + return; |
|
7 | + } |
|
8 | + $file = __DIR__ . str_replace('\\', DIRECTORY_SEPARATOR, substr($class, strlen('Gettext\\Languages'))) . '.php'; |
|
9 | + if (is_file($file)) { |
|
10 | + require_once $file; |
|
11 | + } |
|
12 | + } |
|
13 | 13 | ); |
@@ -1,12 +1,12 @@ |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | spl_autoload_register( |
4 | - function ($class) { |
|
5 | - if (strpos($class, 'Gettext\\Languages\\') !== 0) { |
|
4 | + function( $class ) { |
|
5 | + if ( strpos( $class, 'Gettext\\Languages\\' ) !== 0 ) { |
|
6 | 6 | return; |
7 | 7 | } |
8 | - $file = __DIR__ . str_replace('\\', DIRECTORY_SEPARATOR, substr($class, strlen('Gettext\\Languages'))) . '.php'; |
|
9 | - if (is_file($file)) { |
|
8 | + $file = __DIR__ . str_replace( '\\', DIRECTORY_SEPARATOR, substr( $class, strlen( 'Gettext\\Languages' ) ) ) . '.php'; |
|
9 | + if ( is_file( $file ) ) { |
|
10 | 10 | require_once $file; |
11 | 11 | } |
12 | 12 | } |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * A helper class to convert a CLDR formula to a gettext formula. |
9 | 9 | */ |
10 | -class FormulaConverter |
|
11 | -{ |
|
10 | +class FormulaConverter { |
|
12 | 11 | /** |
13 | 12 | * Converts a formula from the CLDR representation to the gettext representation. |
14 | 13 | * |
@@ -18,8 +17,7 @@ discard block |
||
18 | 17 | * |
19 | 18 | * @return bool|string returns true if the gettext will always evaluate to true, false if gettext will always evaluate to false, return the gettext formula otherwise |
20 | 19 | */ |
21 | - public static function convertFormula($cldrFormula) |
|
22 | - { |
|
20 | + public static function convertFormula($cldrFormula) { |
|
23 | 21 | if (strpbrk($cldrFormula, '()') !== false) { |
24 | 22 | throw new Exception("Unable to convert the formula '{$cldrFormula}': parenthesis handling not implemented"); |
25 | 23 | } |
@@ -77,8 +75,7 @@ discard block |
||
77 | 75 | * |
78 | 76 | * @return bool|string returns true if the gettext will always evaluate to true, false if gettext will always evaluate to false, return the gettext formula otherwise |
79 | 77 | */ |
80 | - private static function convertAtom($cldrAtom) |
|
81 | - { |
|
78 | + private static function convertAtom($cldrAtom) { |
|
82 | 79 | $m = null; |
83 | 80 | $gettextAtom = $cldrAtom; |
84 | 81 | $gettextAtom = str_replace(' = ', ' == ', $gettextAtom); |
@@ -89,16 +86,20 @@ discard block |
||
89 | 86 | if (preg_match('/^n( % \d+)? (!=|==) \d+(,\d+|\.\.\d+)+$/', $gettextAtom)) { |
90 | 87 | return self::expandAtom($gettextAtom); |
91 | 88 | } |
92 | - if (preg_match('/^(?:v|w)(?: % 10+)? == (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // For gettext: v == 0, w == 0 |
|
89 | + if (preg_match('/^(?:v|w)(?: % 10+)? == (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { |
|
90 | +// For gettext: v == 0, w == 0 |
|
93 | 91 | return (int) $m[1] === 0 ? true : false; |
94 | 92 | } |
95 | - if (preg_match('/^(?:v|w)(?: % 10+)? != (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // For gettext: v == 0, w == 0 |
|
93 | + if (preg_match('/^(?:v|w)(?: % 10+)? != (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { |
|
94 | +// For gettext: v == 0, w == 0 |
|
96 | 95 | return (int) $m[1] === 0 ? false : true; |
97 | 96 | } |
98 | - if (preg_match('/^(?:f|t|c|e)(?: % 10+)? == (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // f == empty, t == empty, c == empty, e == empty |
|
97 | + if (preg_match('/^(?:f|t|c|e)(?: % 10+)? == (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { |
|
98 | +// f == empty, t == empty, c == empty, e == empty |
|
99 | 99 | return (int) $m[1] === 0 ? true : false; |
100 | 100 | } |
101 | - if (preg_match('/^(?:f|t|c|e)(?: % 10+)? != (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // f == empty, t == empty, c == empty, e == empty |
|
101 | + if (preg_match('/^(?:f|t|c|e)(?: % 10+)? != (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { |
|
102 | +// f == empty, t == empty, c == empty, e == empty |
|
102 | 103 | return (int) $m[1] === 0 ? false : true; |
103 | 104 | } |
104 | 105 | throw new Exception("Unable to convert the formula chunk '{$cldrAtom}' from CLDR to gettext"); |
@@ -113,8 +114,7 @@ discard block |
||
113 | 114 | * |
114 | 115 | * @return string |
115 | 116 | */ |
116 | - private static function expandAtom($atom) |
|
117 | - { |
|
117 | + private static function expandAtom($atom) { |
|
118 | 118 | $m = null; |
119 | 119 | if (preg_match('/^(n(?: % \d+)?) (==|!=) (\d+(?:\.\.\d+|,\d+)+)$/', $atom, $m)) { |
120 | 120 | $what = $m[1]; |
@@ -15,164 +15,164 @@ |
||
15 | 15 | */ |
16 | 16 | class FormulaConverter |
17 | 17 | { |
18 | - /** |
|
19 | - * Converts a formula from the CLDR representation to the gettext representation. |
|
20 | - * |
|
21 | - * @param string $cldrFormula the CLDR formula to convert |
|
22 | - * |
|
23 | - * @throws \Exception |
|
24 | - * |
|
25 | - * @return bool|string returns true if the gettext will always evaluate to true, false if gettext will always evaluate to false, return the gettext formula otherwise |
|
26 | - */ |
|
27 | - public static function convertFormula($cldrFormula) |
|
28 | - { |
|
29 | - if (strpbrk($cldrFormula, '()') !== false) { |
|
30 | - throw new Exception("Unable to convert the formula '{$cldrFormula}': parenthesis handling not implemented"); |
|
31 | - } |
|
32 | - $orSeparatedChunks = array(); |
|
33 | - foreach (explode(' or ', $cldrFormula) as $cldrFormulaChunk) { |
|
34 | - $gettextFormulaChunk = null; |
|
35 | - $andSeparatedChunks = array(); |
|
36 | - foreach (explode(' and ', $cldrFormulaChunk) as $cldrAtom) { |
|
37 | - $gettextAtom = self::convertAtom($cldrAtom); |
|
38 | - if ($gettextAtom === false) { |
|
39 | - // One atom joined by 'and' always evaluates to false => the whole 'and' group is always false |
|
40 | - $gettextFormulaChunk = false; |
|
41 | - break; |
|
42 | - } |
|
43 | - if ($gettextAtom !== true) { |
|
44 | - $andSeparatedChunks[] = $gettextAtom; |
|
45 | - } |
|
46 | - } |
|
47 | - if (!isset($gettextFormulaChunk)) { |
|
48 | - if (empty($andSeparatedChunks)) { |
|
49 | - // All the atoms joined by 'and' always evaluate to true => the whole 'and' group is always true |
|
50 | - $gettextFormulaChunk = true; |
|
51 | - } else { |
|
52 | - $gettextFormulaChunk = implode(' && ', $andSeparatedChunks); |
|
53 | - // Special cases simplification |
|
54 | - switch ($gettextFormulaChunk) { |
|
55 | - case 'n >= 0 && n <= 2 && n != 2': |
|
56 | - $gettextFormulaChunk = 'n == 0 || n == 1'; |
|
57 | - break; |
|
58 | - } |
|
59 | - } |
|
60 | - } |
|
61 | - if ($gettextFormulaChunk === true) { |
|
62 | - // One part of the formula joined with the others by 'or' always evaluates to true => the whole formula always evaluates to true |
|
63 | - return true; |
|
64 | - } |
|
65 | - if ($gettextFormulaChunk !== false) { |
|
66 | - $orSeparatedChunks[] = $gettextFormulaChunk; |
|
67 | - } |
|
68 | - } |
|
69 | - if (empty($orSeparatedChunks)) { |
|
70 | - // All the parts joined by 'or' always evaluate to false => the whole formula always evaluates to false |
|
71 | - return false; |
|
72 | - } |
|
18 | + /** |
|
19 | + * Converts a formula from the CLDR representation to the gettext representation. |
|
20 | + * |
|
21 | + * @param string $cldrFormula the CLDR formula to convert |
|
22 | + * |
|
23 | + * @throws \Exception |
|
24 | + * |
|
25 | + * @return bool|string returns true if the gettext will always evaluate to true, false if gettext will always evaluate to false, return the gettext formula otherwise |
|
26 | + */ |
|
27 | + public static function convertFormula($cldrFormula) |
|
28 | + { |
|
29 | + if (strpbrk($cldrFormula, '()') !== false) { |
|
30 | + throw new Exception("Unable to convert the formula '{$cldrFormula}': parenthesis handling not implemented"); |
|
31 | + } |
|
32 | + $orSeparatedChunks = array(); |
|
33 | + foreach (explode(' or ', $cldrFormula) as $cldrFormulaChunk) { |
|
34 | + $gettextFormulaChunk = null; |
|
35 | + $andSeparatedChunks = array(); |
|
36 | + foreach (explode(' and ', $cldrFormulaChunk) as $cldrAtom) { |
|
37 | + $gettextAtom = self::convertAtom($cldrAtom); |
|
38 | + if ($gettextAtom === false) { |
|
39 | + // One atom joined by 'and' always evaluates to false => the whole 'and' group is always false |
|
40 | + $gettextFormulaChunk = false; |
|
41 | + break; |
|
42 | + } |
|
43 | + if ($gettextAtom !== true) { |
|
44 | + $andSeparatedChunks[] = $gettextAtom; |
|
45 | + } |
|
46 | + } |
|
47 | + if (!isset($gettextFormulaChunk)) { |
|
48 | + if (empty($andSeparatedChunks)) { |
|
49 | + // All the atoms joined by 'and' always evaluate to true => the whole 'and' group is always true |
|
50 | + $gettextFormulaChunk = true; |
|
51 | + } else { |
|
52 | + $gettextFormulaChunk = implode(' && ', $andSeparatedChunks); |
|
53 | + // Special cases simplification |
|
54 | + switch ($gettextFormulaChunk) { |
|
55 | + case 'n >= 0 && n <= 2 && n != 2': |
|
56 | + $gettextFormulaChunk = 'n == 0 || n == 1'; |
|
57 | + break; |
|
58 | + } |
|
59 | + } |
|
60 | + } |
|
61 | + if ($gettextFormulaChunk === true) { |
|
62 | + // One part of the formula joined with the others by 'or' always evaluates to true => the whole formula always evaluates to true |
|
63 | + return true; |
|
64 | + } |
|
65 | + if ($gettextFormulaChunk !== false) { |
|
66 | + $orSeparatedChunks[] = $gettextFormulaChunk; |
|
67 | + } |
|
68 | + } |
|
69 | + if (empty($orSeparatedChunks)) { |
|
70 | + // All the parts joined by 'or' always evaluate to false => the whole formula always evaluates to false |
|
71 | + return false; |
|
72 | + } |
|
73 | 73 | |
74 | - return implode(' || ', $orSeparatedChunks); |
|
75 | - } |
|
74 | + return implode(' || ', $orSeparatedChunks); |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Converts an atomic part of the CLDR formula to its gettext representation. |
|
79 | - * |
|
80 | - * @param string $cldrAtom the CLDR formula atom to convert |
|
81 | - * |
|
82 | - * @throws \Exception |
|
83 | - * |
|
84 | - * @return bool|string returns true if the gettext will always evaluate to true, false if gettext will always evaluate to false, return the gettext formula otherwise |
|
85 | - */ |
|
86 | - private static function convertAtom($cldrAtom) |
|
87 | - { |
|
88 | - $m = null; |
|
89 | - $gettextAtom = $cldrAtom; |
|
90 | - $gettextAtom = str_replace(' = ', ' == ', $gettextAtom); |
|
91 | - $gettextAtom = str_replace('i', 'n', $gettextAtom); |
|
92 | - if (preg_match('/^n( % \d+)? (!=|==) \d+$/', $gettextAtom)) { |
|
93 | - return $gettextAtom; |
|
94 | - } |
|
95 | - if (preg_match('/^n( % \d+)? (!=|==) \d+(,\d+|\.\.\d+)+$/', $gettextAtom)) { |
|
96 | - return self::expandAtom($gettextAtom); |
|
97 | - } |
|
98 | - if (preg_match('/^(?:v|w)(?: % 10+)? == (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // For gettext: v == 0, w == 0 |
|
99 | - return (int) $m[1] === 0 ? true : false; |
|
100 | - } |
|
101 | - if (preg_match('/^(?:v|w)(?: % 10+)? != (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // For gettext: v == 0, w == 0 |
|
102 | - return (int) $m[1] === 0 ? false : true; |
|
103 | - } |
|
104 | - if (preg_match('/^(?:f|t|c|e)(?: % 10+)? == (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // f == empty, t == empty, c == empty, e == empty |
|
105 | - return (int) $m[1] === 0 ? true : false; |
|
106 | - } |
|
107 | - if (preg_match('/^(?:f|t|c|e)(?: % 10+)? != (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // f == empty, t == empty, c == empty, e == empty |
|
108 | - return (int) $m[1] === 0 ? false : true; |
|
109 | - } |
|
110 | - throw new Exception("Unable to convert the formula chunk '{$cldrAtom}' from CLDR to gettext"); |
|
111 | - } |
|
77 | + /** |
|
78 | + * Converts an atomic part of the CLDR formula to its gettext representation. |
|
79 | + * |
|
80 | + * @param string $cldrAtom the CLDR formula atom to convert |
|
81 | + * |
|
82 | + * @throws \Exception |
|
83 | + * |
|
84 | + * @return bool|string returns true if the gettext will always evaluate to true, false if gettext will always evaluate to false, return the gettext formula otherwise |
|
85 | + */ |
|
86 | + private static function convertAtom($cldrAtom) |
|
87 | + { |
|
88 | + $m = null; |
|
89 | + $gettextAtom = $cldrAtom; |
|
90 | + $gettextAtom = str_replace(' = ', ' == ', $gettextAtom); |
|
91 | + $gettextAtom = str_replace('i', 'n', $gettextAtom); |
|
92 | + if (preg_match('/^n( % \d+)? (!=|==) \d+$/', $gettextAtom)) { |
|
93 | + return $gettextAtom; |
|
94 | + } |
|
95 | + if (preg_match('/^n( % \d+)? (!=|==) \d+(,\d+|\.\.\d+)+$/', $gettextAtom)) { |
|
96 | + return self::expandAtom($gettextAtom); |
|
97 | + } |
|
98 | + if (preg_match('/^(?:v|w)(?: % 10+)? == (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // For gettext: v == 0, w == 0 |
|
99 | + return (int) $m[1] === 0 ? true : false; |
|
100 | + } |
|
101 | + if (preg_match('/^(?:v|w)(?: % 10+)? != (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // For gettext: v == 0, w == 0 |
|
102 | + return (int) $m[1] === 0 ? false : true; |
|
103 | + } |
|
104 | + if (preg_match('/^(?:f|t|c|e)(?: % 10+)? == (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // f == empty, t == empty, c == empty, e == empty |
|
105 | + return (int) $m[1] === 0 ? true : false; |
|
106 | + } |
|
107 | + if (preg_match('/^(?:f|t|c|e)(?: % 10+)? != (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // f == empty, t == empty, c == empty, e == empty |
|
108 | + return (int) $m[1] === 0 ? false : true; |
|
109 | + } |
|
110 | + throw new Exception("Unable to convert the formula chunk '{$cldrAtom}' from CLDR to gettext"); |
|
111 | + } |
|
112 | 112 | |
113 | - /** |
|
114 | - * Expands an atom containing a range (for instance: 'n == 1,3..5'). |
|
115 | - * |
|
116 | - * @param string $atom |
|
117 | - * |
|
118 | - * @throws \Exception |
|
119 | - * |
|
120 | - * @return string |
|
121 | - */ |
|
122 | - private static function expandAtom($atom) |
|
123 | - { |
|
124 | - $m = null; |
|
125 | - if (preg_match('/^(n(?: % \d+)?) (==|!=) (\d+(?:\.\.\d+|,\d+)+)$/', $atom, $m)) { |
|
126 | - $what = $m[1]; |
|
127 | - $op = $m[2]; |
|
128 | - $chunks = array(); |
|
129 | - foreach (explode(',', $m[3]) as $range) { |
|
130 | - $chunk = null; |
|
131 | - if ((!isset($chunk)) && preg_match('/^\d+$/', $range)) { |
|
132 | - $chunk = "{$what} {$op} {$range}"; |
|
133 | - } |
|
134 | - if ((!isset($chunk)) && preg_match('/^(\d+)\.\.(\d+)$/', $range, $m)) { |
|
135 | - $from = (int) $m[1]; |
|
136 | - $to = (int) $m[2]; |
|
137 | - if (($to - $from) === 1) { |
|
138 | - switch ($op) { |
|
139 | - case '==': |
|
140 | - $chunk = "({$what} == {$from} || {$what} == {$to})"; |
|
141 | - break; |
|
142 | - case '!=': |
|
143 | - $chunk = "{$what} != {$from} && {$what} == {$to}"; |
|
144 | - break; |
|
145 | - } |
|
146 | - } else { |
|
147 | - switch ($op) { |
|
148 | - case '==': |
|
149 | - $chunk = "{$what} >= {$from} && {$what} <= {$to}"; |
|
150 | - break; |
|
151 | - case '!=': |
|
152 | - if ($what === 'n' && $from <= 0) { |
|
153 | - $chunk = "{$what} > {$to}"; |
|
154 | - } else { |
|
155 | - $chunk = "({$what} < {$from} || {$what} > {$to})"; |
|
156 | - } |
|
157 | - break; |
|
158 | - } |
|
159 | - } |
|
160 | - } |
|
161 | - if (!isset($chunk)) { |
|
162 | - throw new Exception("Unhandled range '{$range}' in '{$atom}'"); |
|
163 | - } |
|
164 | - $chunks[] = $chunk; |
|
165 | - } |
|
166 | - if (count($chunks) === 1) { |
|
167 | - return $chunks[0]; |
|
168 | - } |
|
169 | - switch ($op) { |
|
170 | - case '==': |
|
171 | - return '(' . implode(' || ', $chunks) . ')'; |
|
172 | - case '!=': |
|
173 | - return implode(' && ', $chunks); |
|
174 | - } |
|
175 | - } |
|
176 | - throw new Exception("Unable to expand '{$atom}'"); |
|
177 | - } |
|
113 | + /** |
|
114 | + * Expands an atom containing a range (for instance: 'n == 1,3..5'). |
|
115 | + * |
|
116 | + * @param string $atom |
|
117 | + * |
|
118 | + * @throws \Exception |
|
119 | + * |
|
120 | + * @return string |
|
121 | + */ |
|
122 | + private static function expandAtom($atom) |
|
123 | + { |
|
124 | + $m = null; |
|
125 | + if (preg_match('/^(n(?: % \d+)?) (==|!=) (\d+(?:\.\.\d+|,\d+)+)$/', $atom, $m)) { |
|
126 | + $what = $m[1]; |
|
127 | + $op = $m[2]; |
|
128 | + $chunks = array(); |
|
129 | + foreach (explode(',', $m[3]) as $range) { |
|
130 | + $chunk = null; |
|
131 | + if ((!isset($chunk)) && preg_match('/^\d+$/', $range)) { |
|
132 | + $chunk = "{$what} {$op} {$range}"; |
|
133 | + } |
|
134 | + if ((!isset($chunk)) && preg_match('/^(\d+)\.\.(\d+)$/', $range, $m)) { |
|
135 | + $from = (int) $m[1]; |
|
136 | + $to = (int) $m[2]; |
|
137 | + if (($to - $from) === 1) { |
|
138 | + switch ($op) { |
|
139 | + case '==': |
|
140 | + $chunk = "({$what} == {$from} || {$what} == {$to})"; |
|
141 | + break; |
|
142 | + case '!=': |
|
143 | + $chunk = "{$what} != {$from} && {$what} == {$to}"; |
|
144 | + break; |
|
145 | + } |
|
146 | + } else { |
|
147 | + switch ($op) { |
|
148 | + case '==': |
|
149 | + $chunk = "{$what} >= {$from} && {$what} <= {$to}"; |
|
150 | + break; |
|
151 | + case '!=': |
|
152 | + if ($what === 'n' && $from <= 0) { |
|
153 | + $chunk = "{$what} > {$to}"; |
|
154 | + } else { |
|
155 | + $chunk = "({$what} < {$from} || {$what} > {$to})"; |
|
156 | + } |
|
157 | + break; |
|
158 | + } |
|
159 | + } |
|
160 | + } |
|
161 | + if (!isset($chunk)) { |
|
162 | + throw new Exception("Unhandled range '{$range}' in '{$atom}'"); |
|
163 | + } |
|
164 | + $chunks[] = $chunk; |
|
165 | + } |
|
166 | + if (count($chunks) === 1) { |
|
167 | + return $chunks[0]; |
|
168 | + } |
|
169 | + switch ($op) { |
|
170 | + case '==': |
|
171 | + return '(' . implode(' || ', $chunks) . ')'; |
|
172 | + case '!=': |
|
173 | + return implode(' && ', $chunks); |
|
174 | + } |
|
175 | + } |
|
176 | + throw new Exception("Unable to expand '{$atom}'"); |
|
177 | + } |
|
178 | 178 | } |
@@ -24,54 +24,54 @@ discard block |
||
24 | 24 | * |
25 | 25 | * @return bool|string returns true if the gettext will always evaluate to true, false if gettext will always evaluate to false, return the gettext formula otherwise |
26 | 26 | */ |
27 | - public static function convertFormula($cldrFormula) |
|
27 | + public static function convertFormula( $cldrFormula ) |
|
28 | 28 | { |
29 | - if (strpbrk($cldrFormula, '()') !== false) { |
|
30 | - throw new Exception("Unable to convert the formula '{$cldrFormula}': parenthesis handling not implemented"); |
|
29 | + if ( strpbrk( $cldrFormula, '()' ) !== false ) { |
|
30 | + throw new Exception( "Unable to convert the formula '{$cldrFormula}': parenthesis handling not implemented" ); |
|
31 | 31 | } |
32 | 32 | $orSeparatedChunks = array(); |
33 | - foreach (explode(' or ', $cldrFormula) as $cldrFormulaChunk) { |
|
33 | + foreach ( explode( ' or ', $cldrFormula ) as $cldrFormulaChunk ) { |
|
34 | 34 | $gettextFormulaChunk = null; |
35 | 35 | $andSeparatedChunks = array(); |
36 | - foreach (explode(' and ', $cldrFormulaChunk) as $cldrAtom) { |
|
37 | - $gettextAtom = self::convertAtom($cldrAtom); |
|
38 | - if ($gettextAtom === false) { |
|
36 | + foreach ( explode( ' and ', $cldrFormulaChunk ) as $cldrAtom ) { |
|
37 | + $gettextAtom = self::convertAtom( $cldrAtom ); |
|
38 | + if ( $gettextAtom === false ) { |
|
39 | 39 | // One atom joined by 'and' always evaluates to false => the whole 'and' group is always false |
40 | 40 | $gettextFormulaChunk = false; |
41 | 41 | break; |
42 | 42 | } |
43 | - if ($gettextAtom !== true) { |
|
44 | - $andSeparatedChunks[] = $gettextAtom; |
|
43 | + if ( $gettextAtom !== true ) { |
|
44 | + $andSeparatedChunks[ ] = $gettextAtom; |
|
45 | 45 | } |
46 | 46 | } |
47 | - if (!isset($gettextFormulaChunk)) { |
|
48 | - if (empty($andSeparatedChunks)) { |
|
47 | + if ( ! isset( $gettextFormulaChunk ) ) { |
|
48 | + if ( empty( $andSeparatedChunks ) ) { |
|
49 | 49 | // All the atoms joined by 'and' always evaluate to true => the whole 'and' group is always true |
50 | 50 | $gettextFormulaChunk = true; |
51 | 51 | } else { |
52 | - $gettextFormulaChunk = implode(' && ', $andSeparatedChunks); |
|
52 | + $gettextFormulaChunk = implode( ' && ', $andSeparatedChunks ); |
|
53 | 53 | // Special cases simplification |
54 | - switch ($gettextFormulaChunk) { |
|
54 | + switch ( $gettextFormulaChunk ) { |
|
55 | 55 | case 'n >= 0 && n <= 2 && n != 2': |
56 | 56 | $gettextFormulaChunk = 'n == 0 || n == 1'; |
57 | 57 | break; |
58 | 58 | } |
59 | 59 | } |
60 | 60 | } |
61 | - if ($gettextFormulaChunk === true) { |
|
61 | + if ( $gettextFormulaChunk === true ) { |
|
62 | 62 | // One part of the formula joined with the others by 'or' always evaluates to true => the whole formula always evaluates to true |
63 | 63 | return true; |
64 | 64 | } |
65 | - if ($gettextFormulaChunk !== false) { |
|
66 | - $orSeparatedChunks[] = $gettextFormulaChunk; |
|
65 | + if ( $gettextFormulaChunk !== false ) { |
|
66 | + $orSeparatedChunks[ ] = $gettextFormulaChunk; |
|
67 | 67 | } |
68 | 68 | } |
69 | - if (empty($orSeparatedChunks)) { |
|
69 | + if ( empty( $orSeparatedChunks ) ) { |
|
70 | 70 | // All the parts joined by 'or' always evaluate to false => the whole formula always evaluates to false |
71 | 71 | return false; |
72 | 72 | } |
73 | 73 | |
74 | - return implode(' || ', $orSeparatedChunks); |
|
74 | + return implode( ' || ', $orSeparatedChunks ); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | /** |
@@ -83,31 +83,31 @@ discard block |
||
83 | 83 | * |
84 | 84 | * @return bool|string returns true if the gettext will always evaluate to true, false if gettext will always evaluate to false, return the gettext formula otherwise |
85 | 85 | */ |
86 | - private static function convertAtom($cldrAtom) |
|
86 | + private static function convertAtom( $cldrAtom ) |
|
87 | 87 | { |
88 | 88 | $m = null; |
89 | 89 | $gettextAtom = $cldrAtom; |
90 | - $gettextAtom = str_replace(' = ', ' == ', $gettextAtom); |
|
91 | - $gettextAtom = str_replace('i', 'n', $gettextAtom); |
|
92 | - if (preg_match('/^n( % \d+)? (!=|==) \d+$/', $gettextAtom)) { |
|
90 | + $gettextAtom = str_replace( ' = ', ' == ', $gettextAtom ); |
|
91 | + $gettextAtom = str_replace( 'i', 'n', $gettextAtom ); |
|
92 | + if ( preg_match( '/^n( % \d+)? (!=|==) \d+$/', $gettextAtom ) ) { |
|
93 | 93 | return $gettextAtom; |
94 | 94 | } |
95 | - if (preg_match('/^n( % \d+)? (!=|==) \d+(,\d+|\.\.\d+)+$/', $gettextAtom)) { |
|
96 | - return self::expandAtom($gettextAtom); |
|
95 | + if ( preg_match( '/^n( % \d+)? (!=|==) \d+(,\d+|\.\.\d+)+$/', $gettextAtom ) ) { |
|
96 | + return self::expandAtom( $gettextAtom ); |
|
97 | 97 | } |
98 | - if (preg_match('/^(?:v|w)(?: % 10+)? == (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // For gettext: v == 0, w == 0 |
|
99 | - return (int) $m[1] === 0 ? true : false; |
|
98 | + if ( preg_match( '/^(?:v|w)(?: % 10+)? == (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m ) ) { // For gettext: v == 0, w == 0 |
|
99 | + return (int)$m[ 1 ] === 0 ? true : false; |
|
100 | 100 | } |
101 | - if (preg_match('/^(?:v|w)(?: % 10+)? != (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // For gettext: v == 0, w == 0 |
|
102 | - return (int) $m[1] === 0 ? false : true; |
|
101 | + if ( preg_match( '/^(?:v|w)(?: % 10+)? != (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m ) ) { // For gettext: v == 0, w == 0 |
|
102 | + return (int)$m[ 1 ] === 0 ? false : true; |
|
103 | 103 | } |
104 | - if (preg_match('/^(?:f|t|c|e)(?: % 10+)? == (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // f == empty, t == empty, c == empty, e == empty |
|
105 | - return (int) $m[1] === 0 ? true : false; |
|
104 | + if ( preg_match( '/^(?:f|t|c|e)(?: % 10+)? == (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m ) ) { // f == empty, t == empty, c == empty, e == empty |
|
105 | + return (int)$m[ 1 ] === 0 ? true : false; |
|
106 | 106 | } |
107 | - if (preg_match('/^(?:f|t|c|e)(?: % 10+)? != (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m)) { // f == empty, t == empty, c == empty, e == empty |
|
108 | - return (int) $m[1] === 0 ? false : true; |
|
107 | + if ( preg_match( '/^(?:f|t|c|e)(?: % 10+)? != (\d+)(?:\.\.\d+)?$/', $gettextAtom, $m ) ) { // f == empty, t == empty, c == empty, e == empty |
|
108 | + return (int)$m[ 1 ] === 0 ? false : true; |
|
109 | 109 | } |
110 | - throw new Exception("Unable to convert the formula chunk '{$cldrAtom}' from CLDR to gettext"); |
|
110 | + throw new Exception( "Unable to convert the formula chunk '{$cldrAtom}' from CLDR to gettext" ); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | /** |
@@ -119,23 +119,23 @@ discard block |
||
119 | 119 | * |
120 | 120 | * @return string |
121 | 121 | */ |
122 | - private static function expandAtom($atom) |
|
122 | + private static function expandAtom( $atom ) |
|
123 | 123 | { |
124 | 124 | $m = null; |
125 | - if (preg_match('/^(n(?: % \d+)?) (==|!=) (\d+(?:\.\.\d+|,\d+)+)$/', $atom, $m)) { |
|
126 | - $what = $m[1]; |
|
127 | - $op = $m[2]; |
|
125 | + if ( preg_match( '/^(n(?: % \d+)?) (==|!=) (\d+(?:\.\.\d+|,\d+)+)$/', $atom, $m ) ) { |
|
126 | + $what = $m[ 1 ]; |
|
127 | + $op = $m[ 2 ]; |
|
128 | 128 | $chunks = array(); |
129 | - foreach (explode(',', $m[3]) as $range) { |
|
129 | + foreach ( explode( ',', $m[ 3 ] ) as $range ) { |
|
130 | 130 | $chunk = null; |
131 | - if ((!isset($chunk)) && preg_match('/^\d+$/', $range)) { |
|
131 | + if ( ( ! isset( $chunk ) ) && preg_match( '/^\d+$/', $range ) ) { |
|
132 | 132 | $chunk = "{$what} {$op} {$range}"; |
133 | 133 | } |
134 | - if ((!isset($chunk)) && preg_match('/^(\d+)\.\.(\d+)$/', $range, $m)) { |
|
135 | - $from = (int) $m[1]; |
|
136 | - $to = (int) $m[2]; |
|
137 | - if (($to - $from) === 1) { |
|
138 | - switch ($op) { |
|
134 | + if ( ( ! isset( $chunk ) ) && preg_match( '/^(\d+)\.\.(\d+)$/', $range, $m ) ) { |
|
135 | + $from = (int)$m[ 1 ]; |
|
136 | + $to = (int)$m[ 2 ]; |
|
137 | + if ( ( $to - $from ) === 1 ) { |
|
138 | + switch ( $op ) { |
|
139 | 139 | case '==': |
140 | 140 | $chunk = "({$what} == {$from} || {$what} == {$to})"; |
141 | 141 | break; |
@@ -144,12 +144,12 @@ discard block |
||
144 | 144 | break; |
145 | 145 | } |
146 | 146 | } else { |
147 | - switch ($op) { |
|
147 | + switch ( $op ) { |
|
148 | 148 | case '==': |
149 | 149 | $chunk = "{$what} >= {$from} && {$what} <= {$to}"; |
150 | 150 | break; |
151 | 151 | case '!=': |
152 | - if ($what === 'n' && $from <= 0) { |
|
152 | + if ( $what === 'n' && $from <= 0 ) { |
|
153 | 153 | $chunk = "{$what} > {$to}"; |
154 | 154 | } else { |
155 | 155 | $chunk = "({$what} < {$from} || {$what} > {$to})"; |
@@ -158,21 +158,21 @@ discard block |
||
158 | 158 | } |
159 | 159 | } |
160 | 160 | } |
161 | - if (!isset($chunk)) { |
|
162 | - throw new Exception("Unhandled range '{$range}' in '{$atom}'"); |
|
161 | + if ( ! isset( $chunk ) ) { |
|
162 | + throw new Exception( "Unhandled range '{$range}' in '{$atom}'" ); |
|
163 | 163 | } |
164 | - $chunks[] = $chunk; |
|
164 | + $chunks[ ] = $chunk; |
|
165 | 165 | } |
166 | - if (count($chunks) === 1) { |
|
167 | - return $chunks[0]; |
|
166 | + if ( count( $chunks ) === 1 ) { |
|
167 | + return $chunks[ 0 ]; |
|
168 | 168 | } |
169 | - switch ($op) { |
|
169 | + switch ( $op ) { |
|
170 | 170 | case '==': |
171 | - return '(' . implode(' || ', $chunks) . ')'; |
|
171 | + return '(' . implode( ' || ', $chunks ) . ')'; |
|
172 | 172 | case '!=': |
173 | - return implode(' && ', $chunks); |
|
173 | + return implode( ' && ', $chunks ); |
|
174 | 174 | } |
175 | 175 | } |
176 | - throw new Exception("Unable to expand '{$atom}'"); |
|
176 | + throw new Exception( "Unable to expand '{$atom}'" ); |
|
177 | 177 | } |
178 | 178 | } |
@@ -7,106 +7,106 @@ |
||
7 | 7 | */ |
8 | 8 | interface TranslatorInterface |
9 | 9 | { |
10 | - /** |
|
11 | - * Register this translator as global, to use with the gettext functions __(), p__(), etc. |
|
12 | - * Returns the previous translator if exists. |
|
13 | - * |
|
14 | - * @return TranslatorInterface|null |
|
15 | - */ |
|
16 | - public function register(); |
|
10 | + /** |
|
11 | + * Register this translator as global, to use with the gettext functions __(), p__(), etc. |
|
12 | + * Returns the previous translator if exists. |
|
13 | + * |
|
14 | + * @return TranslatorInterface|null |
|
15 | + */ |
|
16 | + public function register(); |
|
17 | 17 | |
18 | - /** |
|
19 | - * Noop, marks the string for translation but returns it unchanged. |
|
20 | - * |
|
21 | - * @param string $original |
|
22 | - * |
|
23 | - * @return string |
|
24 | - */ |
|
25 | - public function noop($original); |
|
18 | + /** |
|
19 | + * Noop, marks the string for translation but returns it unchanged. |
|
20 | + * |
|
21 | + * @param string $original |
|
22 | + * |
|
23 | + * @return string |
|
24 | + */ |
|
25 | + public function noop($original); |
|
26 | 26 | |
27 | - /** |
|
28 | - * Gets a translation using the original string. |
|
29 | - * |
|
30 | - * @param string $original |
|
31 | - * |
|
32 | - * @return string |
|
33 | - */ |
|
34 | - public function gettext($original); |
|
27 | + /** |
|
28 | + * Gets a translation using the original string. |
|
29 | + * |
|
30 | + * @param string $original |
|
31 | + * |
|
32 | + * @return string |
|
33 | + */ |
|
34 | + public function gettext($original); |
|
35 | 35 | |
36 | - /** |
|
37 | - * Gets a translation checking the plural form. |
|
38 | - * |
|
39 | - * @param string $original |
|
40 | - * @param string $plural |
|
41 | - * @param string $value |
|
42 | - * |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public function ngettext($original, $plural, $value); |
|
36 | + /** |
|
37 | + * Gets a translation checking the plural form. |
|
38 | + * |
|
39 | + * @param string $original |
|
40 | + * @param string $plural |
|
41 | + * @param string $value |
|
42 | + * |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public function ngettext($original, $plural, $value); |
|
46 | 46 | |
47 | - /** |
|
48 | - * Gets a translation checking the domain and the plural form. |
|
49 | - * |
|
50 | - * @param string $domain |
|
51 | - * @param string $original |
|
52 | - * @param string $plural |
|
53 | - * @param string $value |
|
54 | - * |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - public function dngettext($domain, $original, $plural, $value); |
|
47 | + /** |
|
48 | + * Gets a translation checking the domain and the plural form. |
|
49 | + * |
|
50 | + * @param string $domain |
|
51 | + * @param string $original |
|
52 | + * @param string $plural |
|
53 | + * @param string $value |
|
54 | + * |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + public function dngettext($domain, $original, $plural, $value); |
|
58 | 58 | |
59 | - /** |
|
60 | - * Gets a translation checking the context and the plural form. |
|
61 | - * |
|
62 | - * @param string $context |
|
63 | - * @param string $original |
|
64 | - * @param string $plural |
|
65 | - * @param string $value |
|
66 | - * |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - public function npgettext($context, $original, $plural, $value); |
|
59 | + /** |
|
60 | + * Gets a translation checking the context and the plural form. |
|
61 | + * |
|
62 | + * @param string $context |
|
63 | + * @param string $original |
|
64 | + * @param string $plural |
|
65 | + * @param string $value |
|
66 | + * |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + public function npgettext($context, $original, $plural, $value); |
|
70 | 70 | |
71 | - /** |
|
72 | - * Gets a translation checking the context. |
|
73 | - * |
|
74 | - * @param string $context |
|
75 | - * @param string $original |
|
76 | - * |
|
77 | - * @return string |
|
78 | - */ |
|
79 | - public function pgettext($context, $original); |
|
71 | + /** |
|
72 | + * Gets a translation checking the context. |
|
73 | + * |
|
74 | + * @param string $context |
|
75 | + * @param string $original |
|
76 | + * |
|
77 | + * @return string |
|
78 | + */ |
|
79 | + public function pgettext($context, $original); |
|
80 | 80 | |
81 | - /** |
|
82 | - * Gets a translation checking the domain. |
|
83 | - * |
|
84 | - * @param string $domain |
|
85 | - * @param string $original |
|
86 | - * |
|
87 | - * @return string |
|
88 | - */ |
|
89 | - public function dgettext($domain, $original); |
|
81 | + /** |
|
82 | + * Gets a translation checking the domain. |
|
83 | + * |
|
84 | + * @param string $domain |
|
85 | + * @param string $original |
|
86 | + * |
|
87 | + * @return string |
|
88 | + */ |
|
89 | + public function dgettext($domain, $original); |
|
90 | 90 | |
91 | - /** |
|
92 | - * Gets a translation checking the domain and context. |
|
93 | - * |
|
94 | - * @param string $domain |
|
95 | - * @param string $context |
|
96 | - * @param string $original |
|
97 | - * |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - public function dpgettext($domain, $context, $original); |
|
91 | + /** |
|
92 | + * Gets a translation checking the domain and context. |
|
93 | + * |
|
94 | + * @param string $domain |
|
95 | + * @param string $context |
|
96 | + * @param string $original |
|
97 | + * |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + public function dpgettext($domain, $context, $original); |
|
101 | 101 | |
102 | - /** |
|
103 | - * Gets a translation checking the domain, the context and the plural form. |
|
104 | - * |
|
105 | - * @param string $domain |
|
106 | - * @param string $context |
|
107 | - * @param string $original |
|
108 | - * @param string $plural |
|
109 | - * @param string $value |
|
110 | - */ |
|
111 | - public function dnpgettext($domain, $context, $original, $plural, $value); |
|
102 | + /** |
|
103 | + * Gets a translation checking the domain, the context and the plural form. |
|
104 | + * |
|
105 | + * @param string $domain |
|
106 | + * @param string $context |
|
107 | + * @param string $original |
|
108 | + * @param string $plural |
|
109 | + * @param string $value |
|
110 | + */ |
|
111 | + public function dnpgettext($domain, $context, $original, $plural, $value); |
|
112 | 112 | } |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @return string |
24 | 24 | */ |
25 | - public function noop($original); |
|
25 | + public function noop( $original ); |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * Gets a translation using the original string. |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @return string |
33 | 33 | */ |
34 | - public function gettext($original); |
|
34 | + public function gettext( $original ); |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * Gets a translation checking the plural form. |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | * |
43 | 43 | * @return string |
44 | 44 | */ |
45 | - public function ngettext($original, $plural, $value); |
|
45 | + public function ngettext( $original, $plural, $value ); |
|
46 | 46 | |
47 | 47 | /** |
48 | 48 | * Gets a translation checking the domain and the plural form. |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | * |
55 | 55 | * @return string |
56 | 56 | */ |
57 | - public function dngettext($domain, $original, $plural, $value); |
|
57 | + public function dngettext( $domain, $original, $plural, $value ); |
|
58 | 58 | |
59 | 59 | /** |
60 | 60 | * Gets a translation checking the context and the plural form. |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * |
67 | 67 | * @return string |
68 | 68 | */ |
69 | - public function npgettext($context, $original, $plural, $value); |
|
69 | + public function npgettext( $context, $original, $plural, $value ); |
|
70 | 70 | |
71 | 71 | /** |
72 | 72 | * Gets a translation checking the context. |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * |
77 | 77 | * @return string |
78 | 78 | */ |
79 | - public function pgettext($context, $original); |
|
79 | + public function pgettext( $context, $original ); |
|
80 | 80 | |
81 | 81 | /** |
82 | 82 | * Gets a translation checking the domain. |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * |
87 | 87 | * @return string |
88 | 88 | */ |
89 | - public function dgettext($domain, $original); |
|
89 | + public function dgettext( $domain, $original ); |
|
90 | 90 | |
91 | 91 | /** |
92 | 92 | * Gets a translation checking the domain and context. |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | * |
98 | 98 | * @return string |
99 | 99 | */ |
100 | - public function dpgettext($domain, $context, $original); |
|
100 | + public function dpgettext( $domain, $context, $original ); |
|
101 | 101 | |
102 | 102 | /** |
103 | 103 | * Gets a translation checking the domain, the context and the plural form. |
@@ -108,5 +108,5 @@ discard block |
||
108 | 108 | * @param string $plural |
109 | 109 | * @param string $value |
110 | 110 | */ |
111 | - public function dnpgettext($domain, $context, $original, $plural, $value); |
|
111 | + public function dnpgettext( $domain, $context, $original, $plural, $value ); |
|
112 | 112 | } |
@@ -5,8 +5,7 @@ |
||
5 | 5 | /** |
6 | 6 | * Interface used by all translators. |
7 | 7 | */ |
8 | -interface TranslatorInterface |
|
9 | -{ |
|
8 | +interface TranslatorInterface { |
|
10 | 9 | /** |
11 | 10 | * Register this translator as global, to use with the gettext functions __(), p__(), etc. |
12 | 11 | * Returns the previous translator if exists. |
@@ -11,15 +11,15 @@ discard block |
||
11 | 11 | */ |
12 | 12 | function __($original) |
13 | 13 | { |
14 | - $text = BaseTranslator::$current->gettext($original); |
|
14 | + $text = BaseTranslator::$current->gettext($original); |
|
15 | 15 | |
16 | - if (func_num_args() === 1) { |
|
17 | - return $text; |
|
18 | - } |
|
16 | + if (func_num_args() === 1) { |
|
17 | + return $text; |
|
18 | + } |
|
19 | 19 | |
20 | - $args = array_slice(func_get_args(), 1); |
|
20 | + $args = array_slice(func_get_args(), 1); |
|
21 | 21 | |
22 | - return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); |
|
22 | + return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | */ |
32 | 32 | function noop__($original) |
33 | 33 | { |
34 | - return $original; |
|
34 | + return $original; |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | /** |
@@ -45,15 +45,15 @@ discard block |
||
45 | 45 | */ |
46 | 46 | function n__($original, $plural, $value) |
47 | 47 | { |
48 | - $text = BaseTranslator::$current->ngettext($original, $plural, $value); |
|
48 | + $text = BaseTranslator::$current->ngettext($original, $plural, $value); |
|
49 | 49 | |
50 | - if (func_num_args() === 3) { |
|
51 | - return $text; |
|
52 | - } |
|
50 | + if (func_num_args() === 3) { |
|
51 | + return $text; |
|
52 | + } |
|
53 | 53 | |
54 | - $args = array_slice(func_get_args(), 3); |
|
54 | + $args = array_slice(func_get_args(), 3); |
|
55 | 55 | |
56 | - return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); |
|
56 | + return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -66,15 +66,15 @@ discard block |
||
66 | 66 | */ |
67 | 67 | function p__($context, $original) |
68 | 68 | { |
69 | - $text = BaseTranslator::$current->pgettext($context, $original); |
|
69 | + $text = BaseTranslator::$current->pgettext($context, $original); |
|
70 | 70 | |
71 | - if (func_num_args() === 2) { |
|
72 | - return $text; |
|
73 | - } |
|
71 | + if (func_num_args() === 2) { |
|
72 | + return $text; |
|
73 | + } |
|
74 | 74 | |
75 | - $args = array_slice(func_get_args(), 2); |
|
75 | + $args = array_slice(func_get_args(), 2); |
|
76 | 76 | |
77 | - return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); |
|
77 | + return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -87,15 +87,15 @@ discard block |
||
87 | 87 | */ |
88 | 88 | function d__($domain, $original) |
89 | 89 | { |
90 | - $text = BaseTranslator::$current->dgettext($domain, $original); |
|
90 | + $text = BaseTranslator::$current->dgettext($domain, $original); |
|
91 | 91 | |
92 | - if (func_num_args() === 2) { |
|
93 | - return $text; |
|
94 | - } |
|
92 | + if (func_num_args() === 2) { |
|
93 | + return $text; |
|
94 | + } |
|
95 | 95 | |
96 | - $args = array_slice(func_get_args(), 2); |
|
96 | + $args = array_slice(func_get_args(), 2); |
|
97 | 97 | |
98 | - return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); |
|
98 | + return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -109,15 +109,15 @@ discard block |
||
109 | 109 | */ |
110 | 110 | function dp__($domain, $context, $original) |
111 | 111 | { |
112 | - $text = BaseTranslator::$current->dpgettext($domain, $context, $original); |
|
112 | + $text = BaseTranslator::$current->dpgettext($domain, $context, $original); |
|
113 | 113 | |
114 | - if (func_num_args() === 3) { |
|
115 | - return $text; |
|
116 | - } |
|
114 | + if (func_num_args() === 3) { |
|
115 | + return $text; |
|
116 | + } |
|
117 | 117 | |
118 | - $args = array_slice(func_get_args(), 3); |
|
118 | + $args = array_slice(func_get_args(), 3); |
|
119 | 119 | |
120 | - return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); |
|
120 | + return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -132,15 +132,15 @@ discard block |
||
132 | 132 | */ |
133 | 133 | function dn__($domain, $original, $plural, $value) |
134 | 134 | { |
135 | - $text = BaseTranslator::$current->dngettext($domain, $original, $plural, $value); |
|
135 | + $text = BaseTranslator::$current->dngettext($domain, $original, $plural, $value); |
|
136 | 136 | |
137 | - if (func_num_args() === 4) { |
|
138 | - return $text; |
|
139 | - } |
|
137 | + if (func_num_args() === 4) { |
|
138 | + return $text; |
|
139 | + } |
|
140 | 140 | |
141 | - $args = array_slice(func_get_args(), 4); |
|
141 | + $args = array_slice(func_get_args(), 4); |
|
142 | 142 | |
143 | - return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); |
|
143 | + return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -155,15 +155,15 @@ discard block |
||
155 | 155 | */ |
156 | 156 | function np__($context, $original, $plural, $value) |
157 | 157 | { |
158 | - $text = BaseTranslator::$current->npgettext($context, $original, $plural, $value); |
|
158 | + $text = BaseTranslator::$current->npgettext($context, $original, $plural, $value); |
|
159 | 159 | |
160 | - if (func_num_args() === 4) { |
|
161 | - return $text; |
|
162 | - } |
|
160 | + if (func_num_args() === 4) { |
|
161 | + return $text; |
|
162 | + } |
|
163 | 163 | |
164 | - $args = array_slice(func_get_args(), 4); |
|
164 | + $args = array_slice(func_get_args(), 4); |
|
165 | 165 | |
166 | - return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); |
|
166 | + return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -179,13 +179,13 @@ discard block |
||
179 | 179 | */ |
180 | 180 | function dnp__($domain, $context, $original, $plural, $value) |
181 | 181 | { |
182 | - $text = BaseTranslator::$current->dnpgettext($domain, $context, $original, $plural, $value); |
|
182 | + $text = BaseTranslator::$current->dnpgettext($domain, $context, $original, $plural, $value); |
|
183 | 183 | |
184 | - if (func_num_args() === 5) { |
|
185 | - return $text; |
|
186 | - } |
|
184 | + if (func_num_args() === 5) { |
|
185 | + return $text; |
|
186 | + } |
|
187 | 187 | |
188 | - $args = array_slice(func_get_args(), 5); |
|
188 | + $args = array_slice(func_get_args(), 5); |
|
189 | 189 | |
190 | - return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); |
|
190 | + return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); |
|
191 | 191 | } |
@@ -9,17 +9,17 @@ discard block |
||
9 | 9 | * |
10 | 10 | * @return string |
11 | 11 | */ |
12 | -function __($original) |
|
12 | +function __( $original ) |
|
13 | 13 | { |
14 | - $text = BaseTranslator::$current->gettext($original); |
|
14 | + $text = BaseTranslator::$current->gettext( $original ); |
|
15 | 15 | |
16 | - if (func_num_args() === 1) { |
|
16 | + if ( func_num_args() === 1 ) { |
|
17 | 17 | return $text; |
18 | 18 | } |
19 | 19 | |
20 | - $args = array_slice(func_get_args(), 1); |
|
20 | + $args = array_slice( func_get_args(), 1 ); |
|
21 | 21 | |
22 | - return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); |
|
22 | + return is_array( $args[ 0 ] ) ? strtr( $text, $args[ 0 ] ) : vsprintf( $text, $args ); |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /** |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @return string |
31 | 31 | */ |
32 | -function noop__($original) |
|
32 | +function noop__( $original ) |
|
33 | 33 | { |
34 | 34 | return $original; |
35 | 35 | } |
@@ -43,17 +43,17 @@ discard block |
||
43 | 43 | * |
44 | 44 | * @return string |
45 | 45 | */ |
46 | -function n__($original, $plural, $value) |
|
46 | +function n__( $original, $plural, $value ) |
|
47 | 47 | { |
48 | - $text = BaseTranslator::$current->ngettext($original, $plural, $value); |
|
48 | + $text = BaseTranslator::$current->ngettext( $original, $plural, $value ); |
|
49 | 49 | |
50 | - if (func_num_args() === 3) { |
|
50 | + if ( func_num_args() === 3 ) { |
|
51 | 51 | return $text; |
52 | 52 | } |
53 | 53 | |
54 | - $args = array_slice(func_get_args(), 3); |
|
54 | + $args = array_slice( func_get_args(), 3 ); |
|
55 | 55 | |
56 | - return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); |
|
56 | + return is_array( $args[ 0 ] ) ? strtr( $text, $args[ 0 ] ) : vsprintf( $text, $args ); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -64,17 +64,17 @@ discard block |
||
64 | 64 | * |
65 | 65 | * @return string |
66 | 66 | */ |
67 | -function p__($context, $original) |
|
67 | +function p__( $context, $original ) |
|
68 | 68 | { |
69 | - $text = BaseTranslator::$current->pgettext($context, $original); |
|
69 | + $text = BaseTranslator::$current->pgettext( $context, $original ); |
|
70 | 70 | |
71 | - if (func_num_args() === 2) { |
|
71 | + if ( func_num_args() === 2 ) { |
|
72 | 72 | return $text; |
73 | 73 | } |
74 | 74 | |
75 | - $args = array_slice(func_get_args(), 2); |
|
75 | + $args = array_slice( func_get_args(), 2 ); |
|
76 | 76 | |
77 | - return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); |
|
77 | + return is_array( $args[ 0 ] ) ? strtr( $text, $args[ 0 ] ) : vsprintf( $text, $args ); |
|
78 | 78 | } |
79 | 79 | |
80 | 80 | /** |
@@ -85,17 +85,17 @@ discard block |
||
85 | 85 | * |
86 | 86 | * @return string |
87 | 87 | */ |
88 | -function d__($domain, $original) |
|
88 | +function d__( $domain, $original ) |
|
89 | 89 | { |
90 | - $text = BaseTranslator::$current->dgettext($domain, $original); |
|
90 | + $text = BaseTranslator::$current->dgettext( $domain, $original ); |
|
91 | 91 | |
92 | - if (func_num_args() === 2) { |
|
92 | + if ( func_num_args() === 2 ) { |
|
93 | 93 | return $text; |
94 | 94 | } |
95 | 95 | |
96 | - $args = array_slice(func_get_args(), 2); |
|
96 | + $args = array_slice( func_get_args(), 2 ); |
|
97 | 97 | |
98 | - return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); |
|
98 | + return is_array( $args[ 0 ] ) ? strtr( $text, $args[ 0 ] ) : vsprintf( $text, $args ); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |
@@ -107,17 +107,17 @@ discard block |
||
107 | 107 | * |
108 | 108 | * @return string |
109 | 109 | */ |
110 | -function dp__($domain, $context, $original) |
|
110 | +function dp__( $domain, $context, $original ) |
|
111 | 111 | { |
112 | - $text = BaseTranslator::$current->dpgettext($domain, $context, $original); |
|
112 | + $text = BaseTranslator::$current->dpgettext( $domain, $context, $original ); |
|
113 | 113 | |
114 | - if (func_num_args() === 3) { |
|
114 | + if ( func_num_args() === 3 ) { |
|
115 | 115 | return $text; |
116 | 116 | } |
117 | 117 | |
118 | - $args = array_slice(func_get_args(), 3); |
|
118 | + $args = array_slice( func_get_args(), 3 ); |
|
119 | 119 | |
120 | - return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); |
|
120 | + return is_array( $args[ 0 ] ) ? strtr( $text, $args[ 0 ] ) : vsprintf( $text, $args ); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -130,17 +130,17 @@ discard block |
||
130 | 130 | * |
131 | 131 | * @return string |
132 | 132 | */ |
133 | -function dn__($domain, $original, $plural, $value) |
|
133 | +function dn__( $domain, $original, $plural, $value ) |
|
134 | 134 | { |
135 | - $text = BaseTranslator::$current->dngettext($domain, $original, $plural, $value); |
|
135 | + $text = BaseTranslator::$current->dngettext( $domain, $original, $plural, $value ); |
|
136 | 136 | |
137 | - if (func_num_args() === 4) { |
|
137 | + if ( func_num_args() === 4 ) { |
|
138 | 138 | return $text; |
139 | 139 | } |
140 | 140 | |
141 | - $args = array_slice(func_get_args(), 4); |
|
141 | + $args = array_slice( func_get_args(), 4 ); |
|
142 | 142 | |
143 | - return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); |
|
143 | + return is_array( $args[ 0 ] ) ? strtr( $text, $args[ 0 ] ) : vsprintf( $text, $args ); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | /** |
@@ -153,17 +153,17 @@ discard block |
||
153 | 153 | * |
154 | 154 | * @return string |
155 | 155 | */ |
156 | -function np__($context, $original, $plural, $value) |
|
156 | +function np__( $context, $original, $plural, $value ) |
|
157 | 157 | { |
158 | - $text = BaseTranslator::$current->npgettext($context, $original, $plural, $value); |
|
158 | + $text = BaseTranslator::$current->npgettext( $context, $original, $plural, $value ); |
|
159 | 159 | |
160 | - if (func_num_args() === 4) { |
|
160 | + if ( func_num_args() === 4 ) { |
|
161 | 161 | return $text; |
162 | 162 | } |
163 | 163 | |
164 | - $args = array_slice(func_get_args(), 4); |
|
164 | + $args = array_slice( func_get_args(), 4 ); |
|
165 | 165 | |
166 | - return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); |
|
166 | + return is_array( $args[ 0 ] ) ? strtr( $text, $args[ 0 ] ) : vsprintf( $text, $args ); |
|
167 | 167 | } |
168 | 168 | |
169 | 169 | /** |
@@ -177,15 +177,15 @@ discard block |
||
177 | 177 | * |
178 | 178 | * @return string |
179 | 179 | */ |
180 | -function dnp__($domain, $context, $original, $plural, $value) |
|
180 | +function dnp__( $domain, $context, $original, $plural, $value ) |
|
181 | 181 | { |
182 | - $text = BaseTranslator::$current->dnpgettext($domain, $context, $original, $plural, $value); |
|
182 | + $text = BaseTranslator::$current->dnpgettext( $domain, $context, $original, $plural, $value ); |
|
183 | 183 | |
184 | - if (func_num_args() === 5) { |
|
184 | + if ( func_num_args() === 5 ) { |
|
185 | 185 | return $text; |
186 | 186 | } |
187 | 187 | |
188 | - $args = array_slice(func_get_args(), 5); |
|
188 | + $args = array_slice( func_get_args(), 5 ); |
|
189 | 189 | |
190 | - return is_array($args[0]) ? strtr($text, $args[0]) : vsprintf($text, $args); |
|
190 | + return is_array( $args[ 0 ] ) ? strtr( $text, $args[ 0 ] ) : vsprintf( $text, $args ); |
|
191 | 191 | } |
@@ -9,8 +9,7 @@ discard block |
||
9 | 9 | * |
10 | 10 | * @return string |
11 | 11 | */ |
12 | -function __($original) |
|
13 | -{ |
|
12 | +function __($original) { |
|
14 | 13 | $text = BaseTranslator::$current->gettext($original); |
15 | 14 | |
16 | 15 | if (func_num_args() === 1) { |
@@ -29,8 +28,7 @@ discard block |
||
29 | 28 | * |
30 | 29 | * @return string |
31 | 30 | */ |
32 | -function noop__($original) |
|
33 | -{ |
|
31 | +function noop__($original) { |
|
34 | 32 | return $original; |
35 | 33 | } |
36 | 34 | |
@@ -43,8 +41,7 @@ discard block |
||
43 | 41 | * |
44 | 42 | * @return string |
45 | 43 | */ |
46 | -function n__($original, $plural, $value) |
|
47 | -{ |
|
44 | +function n__($original, $plural, $value) { |
|
48 | 45 | $text = BaseTranslator::$current->ngettext($original, $plural, $value); |
49 | 46 | |
50 | 47 | if (func_num_args() === 3) { |
@@ -64,8 +61,7 @@ discard block |
||
64 | 61 | * |
65 | 62 | * @return string |
66 | 63 | */ |
67 | -function p__($context, $original) |
|
68 | -{ |
|
64 | +function p__($context, $original) { |
|
69 | 65 | $text = BaseTranslator::$current->pgettext($context, $original); |
70 | 66 | |
71 | 67 | if (func_num_args() === 2) { |
@@ -85,8 +81,7 @@ discard block |
||
85 | 81 | * |
86 | 82 | * @return string |
87 | 83 | */ |
88 | -function d__($domain, $original) |
|
89 | -{ |
|
84 | +function d__($domain, $original) { |
|
90 | 85 | $text = BaseTranslator::$current->dgettext($domain, $original); |
91 | 86 | |
92 | 87 | if (func_num_args() === 2) { |
@@ -107,8 +102,7 @@ discard block |
||
107 | 102 | * |
108 | 103 | * @return string |
109 | 104 | */ |
110 | -function dp__($domain, $context, $original) |
|
111 | -{ |
|
105 | +function dp__($domain, $context, $original) { |
|
112 | 106 | $text = BaseTranslator::$current->dpgettext($domain, $context, $original); |
113 | 107 | |
114 | 108 | if (func_num_args() === 3) { |
@@ -130,8 +124,7 @@ discard block |
||
130 | 124 | * |
131 | 125 | * @return string |
132 | 126 | */ |
133 | -function dn__($domain, $original, $plural, $value) |
|
134 | -{ |
|
127 | +function dn__($domain, $original, $plural, $value) { |
|
135 | 128 | $text = BaseTranslator::$current->dngettext($domain, $original, $plural, $value); |
136 | 129 | |
137 | 130 | if (func_num_args() === 4) { |
@@ -153,8 +146,7 @@ discard block |
||
153 | 146 | * |
154 | 147 | * @return string |
155 | 148 | */ |
156 | -function np__($context, $original, $plural, $value) |
|
157 | -{ |
|
149 | +function np__($context, $original, $plural, $value) { |
|
158 | 150 | $text = BaseTranslator::$current->npgettext($context, $original, $plural, $value); |
159 | 151 | |
160 | 152 | if (func_num_args() === 4) { |
@@ -177,8 +169,7 @@ discard block |
||
177 | 169 | * |
178 | 170 | * @return string |
179 | 171 | */ |
180 | -function dnp__($domain, $context, $original, $plural, $value) |
|
181 | -{ |
|
172 | +function dnp__($domain, $context, $original, $plural, $value) { |
|
182 | 173 | $text = BaseTranslator::$current->dnpgettext($domain, $context, $original, $plural, $value); |
183 | 174 | |
184 | 175 | if (func_num_args() === 5) { |
@@ -7,34 +7,34 @@ |
||
7 | 7 | |
8 | 8 | class PhpArray extends Generator implements GeneratorInterface |
9 | 9 | { |
10 | - use MultidimensionalArrayTrait; |
|
11 | - |
|
12 | - public static $options = [ |
|
13 | - 'includeHeaders' => true, |
|
14 | - ]; |
|
15 | - |
|
16 | - /** |
|
17 | - * {@inheritdoc} |
|
18 | - */ |
|
19 | - public static function toString(Translations $translations, array $options = []) |
|
20 | - { |
|
21 | - $array = static::generate($translations, $options); |
|
22 | - |
|
23 | - return '<?php return '.var_export($array, true).';'; |
|
24 | - } |
|
25 | - |
|
26 | - /** |
|
27 | - * Generates an array with the translations. |
|
28 | - * |
|
29 | - * @param Translations $translations |
|
30 | - * @param array $options |
|
31 | - * |
|
32 | - * @return array |
|
33 | - */ |
|
34 | - public static function generate(Translations $translations, array $options = []) |
|
35 | - { |
|
36 | - $options += static::$options; |
|
37 | - |
|
38 | - return static::toArray($translations, $options['includeHeaders'], true); |
|
39 | - } |
|
10 | + use MultidimensionalArrayTrait; |
|
11 | + |
|
12 | + public static $options = [ |
|
13 | + 'includeHeaders' => true, |
|
14 | + ]; |
|
15 | + |
|
16 | + /** |
|
17 | + * {@inheritdoc} |
|
18 | + */ |
|
19 | + public static function toString(Translations $translations, array $options = []) |
|
20 | + { |
|
21 | + $array = static::generate($translations, $options); |
|
22 | + |
|
23 | + return '<?php return '.var_export($array, true).';'; |
|
24 | + } |
|
25 | + |
|
26 | + /** |
|
27 | + * Generates an array with the translations. |
|
28 | + * |
|
29 | + * @param Translations $translations |
|
30 | + * @param array $options |
|
31 | + * |
|
32 | + * @return array |
|
33 | + */ |
|
34 | + public static function generate(Translations $translations, array $options = []) |
|
35 | + { |
|
36 | + $options += static::$options; |
|
37 | + |
|
38 | + return static::toArray($translations, $options['includeHeaders'], true); |
|
39 | + } |
|
40 | 40 | } |
@@ -16,11 +16,11 @@ discard block |
||
16 | 16 | /** |
17 | 17 | * {@inheritdoc} |
18 | 18 | */ |
19 | - public static function toString(Translations $translations, array $options = []) |
|
19 | + public static function toString( Translations $translations, array $options = [ ] ) |
|
20 | 20 | { |
21 | - $array = static::generate($translations, $options); |
|
21 | + $array = static::generate( $translations, $options ); |
|
22 | 22 | |
23 | - return '<?php return '.var_export($array, true).';'; |
|
23 | + return '<?php return ' . var_export( $array, true ) . ';'; |
|
24 | 24 | } |
25 | 25 | |
26 | 26 | /** |
@@ -31,10 +31,10 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @return array |
33 | 33 | */ |
34 | - public static function generate(Translations $translations, array $options = []) |
|
34 | + public static function generate( Translations $translations, array $options = [ ] ) |
|
35 | 35 | { |
36 | 36 | $options += static::$options; |
37 | 37 | |
38 | - return static::toArray($translations, $options['includeHeaders'], true); |
|
38 | + return static::toArray( $translations, $options[ 'includeHeaders' ], true ); |
|
39 | 39 | } |
40 | 40 | } |
@@ -5,8 +5,7 @@ discard block |
||
5 | 5 | use Gettext\Translations; |
6 | 6 | use Gettext\Utils\MultidimensionalArrayTrait; |
7 | 7 | |
8 | -class PhpArray extends Generator implements GeneratorInterface |
|
9 | -{ |
|
8 | +class PhpArray extends Generator implements GeneratorInterface { |
|
10 | 9 | use MultidimensionalArrayTrait; |
11 | 10 | |
12 | 11 | public static $options = [ |
@@ -16,8 +15,7 @@ discard block |
||
16 | 15 | /** |
17 | 16 | * {@inheritdoc} |
18 | 17 | */ |
19 | - public static function toString(Translations $translations, array $options = []) |
|
20 | - { |
|
18 | + public static function toString(Translations $translations, array $options = []) { |
|
21 | 19 | $array = static::generate($translations, $options); |
22 | 20 | |
23 | 21 | return '<?php return '.var_export($array, true).';'; |
@@ -31,8 +29,7 @@ discard block |
||
31 | 29 | * |
32 | 30 | * @return array |
33 | 31 | */ |
34 | - public static function generate(Translations $translations, array $options = []) |
|
35 | - { |
|
32 | + public static function generate(Translations $translations, array $options = []) { |
|
36 | 33 | $options += static::$options; |
37 | 34 | |
38 | 35 | return static::toArray($translations, $options['includeHeaders'], true); |
@@ -8,32 +8,32 @@ |
||
8 | 8 | |
9 | 9 | class CsvDictionary extends Generator implements GeneratorInterface |
10 | 10 | { |
11 | - use DictionaryTrait; |
|
12 | - use CsvTrait; |
|
13 | - |
|
14 | - public static $options = [ |
|
15 | - 'includeHeaders' => false, |
|
16 | - 'delimiter' => ",", |
|
17 | - 'enclosure' => '"', |
|
18 | - 'escape_char' => "\\" |
|
19 | - ]; |
|
20 | - |
|
21 | - /** |
|
22 | - * {@parentDoc}. |
|
23 | - */ |
|
24 | - public static function toString(Translations $translations, array $options = []) |
|
25 | - { |
|
26 | - $options += static::$options; |
|
27 | - $handle = fopen('php://memory', 'w'); |
|
28 | - |
|
29 | - foreach (static::toArray($translations, $options['includeHeaders']) as $original => $translation) { |
|
30 | - static::fputcsv($handle, [$original, $translation], $options); |
|
31 | - } |
|
32 | - |
|
33 | - rewind($handle); |
|
34 | - $csv = stream_get_contents($handle); |
|
35 | - fclose($handle); |
|
36 | - |
|
37 | - return $csv; |
|
38 | - } |
|
11 | + use DictionaryTrait; |
|
12 | + use CsvTrait; |
|
13 | + |
|
14 | + public static $options = [ |
|
15 | + 'includeHeaders' => false, |
|
16 | + 'delimiter' => ",", |
|
17 | + 'enclosure' => '"', |
|
18 | + 'escape_char' => "\\" |
|
19 | + ]; |
|
20 | + |
|
21 | + /** |
|
22 | + * {@parentDoc}. |
|
23 | + */ |
|
24 | + public static function toString(Translations $translations, array $options = []) |
|
25 | + { |
|
26 | + $options += static::$options; |
|
27 | + $handle = fopen('php://memory', 'w'); |
|
28 | + |
|
29 | + foreach (static::toArray($translations, $options['includeHeaders']) as $original => $translation) { |
|
30 | + static::fputcsv($handle, [$original, $translation], $options); |
|
31 | + } |
|
32 | + |
|
33 | + rewind($handle); |
|
34 | + $csv = stream_get_contents($handle); |
|
35 | + fclose($handle); |
|
36 | + |
|
37 | + return $csv; |
|
38 | + } |
|
39 | 39 | } |
@@ -21,18 +21,18 @@ |
||
21 | 21 | /** |
22 | 22 | * {@parentDoc}. |
23 | 23 | */ |
24 | - public static function toString(Translations $translations, array $options = []) |
|
24 | + public static function toString( Translations $translations, array $options = [ ] ) |
|
25 | 25 | { |
26 | 26 | $options += static::$options; |
27 | - $handle = fopen('php://memory', 'w'); |
|
27 | + $handle = fopen( 'php://memory', 'w' ); |
|
28 | 28 | |
29 | - foreach (static::toArray($translations, $options['includeHeaders']) as $original => $translation) { |
|
30 | - static::fputcsv($handle, [$original, $translation], $options); |
|
29 | + foreach ( static::toArray( $translations, $options[ 'includeHeaders' ] ) as $original => $translation ) { |
|
30 | + static::fputcsv( $handle, [ $original, $translation ], $options ); |
|
31 | 31 | } |
32 | 32 | |
33 | - rewind($handle); |
|
34 | - $csv = stream_get_contents($handle); |
|
35 | - fclose($handle); |
|
33 | + rewind( $handle ); |
|
34 | + $csv = stream_get_contents( $handle ); |
|
35 | + fclose( $handle ); |
|
36 | 36 | |
37 | 37 | return $csv; |
38 | 38 | } |
@@ -6,8 +6,7 @@ discard block |
||
6 | 6 | use Gettext\Utils\DictionaryTrait; |
7 | 7 | use Gettext\Utils\CsvTrait; |
8 | 8 | |
9 | -class CsvDictionary extends Generator implements GeneratorInterface |
|
10 | -{ |
|
9 | +class CsvDictionary extends Generator implements GeneratorInterface { |
|
11 | 10 | use DictionaryTrait; |
12 | 11 | use CsvTrait; |
13 | 12 | |
@@ -21,8 +20,7 @@ discard block |
||
21 | 20 | /** |
22 | 21 | * {@parentDoc}. |
23 | 22 | */ |
24 | - public static function toString(Translations $translations, array $options = []) |
|
25 | - { |
|
23 | + public static function toString(Translations $translations, array $options = []) { |
|
26 | 24 | $options += static::$options; |
27 | 25 | $handle = fopen('php://memory', 'w'); |
28 | 26 |