@@ -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 | } |
@@ -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; |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -13,92 +13,92 @@ discard block |
||
13 | 13 | /** |
14 | 14 | * {@inheritdoc} |
15 | 15 | */ |
16 | - public static function toString(Translations $translations, array $options = []) |
|
16 | + public static function toString( Translations $translations, array $options = [ ] ) |
|
17 | 17 | { |
18 | - $dom = new DOMDocument('1.0', 'utf-8'); |
|
18 | + $dom = new DOMDocument( '1.0', 'utf-8' ); |
|
19 | 19 | $dom->formatOutput = true; |
20 | - $xliff = $dom->appendChild($dom->createElement('xliff')); |
|
21 | - $xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:2.0'); |
|
22 | - $xliff->setAttribute('version', '2.0'); |
|
23 | - $xliff->setAttribute('srcLang', $translations->getLanguage()); |
|
24 | - $xliff->setAttribute('trgLang', $translations->getLanguage()); |
|
25 | - $file = $xliff->appendChild($dom->createElement('file')); |
|
26 | - $file->setAttribute('id', $translations->getDomain().'.'.$translations->getLanguage()); |
|
20 | + $xliff = $dom->appendChild( $dom->createElement( 'xliff' ) ); |
|
21 | + $xliff->setAttribute( 'xmlns', 'urn:oasis:names:tc:xliff:document:2.0' ); |
|
22 | + $xliff->setAttribute( 'version', '2.0' ); |
|
23 | + $xliff->setAttribute( 'srcLang', $translations->getLanguage() ); |
|
24 | + $xliff->setAttribute( 'trgLang', $translations->getLanguage() ); |
|
25 | + $file = $xliff->appendChild( $dom->createElement( 'file' ) ); |
|
26 | + $file->setAttribute( 'id', $translations->getDomain() . '.' . $translations->getLanguage() ); |
|
27 | 27 | |
28 | 28 | //Save headers as notes |
29 | - $notes = $dom->createElement('notes'); |
|
29 | + $notes = $dom->createElement( 'notes' ); |
|
30 | 30 | |
31 | - foreach ($translations->getHeaders() as $name => $value) { |
|
32 | - $notes->appendChild(static::createTextNode($dom, 'note', $value))->setAttribute('id', $name); |
|
31 | + foreach ( $translations->getHeaders() as $name => $value ) { |
|
32 | + $notes->appendChild( static::createTextNode( $dom, 'note', $value ) )->setAttribute( 'id', $name ); |
|
33 | 33 | } |
34 | 34 | |
35 | - if ($notes->hasChildNodes()) { |
|
36 | - $file->appendChild($notes); |
|
35 | + if ( $notes->hasChildNodes() ) { |
|
36 | + $file->appendChild( $notes ); |
|
37 | 37 | } |
38 | 38 | |
39 | - foreach ($translations as $translation) { |
|
39 | + foreach ( $translations as $translation ) { |
|
40 | 40 | //Find an XLIFF unit ID, if one is available; otherwise generate |
41 | - $unitId = static::getUnitID($translation)?:md5($translation->getContext().$translation->getOriginal()); |
|
41 | + $unitId = static::getUnitID( $translation ) ?: md5( $translation->getContext() . $translation->getOriginal() ); |
|
42 | 42 | |
43 | - $unit = $dom->createElement('unit'); |
|
44 | - $unit->setAttribute('id', $unitId); |
|
43 | + $unit = $dom->createElement( 'unit' ); |
|
44 | + $unit->setAttribute( 'id', $unitId ); |
|
45 | 45 | |
46 | 46 | //Save comments as notes |
47 | - $notes = $dom->createElement('notes'); |
|
47 | + $notes = $dom->createElement( 'notes' ); |
|
48 | 48 | |
49 | - $notes->appendChild(static::createTextNode($dom, 'note', $translation->getContext())) |
|
50 | - ->setAttribute('category', 'context'); |
|
49 | + $notes->appendChild( static::createTextNode( $dom, 'note', $translation->getContext() ) ) |
|
50 | + ->setAttribute( 'category', 'context' ); |
|
51 | 51 | |
52 | - foreach ($translation->getComments() as $comment) { |
|
52 | + foreach ( $translation->getComments() as $comment ) { |
|
53 | 53 | //Skip XLIFF unit ID comments. |
54 | - if (preg_match(static::UNIT_ID_REGEXP, $comment)) { |
|
54 | + if ( preg_match( static::UNIT_ID_REGEXP, $comment ) ) { |
|
55 | 55 | continue; |
56 | 56 | } |
57 | 57 | |
58 | - $notes->appendChild(static::createTextNode($dom, 'note', $comment)) |
|
59 | - ->setAttribute('category', 'comment'); |
|
58 | + $notes->appendChild( static::createTextNode( $dom, 'note', $comment ) ) |
|
59 | + ->setAttribute( 'category', 'comment' ); |
|
60 | 60 | } |
61 | 61 | |
62 | - foreach ($translation->getExtractedComments() as $comment) { |
|
63 | - $notes->appendChild(static::createTextNode($dom, 'note', $comment)) |
|
64 | - ->setAttribute('category', 'extracted-comment'); |
|
62 | + foreach ( $translation->getExtractedComments() as $comment ) { |
|
63 | + $notes->appendChild( static::createTextNode( $dom, 'note', $comment ) ) |
|
64 | + ->setAttribute( 'category', 'extracted-comment' ); |
|
65 | 65 | } |
66 | 66 | |
67 | - foreach ($translation->getFlags() as $flag) { |
|
68 | - $notes->appendChild(static::createTextNode($dom, 'note', $flag)) |
|
69 | - ->setAttribute('category', 'flag'); |
|
67 | + foreach ( $translation->getFlags() as $flag ) { |
|
68 | + $notes->appendChild( static::createTextNode( $dom, 'note', $flag ) ) |
|
69 | + ->setAttribute( 'category', 'flag' ); |
|
70 | 70 | } |
71 | 71 | |
72 | - foreach ($translation->getReferences() as $reference) { |
|
73 | - $notes->appendChild(static::createTextNode($dom, 'note', $reference[0].':'.$reference[1])) |
|
74 | - ->setAttribute('category', 'reference'); |
|
72 | + foreach ( $translation->getReferences() as $reference ) { |
|
73 | + $notes->appendChild( static::createTextNode( $dom, 'note', $reference[ 0 ] . ':' . $reference[ 1 ] ) ) |
|
74 | + ->setAttribute( 'category', 'reference' ); |
|
75 | 75 | } |
76 | 76 | |
77 | - $unit->appendChild($notes); |
|
77 | + $unit->appendChild( $notes ); |
|
78 | 78 | |
79 | - $segment = $unit->appendChild($dom->createElement('segment')); |
|
80 | - $segment->appendChild(static::createTextNode($dom, 'source', $translation->getOriginal())); |
|
81 | - $segment->appendChild(static::createTextNode($dom, 'target', $translation->getTranslation())); |
|
79 | + $segment = $unit->appendChild( $dom->createElement( 'segment' ) ); |
|
80 | + $segment->appendChild( static::createTextNode( $dom, 'source', $translation->getOriginal() ) ); |
|
81 | + $segment->appendChild( static::createTextNode( $dom, 'target', $translation->getTranslation() ) ); |
|
82 | 82 | |
83 | - foreach ($translation->getPluralTranslations() as $plural) { |
|
84 | - if ($plural !== '') { |
|
85 | - $segment->appendChild(static::createTextNode($dom, 'target', $plural)); |
|
83 | + foreach ( $translation->getPluralTranslations() as $plural ) { |
|
84 | + if ( $plural !== '' ) { |
|
85 | + $segment->appendChild( static::createTextNode( $dom, 'target', $plural ) ); |
|
86 | 86 | } |
87 | 87 | } |
88 | 88 | |
89 | - $file->appendChild($unit); |
|
89 | + $file->appendChild( $unit ); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | return $dom->saveXML(); |
93 | 93 | } |
94 | 94 | |
95 | - protected static function createTextNode(DOMDocument $dom, $name, $string) |
|
95 | + protected static function createTextNode( DOMDocument $dom, $name, $string ) |
|
96 | 96 | { |
97 | - $node = $dom->createElement($name); |
|
98 | - $text = (preg_match('/[&<>]/', $string) === 1) |
|
99 | - ? $dom->createCDATASection($string) |
|
100 | - : $dom->createTextNode($string); |
|
101 | - $node->appendChild($text); |
|
97 | + $node = $dom->createElement( $name ); |
|
98 | + $text = ( preg_match( '/[&<>]/', $string ) === 1 ) |
|
99 | + ? $dom->createCDATASection( $string ) |
|
100 | + : $dom->createTextNode( $string ); |
|
101 | + $node->appendChild( $text ); |
|
102 | 102 | |
103 | 103 | return $node; |
104 | 104 | } |
@@ -110,11 +110,11 @@ discard block |
||
110 | 110 | * |
111 | 111 | * @return string|null |
112 | 112 | */ |
113 | - public static function getUnitID(Translation $translation) |
|
113 | + public static function getUnitID( Translation $translation ) |
|
114 | 114 | { |
115 | - foreach ($translation->getComments() as $comment) { |
|
116 | - if (preg_match(static::UNIT_ID_REGEXP, $comment, $matches)) { |
|
117 | - return $matches[1]; |
|
115 | + foreach ( $translation->getComments() as $comment ) { |
|
116 | + if ( preg_match( static::UNIT_ID_REGEXP, $comment, $matches ) ) { |
|
117 | + return $matches[ 1 ]; |
|
118 | 118 | } |
119 | 119 | } |
120 | 120 | return null; |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | * |
16 | 16 | * @return bool |
17 | 17 | */ |
18 | - public static function toFile(Translations $translations, $file, array $options = []); |
|
18 | + public static function toFile( Translations $translations, $file, array $options = [ ] ); |
|
19 | 19 | |
20 | 20 | /** |
21 | 21 | * Generates a string with the translations ready to save in a file. |
@@ -25,5 +25,5 @@ discard block |
||
25 | 25 | * |
26 | 26 | * @return string |
27 | 27 | */ |
28 | - public static function toString(Translations $translations, array $options = []); |
|
28 | + public static function toString( Translations $translations, array $options = [ ] ); |
|
29 | 29 | } |