@@ -108,17 +108,17 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function allowed_atts( $atts = array() ) { |
110 | 110 | |
111 | - $atts['data-fancybox'] = null; |
|
112 | - $atts['data-fancybox-trigger'] = null; |
|
113 | - $atts['data-fancybox-index'] = null; |
|
114 | - $atts['data-src'] = null; |
|
115 | - $atts['data-type'] = null; |
|
116 | - $atts['data-width'] = null; |
|
117 | - $atts['data-height'] = null; |
|
118 | - $atts['data-srcset'] = null; |
|
119 | - $atts['data-caption'] = null; |
|
120 | - $atts['data-options'] = null; |
|
121 | - $atts['data-filter'] = null; |
|
111 | + $atts[ 'data-fancybox' ] = null; |
|
112 | + $atts[ 'data-fancybox-trigger' ] = null; |
|
113 | + $atts[ 'data-fancybox-index' ] = null; |
|
114 | + $atts[ 'data-src' ] = null; |
|
115 | + $atts[ 'data-type' ] = null; |
|
116 | + $atts[ 'data-width' ] = null; |
|
117 | + $atts[ 'data-height' ] = null; |
|
118 | + $atts[ 'data-srcset' ] = null; |
|
119 | + $atts[ 'data-caption' ] = null; |
|
120 | + $atts[ 'data-options' ] = null; |
|
121 | + $atts[ 'data-filter' ] = null; |
|
122 | 122 | |
123 | 123 | return $atts; |
124 | 124 | } |
@@ -133,23 +133,23 @@ discard block |
||
133 | 133 | } |
134 | 134 | |
135 | 135 | // Prevent empty content from getting added to the lightbox gallery |
136 | - if ( is_array( $additional_details ) && empty( $additional_details['file_path'] ) ) { |
|
136 | + if ( is_array( $additional_details ) && empty( $additional_details[ 'file_path' ] ) ) { |
|
137 | 137 | return $link_atts; |
138 | 138 | } |
139 | 139 | |
140 | 140 | // Prevent empty content from getting added to the lightbox gallery |
141 | - if ( is_array( $additional_details ) && ! empty( $additional_details['disable_lightbox'] ) ) { |
|
141 | + if ( is_array( $additional_details ) && ! empty( $additional_details[ 'disable_lightbox' ] ) ) { |
|
142 | 142 | return $link_atts; |
143 | 143 | } |
144 | 144 | |
145 | - $link_atts['class'] = \GV\Utils::get( $link_atts, 'class' ) . ' gravityview-fancybox'; |
|
145 | + $link_atts[ 'class' ] = \GV\Utils::get( $link_atts, 'class' ) . ' gravityview-fancybox'; |
|
146 | 146 | |
147 | - $link_atts['class'] = gravityview_sanitize_html_class( $link_atts['class'] ); |
|
147 | + $link_atts[ 'class' ] = gravityview_sanitize_html_class( $link_atts[ 'class' ] ); |
|
148 | 148 | |
149 | 149 | if ( $context && ! empty( $context->field->field ) ) { |
150 | 150 | if ( $context->field->field->multipleFiles ) { |
151 | 151 | $entry = $context->entry->as_entry(); |
152 | - $link_atts['data-fancybox'] = 'gallery-' . sprintf( "%s-%s-%s", $entry['form_id'], $context->field->ID, $context->entry->get_slug() ); |
|
152 | + $link_atts[ 'data-fancybox' ] = 'gallery-' . sprintf( "%s-%s-%s", $entry[ 'form_id' ], $context->field->ID, $context->entry->get_slug() ); |
|
153 | 153 | } |
154 | 154 | } |
155 | 155 | |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | * @see https://fancyapps.com/docs/ui/fancybox#media-types |
161 | 161 | */ |
162 | 162 | if ( false !== strpos( $file_path, 'gv-iframe' ) ) { |
163 | - $link_atts['data-type'] = 'pdf'; |
|
163 | + $link_atts[ 'data-type' ] = 'pdf'; |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | return $link_atts; |
@@ -9,403 +9,403 @@ |
||
9 | 9 | */ |
10 | 10 | class Language |
11 | 11 | { |
12 | - /** |
|
13 | - * The language ID. |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - public $id; |
|
12 | + /** |
|
13 | + * The language ID. |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + public $id; |
|
18 | 18 | |
19 | - /** |
|
20 | - * The language name. |
|
21 | - * |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - public $name; |
|
19 | + /** |
|
20 | + * The language name. |
|
21 | + * |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + public $name; |
|
25 | 25 | |
26 | - /** |
|
27 | - * If this language is deprecated: the gettext code of the new language. |
|
28 | - * |
|
29 | - * @var string|null |
|
30 | - */ |
|
31 | - public $supersededBy; |
|
26 | + /** |
|
27 | + * If this language is deprecated: the gettext code of the new language. |
|
28 | + * |
|
29 | + * @var string|null |
|
30 | + */ |
|
31 | + public $supersededBy; |
|
32 | 32 | |
33 | - /** |
|
34 | - * The script name. |
|
35 | - * |
|
36 | - * @var string|null |
|
37 | - */ |
|
38 | - public $script; |
|
33 | + /** |
|
34 | + * The script name. |
|
35 | + * |
|
36 | + * @var string|null |
|
37 | + */ |
|
38 | + public $script; |
|
39 | 39 | |
40 | - /** |
|
41 | - * The territory name. |
|
42 | - * |
|
43 | - * @var string|null |
|
44 | - */ |
|
45 | - public $territory; |
|
40 | + /** |
|
41 | + * The territory name. |
|
42 | + * |
|
43 | + * @var string|null |
|
44 | + */ |
|
45 | + public $territory; |
|
46 | 46 | |
47 | - /** |
|
48 | - * The name of the base language. |
|
49 | - * |
|
50 | - * @var string|null |
|
51 | - */ |
|
52 | - public $baseLanguage; |
|
47 | + /** |
|
48 | + * The name of the base language. |
|
49 | + * |
|
50 | + * @var string|null |
|
51 | + */ |
|
52 | + public $baseLanguage; |
|
53 | 53 | |
54 | - /** |
|
55 | - * The list of categories. |
|
56 | - * |
|
57 | - * @var \Gettext\Languages\Category[] |
|
58 | - */ |
|
59 | - public $categories; |
|
54 | + /** |
|
55 | + * The list of categories. |
|
56 | + * |
|
57 | + * @var \Gettext\Languages\Category[] |
|
58 | + */ |
|
59 | + public $categories; |
|
60 | 60 | |
61 | - /** |
|
62 | - * The gettext formula to decide which category should be applied. |
|
63 | - * |
|
64 | - * @var string |
|
65 | - */ |
|
66 | - public $formula; |
|
61 | + /** |
|
62 | + * The gettext formula to decide which category should be applied. |
|
63 | + * |
|
64 | + * @var string |
|
65 | + */ |
|
66 | + public $formula; |
|
67 | 67 | |
68 | - /** |
|
69 | - * Initialize the instance and parse the language code. |
|
70 | - * |
|
71 | - * @param array $info The result of CldrData::getLanguageInfo() |
|
72 | - * |
|
73 | - * @throws \Exception throws an Exception if $fullId is not valid |
|
74 | - */ |
|
75 | - private function __construct($info) |
|
76 | - { |
|
77 | - $this->id = $info['id']; |
|
78 | - $this->name = $info['name']; |
|
79 | - $this->supersededBy = isset($info['supersededBy']) ? $info['supersededBy'] : null; |
|
80 | - $this->script = isset($info['script']) ? $info['script'] : null; |
|
81 | - $this->territory = isset($info['territory']) ? $info['territory'] : null; |
|
82 | - $this->baseLanguage = isset($info['baseLanguage']) ? $info['baseLanguage'] : null; |
|
83 | - // Let's build the category list |
|
84 | - $this->categories = array(); |
|
85 | - foreach ($info['categories'] as $cldrCategoryId => $cldrFormulaAndExamples) { |
|
86 | - $category = new Category($cldrCategoryId, $cldrFormulaAndExamples); |
|
87 | - foreach ($this->categories as $c) { |
|
88 | - if ($category->id === $c->id) { |
|
89 | - throw new Exception("The category '{$category->id}' is specified more than once"); |
|
90 | - } |
|
91 | - } |
|
92 | - $this->categories[] = $category; |
|
93 | - } |
|
94 | - if (empty($this->categories)) { |
|
95 | - throw new Exception("The language '{$info['id']}' does not have any plural category"); |
|
96 | - } |
|
97 | - // Let's sort the categories from 'zero' to 'other' |
|
98 | - usort($this->categories, function (Category $category1, Category $category2) { |
|
99 | - return array_search($category1->id, CldrData::$categories) - array_search($category2->id, CldrData::$categories); |
|
100 | - }); |
|
101 | - // The 'other' category should always be there |
|
102 | - if ($this->categories[count($this->categories) - 1]->id !== CldrData::OTHER_CATEGORY) { |
|
103 | - throw new Exception("The language '{$info['id']}' does not have the '" . CldrData::OTHER_CATEGORY . "' plural category"); |
|
104 | - } |
|
105 | - $this->checkAlwaysTrueCategories(); |
|
106 | - $this->checkAlwaysFalseCategories(); |
|
107 | - $this->checkAllCategoriesWithExamples(); |
|
108 | - $this->formula = $this->buildFormula(); |
|
109 | - } |
|
68 | + /** |
|
69 | + * Initialize the instance and parse the language code. |
|
70 | + * |
|
71 | + * @param array $info The result of CldrData::getLanguageInfo() |
|
72 | + * |
|
73 | + * @throws \Exception throws an Exception if $fullId is not valid |
|
74 | + */ |
|
75 | + private function __construct($info) |
|
76 | + { |
|
77 | + $this->id = $info['id']; |
|
78 | + $this->name = $info['name']; |
|
79 | + $this->supersededBy = isset($info['supersededBy']) ? $info['supersededBy'] : null; |
|
80 | + $this->script = isset($info['script']) ? $info['script'] : null; |
|
81 | + $this->territory = isset($info['territory']) ? $info['territory'] : null; |
|
82 | + $this->baseLanguage = isset($info['baseLanguage']) ? $info['baseLanguage'] : null; |
|
83 | + // Let's build the category list |
|
84 | + $this->categories = array(); |
|
85 | + foreach ($info['categories'] as $cldrCategoryId => $cldrFormulaAndExamples) { |
|
86 | + $category = new Category($cldrCategoryId, $cldrFormulaAndExamples); |
|
87 | + foreach ($this->categories as $c) { |
|
88 | + if ($category->id === $c->id) { |
|
89 | + throw new Exception("The category '{$category->id}' is specified more than once"); |
|
90 | + } |
|
91 | + } |
|
92 | + $this->categories[] = $category; |
|
93 | + } |
|
94 | + if (empty($this->categories)) { |
|
95 | + throw new Exception("The language '{$info['id']}' does not have any plural category"); |
|
96 | + } |
|
97 | + // Let's sort the categories from 'zero' to 'other' |
|
98 | + usort($this->categories, function (Category $category1, Category $category2) { |
|
99 | + return array_search($category1->id, CldrData::$categories) - array_search($category2->id, CldrData::$categories); |
|
100 | + }); |
|
101 | + // The 'other' category should always be there |
|
102 | + if ($this->categories[count($this->categories) - 1]->id !== CldrData::OTHER_CATEGORY) { |
|
103 | + throw new Exception("The language '{$info['id']}' does not have the '" . CldrData::OTHER_CATEGORY . "' plural category"); |
|
104 | + } |
|
105 | + $this->checkAlwaysTrueCategories(); |
|
106 | + $this->checkAlwaysFalseCategories(); |
|
107 | + $this->checkAllCategoriesWithExamples(); |
|
108 | + $this->formula = $this->buildFormula(); |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * Return a list of all languages available. |
|
113 | - * |
|
114 | - * @throws \Exception |
|
115 | - * |
|
116 | - * @return \Gettext\Languages\Language[] |
|
117 | - */ |
|
118 | - public static function getAll() |
|
119 | - { |
|
120 | - $result = array(); |
|
121 | - foreach (array_keys(CldrData::getLanguageNames()) as $cldrLanguageId) { |
|
122 | - $result[] = new self(CldrData::getLanguageInfo($cldrLanguageId)); |
|
123 | - } |
|
111 | + /** |
|
112 | + * Return a list of all languages available. |
|
113 | + * |
|
114 | + * @throws \Exception |
|
115 | + * |
|
116 | + * @return \Gettext\Languages\Language[] |
|
117 | + */ |
|
118 | + public static function getAll() |
|
119 | + { |
|
120 | + $result = array(); |
|
121 | + foreach (array_keys(CldrData::getLanguageNames()) as $cldrLanguageId) { |
|
122 | + $result[] = new self(CldrData::getLanguageInfo($cldrLanguageId)); |
|
123 | + } |
|
124 | 124 | |
125 | - return $result; |
|
126 | - } |
|
125 | + return $result; |
|
126 | + } |
|
127 | 127 | |
128 | - /** |
|
129 | - * Return a Language instance given the language id. |
|
130 | - * |
|
131 | - * @param string $id |
|
132 | - * |
|
133 | - * @return \Gettext\Languages\Language|null |
|
134 | - */ |
|
135 | - public static function getById($id) |
|
136 | - { |
|
137 | - $result = null; |
|
138 | - $info = CldrData::getLanguageInfo($id); |
|
139 | - if (isset($info)) { |
|
140 | - $result = new self($info); |
|
141 | - } |
|
128 | + /** |
|
129 | + * Return a Language instance given the language id. |
|
130 | + * |
|
131 | + * @param string $id |
|
132 | + * |
|
133 | + * @return \Gettext\Languages\Language|null |
|
134 | + */ |
|
135 | + public static function getById($id) |
|
136 | + { |
|
137 | + $result = null; |
|
138 | + $info = CldrData::getLanguageInfo($id); |
|
139 | + if (isset($info)) { |
|
140 | + $result = new self($info); |
|
141 | + } |
|
142 | 142 | |
143 | - return $result; |
|
144 | - } |
|
143 | + return $result; |
|
144 | + } |
|
145 | 145 | |
146 | - /** |
|
147 | - * Returns a clone of this instance with all the strings to US-ASCII. |
|
148 | - * |
|
149 | - * @return \Gettext\Languages\Language |
|
150 | - */ |
|
151 | - public function getUSAsciiClone() |
|
152 | - { |
|
153 | - $clone = clone $this; |
|
154 | - self::asciifier($clone->name); |
|
155 | - self::asciifier($clone->formula); |
|
156 | - $clone->categories = array(); |
|
157 | - foreach ($this->categories as $category) { |
|
158 | - $categoryClone = clone $category; |
|
159 | - self::asciifier($categoryClone->examples); |
|
160 | - $clone->categories[] = $categoryClone; |
|
161 | - } |
|
146 | + /** |
|
147 | + * Returns a clone of this instance with all the strings to US-ASCII. |
|
148 | + * |
|
149 | + * @return \Gettext\Languages\Language |
|
150 | + */ |
|
151 | + public function getUSAsciiClone() |
|
152 | + { |
|
153 | + $clone = clone $this; |
|
154 | + self::asciifier($clone->name); |
|
155 | + self::asciifier($clone->formula); |
|
156 | + $clone->categories = array(); |
|
157 | + foreach ($this->categories as $category) { |
|
158 | + $categoryClone = clone $category; |
|
159 | + self::asciifier($categoryClone->examples); |
|
160 | + $clone->categories[] = $categoryClone; |
|
161 | + } |
|
162 | 162 | |
163 | - return $clone; |
|
164 | - } |
|
163 | + return $clone; |
|
164 | + } |
|
165 | 165 | |
166 | - /** |
|
167 | - * Build the formula starting from the currently defined categories. |
|
168 | - * |
|
169 | - * @param bool $withoutParenthesis TRUE to build a formula in standard gettext format, FALSE (default) to build a PHP-compatible formula |
|
170 | - * |
|
171 | - * @return string |
|
172 | - */ |
|
173 | - public function buildFormula($withoutParenthesis = false) |
|
174 | - { |
|
175 | - $numCategories = count($this->categories); |
|
176 | - switch ($numCategories) { |
|
177 | - case 1: |
|
178 | - // Just one category |
|
179 | - return '0'; |
|
180 | - case 2: |
|
181 | - return self::reduceFormula(self::reverseFormula($this->categories[0]->formula)); |
|
182 | - default: |
|
183 | - $formula = (string) ($numCategories - 1); |
|
184 | - for ($i = $numCategories - 2; $i >= 0; $i--) { |
|
185 | - $f = self::reduceFormula($this->categories[$i]->formula); |
|
186 | - if (!$withoutParenthesis && !preg_match('/^\([^()]+\)$/', $f)) { |
|
187 | - $f = "({$f})"; |
|
188 | - } |
|
189 | - $formula = "{$f} ? {$i} : {$formula}"; |
|
190 | - if (!$withoutParenthesis && $i > 0) { |
|
191 | - $formula = "({$formula})"; |
|
192 | - } |
|
193 | - } |
|
166 | + /** |
|
167 | + * Build the formula starting from the currently defined categories. |
|
168 | + * |
|
169 | + * @param bool $withoutParenthesis TRUE to build a formula in standard gettext format, FALSE (default) to build a PHP-compatible formula |
|
170 | + * |
|
171 | + * @return string |
|
172 | + */ |
|
173 | + public function buildFormula($withoutParenthesis = false) |
|
174 | + { |
|
175 | + $numCategories = count($this->categories); |
|
176 | + switch ($numCategories) { |
|
177 | + case 1: |
|
178 | + // Just one category |
|
179 | + return '0'; |
|
180 | + case 2: |
|
181 | + return self::reduceFormula(self::reverseFormula($this->categories[0]->formula)); |
|
182 | + default: |
|
183 | + $formula = (string) ($numCategories - 1); |
|
184 | + for ($i = $numCategories - 2; $i >= 0; $i--) { |
|
185 | + $f = self::reduceFormula($this->categories[$i]->formula); |
|
186 | + if (!$withoutParenthesis && !preg_match('/^\([^()]+\)$/', $f)) { |
|
187 | + $f = "({$f})"; |
|
188 | + } |
|
189 | + $formula = "{$f} ? {$i} : {$formula}"; |
|
190 | + if (!$withoutParenthesis && $i > 0) { |
|
191 | + $formula = "({$formula})"; |
|
192 | + } |
|
193 | + } |
|
194 | 194 | |
195 | - return $formula; |
|
196 | - } |
|
197 | - } |
|
195 | + return $formula; |
|
196 | + } |
|
197 | + } |
|
198 | 198 | |
199 | - /** |
|
200 | - * Let's look for categories that will always occur. |
|
201 | - * This because with decimals (CLDR) we may have more cases, with integers (gettext) we have just one case. |
|
202 | - * If we found that (single) category we reduce the categories to that one only. |
|
203 | - * |
|
204 | - * @throws \Exception |
|
205 | - */ |
|
206 | - private function checkAlwaysTrueCategories() |
|
207 | - { |
|
208 | - $alwaysTrueCategory = null; |
|
209 | - foreach ($this->categories as $category) { |
|
210 | - if ($category->formula === true) { |
|
211 | - if (!isset($category->examples)) { |
|
212 | - throw new Exception("The category '{$category->id}' should always occur, but it does not have examples (so for CLDR it will never occur for integers!)"); |
|
213 | - } |
|
214 | - $alwaysTrueCategory = $category; |
|
215 | - break; |
|
216 | - } |
|
217 | - } |
|
218 | - if (isset($alwaysTrueCategory)) { |
|
219 | - foreach ($this->categories as $category) { |
|
220 | - if (($category !== $alwaysTrueCategory) && isset($category->examples)) { |
|
221 | - throw new Exception("The category '{$category->id}' should never occur, but it has some examples (so for CLDR it will occur!)"); |
|
222 | - } |
|
223 | - } |
|
224 | - $alwaysTrueCategory->id = CldrData::OTHER_CATEGORY; |
|
225 | - $alwaysTrueCategory->formula = null; |
|
226 | - $this->categories = array($alwaysTrueCategory); |
|
227 | - } |
|
228 | - } |
|
199 | + /** |
|
200 | + * Let's look for categories that will always occur. |
|
201 | + * This because with decimals (CLDR) we may have more cases, with integers (gettext) we have just one case. |
|
202 | + * If we found that (single) category we reduce the categories to that one only. |
|
203 | + * |
|
204 | + * @throws \Exception |
|
205 | + */ |
|
206 | + private function checkAlwaysTrueCategories() |
|
207 | + { |
|
208 | + $alwaysTrueCategory = null; |
|
209 | + foreach ($this->categories as $category) { |
|
210 | + if ($category->formula === true) { |
|
211 | + if (!isset($category->examples)) { |
|
212 | + throw new Exception("The category '{$category->id}' should always occur, but it does not have examples (so for CLDR it will never occur for integers!)"); |
|
213 | + } |
|
214 | + $alwaysTrueCategory = $category; |
|
215 | + break; |
|
216 | + } |
|
217 | + } |
|
218 | + if (isset($alwaysTrueCategory)) { |
|
219 | + foreach ($this->categories as $category) { |
|
220 | + if (($category !== $alwaysTrueCategory) && isset($category->examples)) { |
|
221 | + throw new Exception("The category '{$category->id}' should never occur, but it has some examples (so for CLDR it will occur!)"); |
|
222 | + } |
|
223 | + } |
|
224 | + $alwaysTrueCategory->id = CldrData::OTHER_CATEGORY; |
|
225 | + $alwaysTrueCategory->formula = null; |
|
226 | + $this->categories = array($alwaysTrueCategory); |
|
227 | + } |
|
228 | + } |
|
229 | 229 | |
230 | - /** |
|
231 | - * Let's look for categories that will never occur. |
|
232 | - * This because with decimals (CLDR) we may have more cases, with integers (gettext) we have some less cases. |
|
233 | - * If we found those categories we strip them out. |
|
234 | - * |
|
235 | - * @throws \Exception |
|
236 | - */ |
|
237 | - private function checkAlwaysFalseCategories() |
|
238 | - { |
|
239 | - $filtered = array(); |
|
240 | - foreach ($this->categories as $category) { |
|
241 | - if ($category->formula === false) { |
|
242 | - if (isset($category->examples)) { |
|
243 | - throw new Exception("The category '{$category->id}' should never occur, but it has examples (so for CLDR it may occur!)"); |
|
244 | - } |
|
245 | - } else { |
|
246 | - $filtered[] = $category; |
|
247 | - } |
|
248 | - } |
|
249 | - $this->categories = $filtered; |
|
250 | - } |
|
230 | + /** |
|
231 | + * Let's look for categories that will never occur. |
|
232 | + * This because with decimals (CLDR) we may have more cases, with integers (gettext) we have some less cases. |
|
233 | + * If we found those categories we strip them out. |
|
234 | + * |
|
235 | + * @throws \Exception |
|
236 | + */ |
|
237 | + private function checkAlwaysFalseCategories() |
|
238 | + { |
|
239 | + $filtered = array(); |
|
240 | + foreach ($this->categories as $category) { |
|
241 | + if ($category->formula === false) { |
|
242 | + if (isset($category->examples)) { |
|
243 | + throw new Exception("The category '{$category->id}' should never occur, but it has examples (so for CLDR it may occur!)"); |
|
244 | + } |
|
245 | + } else { |
|
246 | + $filtered[] = $category; |
|
247 | + } |
|
248 | + } |
|
249 | + $this->categories = $filtered; |
|
250 | + } |
|
251 | 251 | |
252 | - /** |
|
253 | - * Let's look for categories that don't have examples. |
|
254 | - * This because with decimals (CLDR) we may have more cases, with integers (gettext) we have some less cases. |
|
255 | - * If we found those categories, we check that they never occur and we strip them out. |
|
256 | - * |
|
257 | - * @throws \Exception |
|
258 | - */ |
|
259 | - private function checkAllCategoriesWithExamples() |
|
260 | - { |
|
261 | - $allCategoriesIds = array(); |
|
262 | - $goodCategories = array(); |
|
263 | - $badCategories = array(); |
|
264 | - $badCategoriesIds = array(); |
|
265 | - foreach ($this->categories as $category) { |
|
266 | - $allCategoriesIds[] = $category->id; |
|
267 | - if (isset($category->examples)) { |
|
268 | - $goodCategories[] = $category; |
|
269 | - } else { |
|
270 | - $badCategories[] = $category; |
|
271 | - $badCategoriesIds[] = $category->id; |
|
272 | - } |
|
273 | - } |
|
274 | - if (empty($badCategories)) { |
|
275 | - return; |
|
276 | - } |
|
277 | - $removeCategoriesWithoutExamples = false; |
|
278 | - switch (implode(',', $badCategoriesIds) . '@' . implode(',', $allCategoriesIds)) { |
|
279 | - case CldrData::OTHER_CATEGORY . '@one,few,many,' . CldrData::OTHER_CATEGORY: |
|
280 | - switch ($this->buildFormula()) { |
|
281 | - case '(n % 10 == 1 && n % 100 != 11) ? 0 : ((n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) ? 1 : ((n % 10 == 0 || n % 10 >= 5 && n % 10 <= 9 || n % 100 >= 11 && n % 100 <= 14) ? 2 : 3))': |
|
282 | - // Numbers ending with 0 => case 2 ('many') |
|
283 | - // Numbers ending with 1 but not with 11 => case 0 ('one') |
|
284 | - // Numbers ending with 11 => case 2 ('many') |
|
285 | - // Numbers ending with 2 but not with 12 => case 1 ('few') |
|
286 | - // Numbers ending with 12 => case 2 ('many') |
|
287 | - // Numbers ending with 3 but not with 13 => case 1 ('few') |
|
288 | - // Numbers ending with 13 => case 2 ('many') |
|
289 | - // Numbers ending with 4 but not with 14 => case 1 ('few') |
|
290 | - // Numbers ending with 14 => case 2 ('many') |
|
291 | - // Numbers ending with 5 => case 2 ('many') |
|
292 | - // Numbers ending with 6 => case 2 ('many') |
|
293 | - // Numbers ending with 7 => case 2 ('many') |
|
294 | - // Numbers ending with 8 => case 2 ('many') |
|
295 | - // Numbers ending with 9 => case 2 ('many') |
|
296 | - // => the 'other' case never occurs: use 'other' for 'many' |
|
297 | - $removeCategoriesWithoutExamples = true; |
|
298 | - break; |
|
299 | - case '(n == 1) ? 0 : ((n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) ? 1 : ((n != 1 && (n % 10 == 0 || n % 10 == 1) || n % 10 >= 5 && n % 10 <= 9 || n % 100 >= 12 && n % 100 <= 14) ? 2 : 3))': |
|
300 | - // Numbers ending with 0 => case 2 ('many') |
|
301 | - // Numbers ending with 1 but not number 1 => case 2 ('many') |
|
302 | - // Number 1 => case 0 ('one') |
|
303 | - // Numbers ending with 2 but not with 12 => case 1 ('few') |
|
304 | - // Numbers ending with 12 => case 2 ('many') |
|
305 | - // Numbers ending with 3 but not with 13 => case 1 ('few') |
|
306 | - // Numbers ending with 13 => case 2 ('many') |
|
307 | - // Numbers ending with 4 but not with 14 => case 1 ('few') |
|
308 | - // Numbers ending with 14 => case 2 ('many') |
|
309 | - // Numbers ending with 5 => case 2 ('many') |
|
310 | - // Numbers ending with 6 => case 2 ('many') |
|
311 | - // Numbers ending with 7 => case 2 ('many') |
|
312 | - // Numbers ending with 8 => case 2 ('many') |
|
313 | - // Numbers ending with 9 => case 2 ('many') |
|
314 | - // => the 'other' case never occurs: use 'other' for 'many' |
|
315 | - $removeCategoriesWithoutExamples = true; |
|
316 | - break; |
|
317 | - } |
|
318 | - } |
|
319 | - if (!$removeCategoriesWithoutExamples) { |
|
320 | - throw new Exception("Unhandled case of plural categories without examples '" . implode(', ', $badCategoriesIds) . "' out of '" . implode(', ', $allCategoriesIds) . "'"); |
|
321 | - } |
|
322 | - if ($badCategories[count($badCategories) - 1]->id === CldrData::OTHER_CATEGORY) { |
|
323 | - // We're removing the 'other' cagory: let's change the last good category to 'other' |
|
324 | - $lastGood = $goodCategories[count($goodCategories) - 1]; |
|
325 | - $lastGood->id = CldrData::OTHER_CATEGORY; |
|
326 | - $lastGood->formula = null; |
|
327 | - } |
|
328 | - $this->categories = $goodCategories; |
|
329 | - } |
|
252 | + /** |
|
253 | + * Let's look for categories that don't have examples. |
|
254 | + * This because with decimals (CLDR) we may have more cases, with integers (gettext) we have some less cases. |
|
255 | + * If we found those categories, we check that they never occur and we strip them out. |
|
256 | + * |
|
257 | + * @throws \Exception |
|
258 | + */ |
|
259 | + private function checkAllCategoriesWithExamples() |
|
260 | + { |
|
261 | + $allCategoriesIds = array(); |
|
262 | + $goodCategories = array(); |
|
263 | + $badCategories = array(); |
|
264 | + $badCategoriesIds = array(); |
|
265 | + foreach ($this->categories as $category) { |
|
266 | + $allCategoriesIds[] = $category->id; |
|
267 | + if (isset($category->examples)) { |
|
268 | + $goodCategories[] = $category; |
|
269 | + } else { |
|
270 | + $badCategories[] = $category; |
|
271 | + $badCategoriesIds[] = $category->id; |
|
272 | + } |
|
273 | + } |
|
274 | + if (empty($badCategories)) { |
|
275 | + return; |
|
276 | + } |
|
277 | + $removeCategoriesWithoutExamples = false; |
|
278 | + switch (implode(',', $badCategoriesIds) . '@' . implode(',', $allCategoriesIds)) { |
|
279 | + case CldrData::OTHER_CATEGORY . '@one,few,many,' . CldrData::OTHER_CATEGORY: |
|
280 | + switch ($this->buildFormula()) { |
|
281 | + case '(n % 10 == 1 && n % 100 != 11) ? 0 : ((n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) ? 1 : ((n % 10 == 0 || n % 10 >= 5 && n % 10 <= 9 || n % 100 >= 11 && n % 100 <= 14) ? 2 : 3))': |
|
282 | + // Numbers ending with 0 => case 2 ('many') |
|
283 | + // Numbers ending with 1 but not with 11 => case 0 ('one') |
|
284 | + // Numbers ending with 11 => case 2 ('many') |
|
285 | + // Numbers ending with 2 but not with 12 => case 1 ('few') |
|
286 | + // Numbers ending with 12 => case 2 ('many') |
|
287 | + // Numbers ending with 3 but not with 13 => case 1 ('few') |
|
288 | + // Numbers ending with 13 => case 2 ('many') |
|
289 | + // Numbers ending with 4 but not with 14 => case 1 ('few') |
|
290 | + // Numbers ending with 14 => case 2 ('many') |
|
291 | + // Numbers ending with 5 => case 2 ('many') |
|
292 | + // Numbers ending with 6 => case 2 ('many') |
|
293 | + // Numbers ending with 7 => case 2 ('many') |
|
294 | + // Numbers ending with 8 => case 2 ('many') |
|
295 | + // Numbers ending with 9 => case 2 ('many') |
|
296 | + // => the 'other' case never occurs: use 'other' for 'many' |
|
297 | + $removeCategoriesWithoutExamples = true; |
|
298 | + break; |
|
299 | + case '(n == 1) ? 0 : ((n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) ? 1 : ((n != 1 && (n % 10 == 0 || n % 10 == 1) || n % 10 >= 5 && n % 10 <= 9 || n % 100 >= 12 && n % 100 <= 14) ? 2 : 3))': |
|
300 | + // Numbers ending with 0 => case 2 ('many') |
|
301 | + // Numbers ending with 1 but not number 1 => case 2 ('many') |
|
302 | + // Number 1 => case 0 ('one') |
|
303 | + // Numbers ending with 2 but not with 12 => case 1 ('few') |
|
304 | + // Numbers ending with 12 => case 2 ('many') |
|
305 | + // Numbers ending with 3 but not with 13 => case 1 ('few') |
|
306 | + // Numbers ending with 13 => case 2 ('many') |
|
307 | + // Numbers ending with 4 but not with 14 => case 1 ('few') |
|
308 | + // Numbers ending with 14 => case 2 ('many') |
|
309 | + // Numbers ending with 5 => case 2 ('many') |
|
310 | + // Numbers ending with 6 => case 2 ('many') |
|
311 | + // Numbers ending with 7 => case 2 ('many') |
|
312 | + // Numbers ending with 8 => case 2 ('many') |
|
313 | + // Numbers ending with 9 => case 2 ('many') |
|
314 | + // => the 'other' case never occurs: use 'other' for 'many' |
|
315 | + $removeCategoriesWithoutExamples = true; |
|
316 | + break; |
|
317 | + } |
|
318 | + } |
|
319 | + if (!$removeCategoriesWithoutExamples) { |
|
320 | + throw new Exception("Unhandled case of plural categories without examples '" . implode(', ', $badCategoriesIds) . "' out of '" . implode(', ', $allCategoriesIds) . "'"); |
|
321 | + } |
|
322 | + if ($badCategories[count($badCategories) - 1]->id === CldrData::OTHER_CATEGORY) { |
|
323 | + // We're removing the 'other' cagory: let's change the last good category to 'other' |
|
324 | + $lastGood = $goodCategories[count($goodCategories) - 1]; |
|
325 | + $lastGood->id = CldrData::OTHER_CATEGORY; |
|
326 | + $lastGood->formula = null; |
|
327 | + } |
|
328 | + $this->categories = $goodCategories; |
|
329 | + } |
|
330 | 330 | |
331 | - /** |
|
332 | - * Reverse a formula. |
|
333 | - * |
|
334 | - * @param string $formula |
|
335 | - * |
|
336 | - * @throws \Exception |
|
337 | - * |
|
338 | - * @return string |
|
339 | - */ |
|
340 | - private static function reverseFormula($formula) |
|
341 | - { |
|
342 | - if (preg_match('/^n( % \d+)? == \d+(\.\.\d+|,\d+)*?$/', $formula)) { |
|
343 | - return str_replace(' == ', ' != ', $formula); |
|
344 | - } |
|
345 | - if (preg_match('/^n( % \d+)? != \d+(\.\.\d+|,\d+)*?$/', $formula)) { |
|
346 | - return str_replace(' != ', ' == ', $formula); |
|
347 | - } |
|
348 | - if (preg_match('/^\(?n == \d+ \|\| n == \d+\)?$/', $formula)) { |
|
349 | - return trim(str_replace(array(' == ', ' || '), array(' != ', ' && '), $formula), '()'); |
|
350 | - } |
|
351 | - $m = null; |
|
352 | - if (preg_match('/^(n(?: % \d+)?) == (\d+) && (n(?: % \d+)?) != (\d+)$/', $formula, $m)) { |
|
353 | - return "{$m[1]} != {$m[2]} || {$m[3]} == {$m[4]}"; |
|
354 | - } |
|
355 | - switch ($formula) { |
|
356 | - case '(n == 1 || n == 2 || n == 3) || n % 10 != 4 && n % 10 != 6 && n % 10 != 9': |
|
357 | - return 'n != 1 && n != 2 && n != 3 && (n % 10 == 4 || n % 10 == 6 || n % 10 == 9)'; |
|
358 | - case '(n == 0 || n == 1) || n >= 11 && n <= 99': |
|
359 | - return 'n >= 2 && (n < 11 || n > 99)'; |
|
360 | - } |
|
361 | - throw new Exception("Unable to reverse the formula '{$formula}'"); |
|
362 | - } |
|
331 | + /** |
|
332 | + * Reverse a formula. |
|
333 | + * |
|
334 | + * @param string $formula |
|
335 | + * |
|
336 | + * @throws \Exception |
|
337 | + * |
|
338 | + * @return string |
|
339 | + */ |
|
340 | + private static function reverseFormula($formula) |
|
341 | + { |
|
342 | + if (preg_match('/^n( % \d+)? == \d+(\.\.\d+|,\d+)*?$/', $formula)) { |
|
343 | + return str_replace(' == ', ' != ', $formula); |
|
344 | + } |
|
345 | + if (preg_match('/^n( % \d+)? != \d+(\.\.\d+|,\d+)*?$/', $formula)) { |
|
346 | + return str_replace(' != ', ' == ', $formula); |
|
347 | + } |
|
348 | + if (preg_match('/^\(?n == \d+ \|\| n == \d+\)?$/', $formula)) { |
|
349 | + return trim(str_replace(array(' == ', ' || '), array(' != ', ' && '), $formula), '()'); |
|
350 | + } |
|
351 | + $m = null; |
|
352 | + if (preg_match('/^(n(?: % \d+)?) == (\d+) && (n(?: % \d+)?) != (\d+)$/', $formula, $m)) { |
|
353 | + return "{$m[1]} != {$m[2]} || {$m[3]} == {$m[4]}"; |
|
354 | + } |
|
355 | + switch ($formula) { |
|
356 | + case '(n == 1 || n == 2 || n == 3) || n % 10 != 4 && n % 10 != 6 && n % 10 != 9': |
|
357 | + return 'n != 1 && n != 2 && n != 3 && (n % 10 == 4 || n % 10 == 6 || n % 10 == 9)'; |
|
358 | + case '(n == 0 || n == 1) || n >= 11 && n <= 99': |
|
359 | + return 'n >= 2 && (n < 11 || n > 99)'; |
|
360 | + } |
|
361 | + throw new Exception("Unable to reverse the formula '{$formula}'"); |
|
362 | + } |
|
363 | 363 | |
364 | - /** |
|
365 | - * Reduce some excessively complex formulas. |
|
366 | - * |
|
367 | - * @param string $formula |
|
368 | - * |
|
369 | - * @return string |
|
370 | - */ |
|
371 | - private static function reduceFormula($formula) |
|
372 | - { |
|
373 | - $map = array( |
|
374 | - 'n != 0 && n != 1' => 'n > 1', |
|
375 | - '(n == 0 || n == 1) && n != 0' => 'n == 1', |
|
376 | - ); |
|
364 | + /** |
|
365 | + * Reduce some excessively complex formulas. |
|
366 | + * |
|
367 | + * @param string $formula |
|
368 | + * |
|
369 | + * @return string |
|
370 | + */ |
|
371 | + private static function reduceFormula($formula) |
|
372 | + { |
|
373 | + $map = array( |
|
374 | + 'n != 0 && n != 1' => 'n > 1', |
|
375 | + '(n == 0 || n == 1) && n != 0' => 'n == 1', |
|
376 | + ); |
|
377 | 377 | |
378 | - return isset($map[$formula]) ? $map[$formula] : $formula; |
|
379 | - } |
|
378 | + return isset($map[$formula]) ? $map[$formula] : $formula; |
|
379 | + } |
|
380 | 380 | |
381 | - /** |
|
382 | - * Take one variable and, if it's a string, we transliterate it to US-ASCII. |
|
383 | - * |
|
384 | - * @param mixed $value the variable to work on |
|
385 | - * |
|
386 | - * @throws \Exception |
|
387 | - */ |
|
388 | - private static function asciifier(&$value) |
|
389 | - { |
|
390 | - if (is_string($value) && $value !== '') { |
|
391 | - // Avoid converting from 'Ÿ' to '"Y', let's prefer 'Y' |
|
392 | - $value = strtr($value, array( |
|
393 | - 'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', |
|
394 | - 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', |
|
395 | - 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', |
|
396 | - 'Ñ' => 'N', |
|
397 | - 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', |
|
398 | - 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', |
|
399 | - 'Ÿ' => 'Y', 'Ý' => 'Y', |
|
400 | - 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', |
|
401 | - 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', |
|
402 | - 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', |
|
403 | - 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', |
|
404 | - 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u', |
|
405 | - 'ý' => 'y', 'ÿ' => 'y', |
|
406 | - '…' => '...', |
|
407 | - 'ʼ' => "'", '’' => "'", |
|
408 | - )); |
|
409 | - } |
|
410 | - } |
|
381 | + /** |
|
382 | + * Take one variable and, if it's a string, we transliterate it to US-ASCII. |
|
383 | + * |
|
384 | + * @param mixed $value the variable to work on |
|
385 | + * |
|
386 | + * @throws \Exception |
|
387 | + */ |
|
388 | + private static function asciifier(&$value) |
|
389 | + { |
|
390 | + if (is_string($value) && $value !== '') { |
|
391 | + // Avoid converting from 'Ÿ' to '"Y', let's prefer 'Y' |
|
392 | + $value = strtr($value, array( |
|
393 | + 'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', |
|
394 | + 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', |
|
395 | + 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', |
|
396 | + 'Ñ' => 'N', |
|
397 | + 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', |
|
398 | + 'Ù' => 'U', 'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', |
|
399 | + 'Ÿ' => 'Y', 'Ý' => 'Y', |
|
400 | + 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', |
|
401 | + 'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', |
|
402 | + 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', |
|
403 | + 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o', 'ö' => 'o', |
|
404 | + 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ü' => 'u', |
|
405 | + 'ý' => 'y', 'ÿ' => 'y', |
|
406 | + '…' => '...', |
|
407 | + 'ʼ' => "'", '’' => "'", |
|
408 | + )); |
|
409 | + } |
|
410 | + } |
|
411 | 411 | } |
@@ -72,35 +72,35 @@ discard block |
||
72 | 72 | * |
73 | 73 | * @throws \Exception throws an Exception if $fullId is not valid |
74 | 74 | */ |
75 | - private function __construct($info) |
|
75 | + private function __construct( $info ) |
|
76 | 76 | { |
77 | - $this->id = $info['id']; |
|
78 | - $this->name = $info['name']; |
|
79 | - $this->supersededBy = isset($info['supersededBy']) ? $info['supersededBy'] : null; |
|
80 | - $this->script = isset($info['script']) ? $info['script'] : null; |
|
81 | - $this->territory = isset($info['territory']) ? $info['territory'] : null; |
|
82 | - $this->baseLanguage = isset($info['baseLanguage']) ? $info['baseLanguage'] : null; |
|
77 | + $this->id = $info[ 'id' ]; |
|
78 | + $this->name = $info[ 'name' ]; |
|
79 | + $this->supersededBy = isset( $info[ 'supersededBy' ] ) ? $info[ 'supersededBy' ] : null; |
|
80 | + $this->script = isset( $info[ 'script' ] ) ? $info[ 'script' ] : null; |
|
81 | + $this->territory = isset( $info[ 'territory' ] ) ? $info[ 'territory' ] : null; |
|
82 | + $this->baseLanguage = isset( $info[ 'baseLanguage' ] ) ? $info[ 'baseLanguage' ] : null; |
|
83 | 83 | // Let's build the category list |
84 | 84 | $this->categories = array(); |
85 | - foreach ($info['categories'] as $cldrCategoryId => $cldrFormulaAndExamples) { |
|
86 | - $category = new Category($cldrCategoryId, $cldrFormulaAndExamples); |
|
87 | - foreach ($this->categories as $c) { |
|
88 | - if ($category->id === $c->id) { |
|
89 | - throw new Exception("The category '{$category->id}' is specified more than once"); |
|
85 | + foreach ( $info[ 'categories' ] as $cldrCategoryId => $cldrFormulaAndExamples ) { |
|
86 | + $category = new Category( $cldrCategoryId, $cldrFormulaAndExamples ); |
|
87 | + foreach ( $this->categories as $c ) { |
|
88 | + if ( $category->id === $c->id ) { |
|
89 | + throw new Exception( "The category '{$category->id}' is specified more than once" ); |
|
90 | 90 | } |
91 | 91 | } |
92 | - $this->categories[] = $category; |
|
92 | + $this->categories[ ] = $category; |
|
93 | 93 | } |
94 | - if (empty($this->categories)) { |
|
95 | - throw new Exception("The language '{$info['id']}' does not have any plural category"); |
|
94 | + if ( empty( $this->categories ) ) { |
|
95 | + throw new Exception( "The language '{$info[ 'id' ]}' does not have any plural category" ); |
|
96 | 96 | } |
97 | 97 | // Let's sort the categories from 'zero' to 'other' |
98 | - usort($this->categories, function (Category $category1, Category $category2) { |
|
99 | - return array_search($category1->id, CldrData::$categories) - array_search($category2->id, CldrData::$categories); |
|
98 | + usort( $this->categories, function( Category $category1, Category $category2 ) { |
|
99 | + return array_search( $category1->id, CldrData::$categories ) - array_search( $category2->id, CldrData::$categories ); |
|
100 | 100 | }); |
101 | 101 | // The 'other' category should always be there |
102 | - if ($this->categories[count($this->categories) - 1]->id !== CldrData::OTHER_CATEGORY) { |
|
103 | - throw new Exception("The language '{$info['id']}' does not have the '" . CldrData::OTHER_CATEGORY . "' plural category"); |
|
102 | + if ( $this->categories[ count( $this->categories ) - 1 ]->id !== CldrData::OTHER_CATEGORY ) { |
|
103 | + throw new Exception( "The language '{$info[ 'id' ]}' does not have the '" . CldrData::OTHER_CATEGORY . "' plural category" ); |
|
104 | 104 | } |
105 | 105 | $this->checkAlwaysTrueCategories(); |
106 | 106 | $this->checkAlwaysFalseCategories(); |
@@ -118,8 +118,8 @@ discard block |
||
118 | 118 | public static function getAll() |
119 | 119 | { |
120 | 120 | $result = array(); |
121 | - foreach (array_keys(CldrData::getLanguageNames()) as $cldrLanguageId) { |
|
122 | - $result[] = new self(CldrData::getLanguageInfo($cldrLanguageId)); |
|
121 | + foreach ( array_keys( CldrData::getLanguageNames() ) as $cldrLanguageId ) { |
|
122 | + $result[ ] = new self( CldrData::getLanguageInfo( $cldrLanguageId ) ); |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | return $result; |
@@ -132,12 +132,12 @@ discard block |
||
132 | 132 | * |
133 | 133 | * @return \Gettext\Languages\Language|null |
134 | 134 | */ |
135 | - public static function getById($id) |
|
135 | + public static function getById( $id ) |
|
136 | 136 | { |
137 | 137 | $result = null; |
138 | - $info = CldrData::getLanguageInfo($id); |
|
139 | - if (isset($info)) { |
|
140 | - $result = new self($info); |
|
138 | + $info = CldrData::getLanguageInfo( $id ); |
|
139 | + if ( isset( $info ) ) { |
|
140 | + $result = new self( $info ); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | return $result; |
@@ -151,13 +151,13 @@ discard block |
||
151 | 151 | public function getUSAsciiClone() |
152 | 152 | { |
153 | 153 | $clone = clone $this; |
154 | - self::asciifier($clone->name); |
|
155 | - self::asciifier($clone->formula); |
|
154 | + self::asciifier( $clone->name ); |
|
155 | + self::asciifier( $clone->formula ); |
|
156 | 156 | $clone->categories = array(); |
157 | - foreach ($this->categories as $category) { |
|
157 | + foreach ( $this->categories as $category ) { |
|
158 | 158 | $categoryClone = clone $category; |
159 | - self::asciifier($categoryClone->examples); |
|
160 | - $clone->categories[] = $categoryClone; |
|
159 | + self::asciifier( $categoryClone->examples ); |
|
160 | + $clone->categories[ ] = $categoryClone; |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | return $clone; |
@@ -170,24 +170,24 @@ discard block |
||
170 | 170 | * |
171 | 171 | * @return string |
172 | 172 | */ |
173 | - public function buildFormula($withoutParenthesis = false) |
|
173 | + public function buildFormula( $withoutParenthesis = false ) |
|
174 | 174 | { |
175 | - $numCategories = count($this->categories); |
|
176 | - switch ($numCategories) { |
|
175 | + $numCategories = count( $this->categories ); |
|
176 | + switch ( $numCategories ) { |
|
177 | 177 | case 1: |
178 | 178 | // Just one category |
179 | 179 | return '0'; |
180 | 180 | case 2: |
181 | - return self::reduceFormula(self::reverseFormula($this->categories[0]->formula)); |
|
181 | + return self::reduceFormula( self::reverseFormula( $this->categories[ 0 ]->formula ) ); |
|
182 | 182 | default: |
183 | - $formula = (string) ($numCategories - 1); |
|
184 | - for ($i = $numCategories - 2; $i >= 0; $i--) { |
|
185 | - $f = self::reduceFormula($this->categories[$i]->formula); |
|
186 | - if (!$withoutParenthesis && !preg_match('/^\([^()]+\)$/', $f)) { |
|
183 | + $formula = (string)( $numCategories - 1 ); |
|
184 | + for ( $i = $numCategories - 2; $i >= 0; $i-- ) { |
|
185 | + $f = self::reduceFormula( $this->categories[ $i ]->formula ); |
|
186 | + if ( ! $withoutParenthesis && ! preg_match( '/^\([^()]+\)$/', $f ) ) { |
|
187 | 187 | $f = "({$f})"; |
188 | 188 | } |
189 | 189 | $formula = "{$f} ? {$i} : {$formula}"; |
190 | - if (!$withoutParenthesis && $i > 0) { |
|
190 | + if ( ! $withoutParenthesis && $i > 0 ) { |
|
191 | 191 | $formula = "({$formula})"; |
192 | 192 | } |
193 | 193 | } |
@@ -206,24 +206,24 @@ discard block |
||
206 | 206 | private function checkAlwaysTrueCategories() |
207 | 207 | { |
208 | 208 | $alwaysTrueCategory = null; |
209 | - foreach ($this->categories as $category) { |
|
210 | - if ($category->formula === true) { |
|
211 | - if (!isset($category->examples)) { |
|
212 | - throw new Exception("The category '{$category->id}' should always occur, but it does not have examples (so for CLDR it will never occur for integers!)"); |
|
209 | + foreach ( $this->categories as $category ) { |
|
210 | + if ( $category->formula === true ) { |
|
211 | + if ( ! isset( $category->examples ) ) { |
|
212 | + throw new Exception( "The category '{$category->id}' should always occur, but it does not have examples (so for CLDR it will never occur for integers!)" ); |
|
213 | 213 | } |
214 | 214 | $alwaysTrueCategory = $category; |
215 | 215 | break; |
216 | 216 | } |
217 | 217 | } |
218 | - if (isset($alwaysTrueCategory)) { |
|
219 | - foreach ($this->categories as $category) { |
|
220 | - if (($category !== $alwaysTrueCategory) && isset($category->examples)) { |
|
221 | - throw new Exception("The category '{$category->id}' should never occur, but it has some examples (so for CLDR it will occur!)"); |
|
218 | + if ( isset( $alwaysTrueCategory ) ) { |
|
219 | + foreach ( $this->categories as $category ) { |
|
220 | + if ( ( $category !== $alwaysTrueCategory ) && isset( $category->examples ) ) { |
|
221 | + throw new Exception( "The category '{$category->id}' should never occur, but it has some examples (so for CLDR it will occur!)" ); |
|
222 | 222 | } |
223 | 223 | } |
224 | 224 | $alwaysTrueCategory->id = CldrData::OTHER_CATEGORY; |
225 | 225 | $alwaysTrueCategory->formula = null; |
226 | - $this->categories = array($alwaysTrueCategory); |
|
226 | + $this->categories = array( $alwaysTrueCategory ); |
|
227 | 227 | } |
228 | 228 | } |
229 | 229 | |
@@ -237,13 +237,13 @@ discard block |
||
237 | 237 | private function checkAlwaysFalseCategories() |
238 | 238 | { |
239 | 239 | $filtered = array(); |
240 | - foreach ($this->categories as $category) { |
|
241 | - if ($category->formula === false) { |
|
242 | - if (isset($category->examples)) { |
|
243 | - throw new Exception("The category '{$category->id}' should never occur, but it has examples (so for CLDR it may occur!)"); |
|
240 | + foreach ( $this->categories as $category ) { |
|
241 | + if ( $category->formula === false ) { |
|
242 | + if ( isset( $category->examples ) ) { |
|
243 | + throw new Exception( "The category '{$category->id}' should never occur, but it has examples (so for CLDR it may occur!)" ); |
|
244 | 244 | } |
245 | 245 | } else { |
246 | - $filtered[] = $category; |
|
246 | + $filtered[ ] = $category; |
|
247 | 247 | } |
248 | 248 | } |
249 | 249 | $this->categories = $filtered; |
@@ -262,22 +262,22 @@ discard block |
||
262 | 262 | $goodCategories = array(); |
263 | 263 | $badCategories = array(); |
264 | 264 | $badCategoriesIds = array(); |
265 | - foreach ($this->categories as $category) { |
|
266 | - $allCategoriesIds[] = $category->id; |
|
267 | - if (isset($category->examples)) { |
|
268 | - $goodCategories[] = $category; |
|
265 | + foreach ( $this->categories as $category ) { |
|
266 | + $allCategoriesIds[ ] = $category->id; |
|
267 | + if ( isset( $category->examples ) ) { |
|
268 | + $goodCategories[ ] = $category; |
|
269 | 269 | } else { |
270 | - $badCategories[] = $category; |
|
271 | - $badCategoriesIds[] = $category->id; |
|
270 | + $badCategories[ ] = $category; |
|
271 | + $badCategoriesIds[ ] = $category->id; |
|
272 | 272 | } |
273 | 273 | } |
274 | - if (empty($badCategories)) { |
|
274 | + if ( empty( $badCategories ) ) { |
|
275 | 275 | return; |
276 | 276 | } |
277 | 277 | $removeCategoriesWithoutExamples = false; |
278 | - switch (implode(',', $badCategoriesIds) . '@' . implode(',', $allCategoriesIds)) { |
|
278 | + switch ( implode( ',', $badCategoriesIds ) . '@' . implode( ',', $allCategoriesIds ) ) { |
|
279 | 279 | case CldrData::OTHER_CATEGORY . '@one,few,many,' . CldrData::OTHER_CATEGORY: |
280 | - switch ($this->buildFormula()) { |
|
280 | + switch ( $this->buildFormula() ) { |
|
281 | 281 | case '(n % 10 == 1 && n % 100 != 11) ? 0 : ((n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 12 || n % 100 > 14)) ? 1 : ((n % 10 == 0 || n % 10 >= 5 && n % 10 <= 9 || n % 100 >= 11 && n % 100 <= 14) ? 2 : 3))': |
282 | 282 | // Numbers ending with 0 => case 2 ('many') |
283 | 283 | // Numbers ending with 1 but not with 11 => case 0 ('one') |
@@ -316,12 +316,12 @@ discard block |
||
316 | 316 | break; |
317 | 317 | } |
318 | 318 | } |
319 | - if (!$removeCategoriesWithoutExamples) { |
|
320 | - throw new Exception("Unhandled case of plural categories without examples '" . implode(', ', $badCategoriesIds) . "' out of '" . implode(', ', $allCategoriesIds) . "'"); |
|
319 | + if ( ! $removeCategoriesWithoutExamples ) { |
|
320 | + throw new Exception( "Unhandled case of plural categories without examples '" . implode( ', ', $badCategoriesIds ) . "' out of '" . implode( ', ', $allCategoriesIds ) . "'" ); |
|
321 | 321 | } |
322 | - if ($badCategories[count($badCategories) - 1]->id === CldrData::OTHER_CATEGORY) { |
|
322 | + if ( $badCategories[ count( $badCategories ) - 1 ]->id === CldrData::OTHER_CATEGORY ) { |
|
323 | 323 | // We're removing the 'other' cagory: let's change the last good category to 'other' |
324 | - $lastGood = $goodCategories[count($goodCategories) - 1]; |
|
324 | + $lastGood = $goodCategories[ count( $goodCategories ) - 1 ]; |
|
325 | 325 | $lastGood->id = CldrData::OTHER_CATEGORY; |
326 | 326 | $lastGood->formula = null; |
327 | 327 | } |
@@ -337,28 +337,28 @@ discard block |
||
337 | 337 | * |
338 | 338 | * @return string |
339 | 339 | */ |
340 | - private static function reverseFormula($formula) |
|
340 | + private static function reverseFormula( $formula ) |
|
341 | 341 | { |
342 | - if (preg_match('/^n( % \d+)? == \d+(\.\.\d+|,\d+)*?$/', $formula)) { |
|
343 | - return str_replace(' == ', ' != ', $formula); |
|
342 | + if ( preg_match( '/^n( % \d+)? == \d+(\.\.\d+|,\d+)*?$/', $formula ) ) { |
|
343 | + return str_replace( ' == ', ' != ', $formula ); |
|
344 | 344 | } |
345 | - if (preg_match('/^n( % \d+)? != \d+(\.\.\d+|,\d+)*?$/', $formula)) { |
|
346 | - return str_replace(' != ', ' == ', $formula); |
|
345 | + if ( preg_match( '/^n( % \d+)? != \d+(\.\.\d+|,\d+)*?$/', $formula ) ) { |
|
346 | + return str_replace( ' != ', ' == ', $formula ); |
|
347 | 347 | } |
348 | - if (preg_match('/^\(?n == \d+ \|\| n == \d+\)?$/', $formula)) { |
|
349 | - return trim(str_replace(array(' == ', ' || '), array(' != ', ' && '), $formula), '()'); |
|
348 | + if ( preg_match( '/^\(?n == \d+ \|\| n == \d+\)?$/', $formula ) ) { |
|
349 | + return trim( str_replace( array( ' == ', ' || ' ), array( ' != ', ' && ' ), $formula ), '()' ); |
|
350 | 350 | } |
351 | 351 | $m = null; |
352 | - if (preg_match('/^(n(?: % \d+)?) == (\d+) && (n(?: % \d+)?) != (\d+)$/', $formula, $m)) { |
|
353 | - return "{$m[1]} != {$m[2]} || {$m[3]} == {$m[4]}"; |
|
352 | + if ( preg_match( '/^(n(?: % \d+)?) == (\d+) && (n(?: % \d+)?) != (\d+)$/', $formula, $m ) ) { |
|
353 | + return "{$m[ 1 ]} != {$m[ 2 ]} || {$m[ 3 ]} == {$m[ 4 ]}"; |
|
354 | 354 | } |
355 | - switch ($formula) { |
|
355 | + switch ( $formula ) { |
|
356 | 356 | case '(n == 1 || n == 2 || n == 3) || n % 10 != 4 && n % 10 != 6 && n % 10 != 9': |
357 | 357 | return 'n != 1 && n != 2 && n != 3 && (n % 10 == 4 || n % 10 == 6 || n % 10 == 9)'; |
358 | 358 | case '(n == 0 || n == 1) || n >= 11 && n <= 99': |
359 | 359 | return 'n >= 2 && (n < 11 || n > 99)'; |
360 | 360 | } |
361 | - throw new Exception("Unable to reverse the formula '{$formula}'"); |
|
361 | + throw new Exception( "Unable to reverse the formula '{$formula}'" ); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | /** |
@@ -368,14 +368,14 @@ discard block |
||
368 | 368 | * |
369 | 369 | * @return string |
370 | 370 | */ |
371 | - private static function reduceFormula($formula) |
|
371 | + private static function reduceFormula( $formula ) |
|
372 | 372 | { |
373 | 373 | $map = array( |
374 | 374 | 'n != 0 && n != 1' => 'n > 1', |
375 | 375 | '(n == 0 || n == 1) && n != 0' => 'n == 1', |
376 | 376 | ); |
377 | 377 | |
378 | - return isset($map[$formula]) ? $map[$formula] : $formula; |
|
378 | + return isset( $map[ $formula ] ) ? $map[ $formula ] : $formula; |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | /** |
@@ -385,11 +385,11 @@ discard block |
||
385 | 385 | * |
386 | 386 | * @throws \Exception |
387 | 387 | */ |
388 | - private static function asciifier(&$value) |
|
388 | + private static function asciifier( &$value ) |
|
389 | 389 | { |
390 | - if (is_string($value) && $value !== '') { |
|
390 | + if ( is_string( $value ) && $value !== '' ) { |
|
391 | 391 | // Avoid converting from 'Ÿ' to '"Y', let's prefer 'Y' |
392 | - $value = strtr($value, array( |
|
392 | + $value = strtr( $value, array( |
|
393 | 393 | 'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', |
394 | 394 | 'È' => 'E', 'É' => 'E', 'Ê' => 'E', 'Ë' => 'E', |
395 | 395 | 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | 'ý' => 'y', 'ÿ' => 'y', |
406 | 406 | '…' => '...', |
407 | 407 | 'ʼ' => "'", '’' => "'", |
408 | - )); |
|
408 | + ) ); |
|
409 | 409 | } |
410 | 410 | } |
411 | 411 | } |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Main class to convert the plural rules of a language from CLDR to gettext. |
9 | 9 | */ |
10 | -class Language |
|
11 | -{ |
|
10 | +class Language { |
|
12 | 11 | /** |
13 | 12 | * The language ID. |
14 | 13 | * |
@@ -72,8 +71,7 @@ discard block |
||
72 | 71 | * |
73 | 72 | * @throws \Exception throws an Exception if $fullId is not valid |
74 | 73 | */ |
75 | - private function __construct($info) |
|
76 | - { |
|
74 | + private function __construct($info) { |
|
77 | 75 | $this->id = $info['id']; |
78 | 76 | $this->name = $info['name']; |
79 | 77 | $this->supersededBy = isset($info['supersededBy']) ? $info['supersededBy'] : null; |
@@ -115,8 +113,7 @@ discard block |
||
115 | 113 | * |
116 | 114 | * @return \Gettext\Languages\Language[] |
117 | 115 | */ |
118 | - public static function getAll() |
|
119 | - { |
|
116 | + public static function getAll() { |
|
120 | 117 | $result = array(); |
121 | 118 | foreach (array_keys(CldrData::getLanguageNames()) as $cldrLanguageId) { |
122 | 119 | $result[] = new self(CldrData::getLanguageInfo($cldrLanguageId)); |
@@ -132,8 +129,7 @@ discard block |
||
132 | 129 | * |
133 | 130 | * @return \Gettext\Languages\Language|null |
134 | 131 | */ |
135 | - public static function getById($id) |
|
136 | - { |
|
132 | + public static function getById($id) { |
|
137 | 133 | $result = null; |
138 | 134 | $info = CldrData::getLanguageInfo($id); |
139 | 135 | if (isset($info)) { |
@@ -148,8 +144,7 @@ discard block |
||
148 | 144 | * |
149 | 145 | * @return \Gettext\Languages\Language |
150 | 146 | */ |
151 | - public function getUSAsciiClone() |
|
152 | - { |
|
147 | + public function getUSAsciiClone() { |
|
153 | 148 | $clone = clone $this; |
154 | 149 | self::asciifier($clone->name); |
155 | 150 | self::asciifier($clone->formula); |
@@ -170,8 +165,7 @@ discard block |
||
170 | 165 | * |
171 | 166 | * @return string |
172 | 167 | */ |
173 | - public function buildFormula($withoutParenthesis = false) |
|
174 | - { |
|
168 | + public function buildFormula($withoutParenthesis = false) { |
|
175 | 169 | $numCategories = count($this->categories); |
176 | 170 | switch ($numCategories) { |
177 | 171 | case 1: |
@@ -203,8 +197,7 @@ discard block |
||
203 | 197 | * |
204 | 198 | * @throws \Exception |
205 | 199 | */ |
206 | - private function checkAlwaysTrueCategories() |
|
207 | - { |
|
200 | + private function checkAlwaysTrueCategories() { |
|
208 | 201 | $alwaysTrueCategory = null; |
209 | 202 | foreach ($this->categories as $category) { |
210 | 203 | if ($category->formula === true) { |
@@ -234,8 +227,7 @@ discard block |
||
234 | 227 | * |
235 | 228 | * @throws \Exception |
236 | 229 | */ |
237 | - private function checkAlwaysFalseCategories() |
|
238 | - { |
|
230 | + private function checkAlwaysFalseCategories() { |
|
239 | 231 | $filtered = array(); |
240 | 232 | foreach ($this->categories as $category) { |
241 | 233 | if ($category->formula === false) { |
@@ -256,8 +248,7 @@ discard block |
||
256 | 248 | * |
257 | 249 | * @throws \Exception |
258 | 250 | */ |
259 | - private function checkAllCategoriesWithExamples() |
|
260 | - { |
|
251 | + private function checkAllCategoriesWithExamples() { |
|
261 | 252 | $allCategoriesIds = array(); |
262 | 253 | $goodCategories = array(); |
263 | 254 | $badCategories = array(); |
@@ -337,8 +328,7 @@ discard block |
||
337 | 328 | * |
338 | 329 | * @return string |
339 | 330 | */ |
340 | - private static function reverseFormula($formula) |
|
341 | - { |
|
331 | + private static function reverseFormula($formula) { |
|
342 | 332 | if (preg_match('/^n( % \d+)? == \d+(\.\.\d+|,\d+)*?$/', $formula)) { |
343 | 333 | return str_replace(' == ', ' != ', $formula); |
344 | 334 | } |
@@ -368,8 +358,7 @@ discard block |
||
368 | 358 | * |
369 | 359 | * @return string |
370 | 360 | */ |
371 | - private static function reduceFormula($formula) |
|
372 | - { |
|
361 | + private static function reduceFormula($formula) { |
|
373 | 362 | $map = array( |
374 | 363 | 'n != 0 && n != 1' => 'n > 1', |
375 | 364 | '(n == 0 || n == 1) && n != 0' => 'n == 1', |
@@ -385,8 +374,7 @@ discard block |
||
385 | 374 | * |
386 | 375 | * @throws \Exception |
387 | 376 | */ |
388 | - private static function asciifier(&$value) |
|
389 | - { |
|
377 | + private static function asciifier(&$value) { |
|
390 | 378 | if (is_string($value) && $value !== '') { |
391 | 379 | // Avoid converting from 'Ÿ' to '"Y', let's prefer 'Y' |
392 | 380 | $value = strtr($value, array( |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @var string[] |
23 | 23 | */ |
24 | - public static $categories = array('zero', 'one', 'two', 'few', 'many', self::OTHER_CATEGORY); |
|
24 | + public static $categories = array( 'zero', 'one', 'two', 'few', 'many', self::OTHER_CATEGORY ); |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * The loaded CLDR data. |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | */ |
45 | 45 | public static function getLanguageNames() |
46 | 46 | { |
47 | - return self::getData('languages'); |
|
47 | + return self::getData( 'languages' ); |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public static function getTerritoryNames() |
58 | 58 | { |
59 | - return self::getData('territories'); |
|
59 | + return self::getData( 'territories' ); |
|
60 | 60 | } |
61 | 61 | |
62 | 62 | /** |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | * |
69 | 69 | * @return string[] |
70 | 70 | */ |
71 | - public static function getScriptNames($standAlone) |
|
71 | + public static function getScriptNames( $standAlone ) |
|
72 | 72 | { |
73 | - return self::getData($standAlone ? 'standAloneScripts' : 'scripts'); |
|
73 | + return self::getData( $standAlone ? 'standAloneScripts' : 'scripts' ); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | */ |
91 | 91 | public static function getPlurals() |
92 | 92 | { |
93 | - return self::getData('plurals'); |
|
93 | + return self::getData( 'plurals' ); |
|
94 | 94 | } |
95 | 95 | |
96 | 96 | /** |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public static function getSupersededLanguages() |
102 | 102 | { |
103 | - return self::getData('supersededLanguages'); |
|
103 | + return self::getData( 'supersededLanguages' ); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -110,54 +110,54 @@ discard block |
||
110 | 110 | * |
111 | 111 | * @return array|null Returns an array with the keys 'id' (normalized), 'name', 'supersededBy' (optional), 'territory' (optional), 'script' (optional), 'baseLanguage' (optional), 'categories'. If $id is not valid returns null. |
112 | 112 | */ |
113 | - public static function getLanguageInfo($id) |
|
113 | + public static function getLanguageInfo( $id ) |
|
114 | 114 | { |
115 | 115 | $result = null; |
116 | 116 | $matches = array(); |
117 | - if (preg_match('/^([a-z]{2,3})(?:[_\-]([a-z]{4}))?(?:[_\-]([a-z]{2}|[0-9]{3}))?(?:$|-)/i', $id, $matches)) { |
|
118 | - $languageId = strtolower($matches[1]); |
|
119 | - $scriptId = (isset($matches[2]) && ($matches[2] !== '')) ? ucfirst(strtolower($matches[2])) : null; |
|
120 | - $territoryId = (isset($matches[3]) && ($matches[3] !== '')) ? strtoupper($matches[3]) : null; |
|
117 | + if ( preg_match( '/^([a-z]{2,3})(?:[_\-]([a-z]{4}))?(?:[_\-]([a-z]{2}|[0-9]{3}))?(?:$|-)/i', $id, $matches ) ) { |
|
118 | + $languageId = strtolower( $matches[ 1 ] ); |
|
119 | + $scriptId = ( isset( $matches[ 2 ] ) && ( $matches[ 2 ] !== '' ) ) ? ucfirst( strtolower( $matches[ 2 ] ) ) : null; |
|
120 | + $territoryId = ( isset( $matches[ 3 ] ) && ( $matches[ 3 ] !== '' ) ) ? strtoupper( $matches[ 3 ] ) : null; |
|
121 | 121 | $normalizedId = $languageId; |
122 | - if (isset($scriptId)) { |
|
122 | + if ( isset( $scriptId ) ) { |
|
123 | 123 | $normalizedId .= '_' . $scriptId; |
124 | 124 | } |
125 | - if (isset($territoryId)) { |
|
125 | + if ( isset( $territoryId ) ) { |
|
126 | 126 | $normalizedId .= '_' . $territoryId; |
127 | 127 | } |
128 | 128 | // Structure precedence: see Likely Subtags - http://www.unicode.org/reports/tr35/tr35-31/tr35.html#Likely_Subtags |
129 | 129 | $variants = array(); |
130 | 130 | $variantsWithScript = array(); |
131 | 131 | $variantsWithTerritory = array(); |
132 | - if (isset($scriptId) && isset($territoryId)) { |
|
133 | - $variantsWithTerritory[] = $variantsWithScript[] = $variants[] = "{$languageId}_{$scriptId}_{$territoryId}"; |
|
132 | + if ( isset( $scriptId ) && isset( $territoryId ) ) { |
|
133 | + $variantsWithTerritory[ ] = $variantsWithScript[ ] = $variants[ ] = "{$languageId}_{$scriptId}_{$territoryId}"; |
|
134 | 134 | } |
135 | - if (isset($scriptId)) { |
|
136 | - $variantsWithScript[] = $variants[] = "{$languageId}_{$scriptId}"; |
|
135 | + if ( isset( $scriptId ) ) { |
|
136 | + $variantsWithScript[ ] = $variants[ ] = "{$languageId}_{$scriptId}"; |
|
137 | 137 | } |
138 | - if (isset($territoryId)) { |
|
139 | - $variantsWithTerritory[] = $variants[] = "{$languageId}_{$territoryId}"; |
|
138 | + if ( isset( $territoryId ) ) { |
|
139 | + $variantsWithTerritory[ ] = $variants[ ] = "{$languageId}_{$territoryId}"; |
|
140 | 140 | } |
141 | - $variants[] = $languageId; |
|
141 | + $variants[ ] = $languageId; |
|
142 | 142 | $allGood = true; |
143 | 143 | $scriptName = null; |
144 | 144 | $scriptStandAloneName = null; |
145 | - if (isset($scriptId)) { |
|
146 | - $scriptNames = self::getScriptNames(false); |
|
147 | - if (isset($scriptNames[$scriptId])) { |
|
148 | - $scriptName = $scriptNames[$scriptId]; |
|
149 | - $scriptStandAloneNames = self::getScriptNames(true); |
|
150 | - $scriptStandAloneName = $scriptStandAloneNames[$scriptId]; |
|
145 | + if ( isset( $scriptId ) ) { |
|
146 | + $scriptNames = self::getScriptNames( false ); |
|
147 | + if ( isset( $scriptNames[ $scriptId ] ) ) { |
|
148 | + $scriptName = $scriptNames[ $scriptId ]; |
|
149 | + $scriptStandAloneNames = self::getScriptNames( true ); |
|
150 | + $scriptStandAloneName = $scriptStandAloneNames[ $scriptId ]; |
|
151 | 151 | } else { |
152 | 152 | $allGood = false; |
153 | 153 | } |
154 | 154 | } |
155 | 155 | $territoryName = null; |
156 | - if (isset($territoryId)) { |
|
156 | + if ( isset( $territoryId ) ) { |
|
157 | 157 | $territoryNames = self::getTerritoryNames(); |
158 | - if (isset($territoryNames[$territoryId])) { |
|
159 | - if ($territoryId !== '001') { |
|
160 | - $territoryName = $territoryNames[$territoryId]; |
|
158 | + if ( isset( $territoryNames[ $territoryId ] ) ) { |
|
159 | + if ( $territoryId !== '001' ) { |
|
160 | + $territoryName = $territoryNames[ $territoryId ]; |
|
161 | 161 | } |
162 | 162 | } else { |
163 | 163 | $allGood = false; |
@@ -165,63 +165,63 @@ discard block |
||
165 | 165 | } |
166 | 166 | $languageName = null; |
167 | 167 | $languageNames = self::getLanguageNames(); |
168 | - foreach ($variants as $variant) { |
|
169 | - if (isset($languageNames[$variant])) { |
|
170 | - $languageName = $languageNames[$variant]; |
|
171 | - if (isset($scriptName) && (!in_array($variant, $variantsWithScript))) { |
|
168 | + foreach ( $variants as $variant ) { |
|
169 | + if ( isset( $languageNames[ $variant ] ) ) { |
|
170 | + $languageName = $languageNames[ $variant ]; |
|
171 | + if ( isset( $scriptName ) && ( ! in_array( $variant, $variantsWithScript ) ) ) { |
|
172 | 172 | $languageName = $scriptName . ' ' . $languageName; |
173 | 173 | } |
174 | - if (isset($territoryName) && (!in_array($variant, $variantsWithTerritory))) { |
|
175 | - $languageName .= ' (' . $territoryNames[$territoryId] . ')'; |
|
174 | + if ( isset( $territoryName ) && ( ! in_array( $variant, $variantsWithTerritory ) ) ) { |
|
175 | + $languageName .= ' (' . $territoryNames[ $territoryId ] . ')'; |
|
176 | 176 | } |
177 | 177 | break; |
178 | 178 | } |
179 | 179 | } |
180 | - if (!isset($languageName)) { |
|
180 | + if ( ! isset( $languageName ) ) { |
|
181 | 181 | $allGood = false; |
182 | 182 | } |
183 | 183 | $baseLanguage = null; |
184 | - if (isset($scriptId) || isset($territoryId)) { |
|
185 | - if (isset($languageNames[$languageId]) && ($languageNames[$languageId] !== $languageName)) { |
|
186 | - $baseLanguage = $languageNames[$languageId]; |
|
184 | + if ( isset( $scriptId ) || isset( $territoryId ) ) { |
|
185 | + if ( isset( $languageNames[ $languageId ] ) && ( $languageNames[ $languageId ] !== $languageName ) ) { |
|
186 | + $baseLanguage = $languageNames[ $languageId ]; |
|
187 | 187 | } |
188 | 188 | } |
189 | 189 | $plural = null; |
190 | 190 | $plurals = self::getPlurals(); |
191 | - foreach ($variants as $variant) { |
|
192 | - if (isset($plurals[$variant])) { |
|
193 | - $plural = $plurals[$variant]; |
|
191 | + foreach ( $variants as $variant ) { |
|
192 | + if ( isset( $plurals[ $variant ] ) ) { |
|
193 | + $plural = $plurals[ $variant ]; |
|
194 | 194 | break; |
195 | 195 | } |
196 | 196 | } |
197 | - if (!isset($plural)) { |
|
197 | + if ( ! isset( $plural ) ) { |
|
198 | 198 | $allGood = false; |
199 | 199 | } |
200 | 200 | $supersededBy = null; |
201 | 201 | $supersededBys = self::getSupersededLanguages(); |
202 | - foreach ($variants as $variant) { |
|
203 | - if (isset($supersededBys[$variant])) { |
|
204 | - $supersededBy = $supersededBys[$variant]; |
|
202 | + foreach ( $variants as $variant ) { |
|
203 | + if ( isset( $supersededBys[ $variant ] ) ) { |
|
204 | + $supersededBy = $supersededBys[ $variant ]; |
|
205 | 205 | break; |
206 | 206 | } |
207 | 207 | } |
208 | - if ($allGood) { |
|
208 | + if ( $allGood ) { |
|
209 | 209 | $result = array(); |
210 | - $result['id'] = $normalizedId; |
|
211 | - $result['name'] = $languageName; |
|
212 | - if (isset($supersededBy)) { |
|
213 | - $result['supersededBy'] = $supersededBy; |
|
210 | + $result[ 'id' ] = $normalizedId; |
|
211 | + $result[ 'name' ] = $languageName; |
|
212 | + if ( isset( $supersededBy ) ) { |
|
213 | + $result[ 'supersededBy' ] = $supersededBy; |
|
214 | 214 | } |
215 | - if (isset($scriptStandAloneName)) { |
|
216 | - $result['script'] = $scriptStandAloneName; |
|
215 | + if ( isset( $scriptStandAloneName ) ) { |
|
216 | + $result[ 'script' ] = $scriptStandAloneName; |
|
217 | 217 | } |
218 | - if (isset($territoryName)) { |
|
219 | - $result['territory'] = $territoryName; |
|
218 | + if ( isset( $territoryName ) ) { |
|
219 | + $result[ 'territory' ] = $territoryName; |
|
220 | 220 | } |
221 | - if (isset($baseLanguage)) { |
|
222 | - $result['baseLanguage'] = $baseLanguage; |
|
221 | + if ( isset( $baseLanguage ) ) { |
|
222 | + $result[ 'baseLanguage' ] = $baseLanguage; |
|
223 | 223 | } |
224 | - $result['categories'] = $plural; |
|
224 | + $result[ 'categories' ] = $plural; |
|
225 | 225 | } |
226 | 226 | } |
227 | 227 | |
@@ -235,21 +235,21 @@ discard block |
||
235 | 235 | * |
236 | 236 | * @return array |
237 | 237 | */ |
238 | - private static function getData($key) |
|
238 | + private static function getData( $key ) |
|
239 | 239 | { |
240 | - if (!isset(self::$data)) { |
|
241 | - $fixKeys = function ($list, &$standAlone = null) { |
|
240 | + if ( ! isset( self::$data ) ) { |
|
241 | + $fixKeys = function( $list, &$standAlone = null ) { |
|
242 | 242 | $result = array(); |
243 | 243 | $standAlone = array(); |
244 | 244 | $match = null; |
245 | - foreach ($list as $key => $value) { |
|
245 | + foreach ( $list as $key => $value ) { |
|
246 | 246 | $variant = ''; |
247 | - if (preg_match('/^(.+)-alt-(short|variant|stand-alone|long|menu)$/', $key, $match)) { |
|
248 | - $key = $match[1]; |
|
249 | - $variant = $match[2]; |
|
247 | + if ( preg_match( '/^(.+)-alt-(short|variant|stand-alone|long|menu)$/', $key, $match ) ) { |
|
248 | + $key = $match[ 1 ]; |
|
249 | + $variant = $match[ 2 ]; |
|
250 | 250 | } |
251 | - $key = str_replace('-', '_', $key); |
|
252 | - switch ($key) { |
|
251 | + $key = str_replace( '-', '_', $key ); |
|
252 | + switch ( $key ) { |
|
253 | 253 | case 'root': // Language: Root |
254 | 254 | case 'und': // Language: Unknown Language |
255 | 255 | case 'zxx': // Language: No linguistic content |
@@ -262,12 +262,12 @@ discard block |
||
262 | 262 | case 'Zzzz': // Script: Unknown Script |
263 | 263 | break; |
264 | 264 | default: |
265 | - switch ($variant) { |
|
265 | + switch ( $variant ) { |
|
266 | 266 | case 'stand-alone': |
267 | - $standAlone[$key] = $value; |
|
267 | + $standAlone[ $key ] = $value; |
|
268 | 268 | break; |
269 | 269 | case '': |
270 | - $result[$key] = $value; |
|
270 | + $result[ $key ] = $value; |
|
271 | 271 | break; |
272 | 272 | } |
273 | 273 | break; |
@@ -277,26 +277,26 @@ discard block |
||
277 | 277 | return $result; |
278 | 278 | }; |
279 | 279 | $data = array(); |
280 | - $json = json_decode(file_get_contents(__DIR__ . '/cldr-data/main/en-US/languages.json'), true); |
|
281 | - $data['languages'] = $fixKeys($json['main']['en-US']['localeDisplayNames']['languages']); |
|
282 | - $json = json_decode(file_get_contents(__DIR__ . '/cldr-data/main/en-US/territories.json'), true); |
|
283 | - $data['territories'] = $fixKeys($json['main']['en-US']['localeDisplayNames']['territories']); |
|
284 | - $json = json_decode(file_get_contents(__DIR__ . '/cldr-data/supplemental/plurals.json'), true); |
|
285 | - $data['plurals'] = $fixKeys($json['supplemental']['plurals-type-cardinal']); |
|
286 | - $json = json_decode(file_get_contents(__DIR__ . '/cldr-data/main/en-US/scripts.json'), true); |
|
287 | - $data['scripts'] = $fixKeys($json['main']['en-US']['localeDisplayNames']['scripts'], $data['standAloneScripts']); |
|
288 | - $data['standAloneScripts'] = array_merge($data['scripts'], $data['standAloneScripts']); |
|
289 | - $data['scripts'] = array_merge($data['standAloneScripts'], $data['scripts']); |
|
290 | - $data['supersededLanguages'] = array(); |
|
280 | + $json = json_decode( file_get_contents( __DIR__ . '/cldr-data/main/en-US/languages.json' ), true ); |
|
281 | + $data[ 'languages' ] = $fixKeys( $json[ 'main' ][ 'en-US' ][ 'localeDisplayNames' ][ 'languages' ] ); |
|
282 | + $json = json_decode( file_get_contents( __DIR__ . '/cldr-data/main/en-US/territories.json' ), true ); |
|
283 | + $data[ 'territories' ] = $fixKeys( $json[ 'main' ][ 'en-US' ][ 'localeDisplayNames' ][ 'territories' ] ); |
|
284 | + $json = json_decode( file_get_contents( __DIR__ . '/cldr-data/supplemental/plurals.json' ), true ); |
|
285 | + $data[ 'plurals' ] = $fixKeys( $json[ 'supplemental' ][ 'plurals-type-cardinal' ] ); |
|
286 | + $json = json_decode( file_get_contents( __DIR__ . '/cldr-data/main/en-US/scripts.json' ), true ); |
|
287 | + $data[ 'scripts' ] = $fixKeys( $json[ 'main' ][ 'en-US' ][ 'localeDisplayNames' ][ 'scripts' ], $data[ 'standAloneScripts' ] ); |
|
288 | + $data[ 'standAloneScripts' ] = array_merge( $data[ 'scripts' ], $data[ 'standAloneScripts' ] ); |
|
289 | + $data[ 'scripts' ] = array_merge( $data[ 'standAloneScripts' ], $data[ 'scripts' ] ); |
|
290 | + $data[ 'supersededLanguages' ] = array(); |
|
291 | 291 | // Remove the languages for which we don't have plurals |
292 | 292 | $m = null; |
293 | - foreach (array_keys(array_diff_key($data['languages'], $data['plurals'])) as $missingPlural) { |
|
294 | - if (preg_match('/^([a-z]{2,3})_/', $missingPlural, $m)) { |
|
295 | - if (!isset($data['plurals'][$m[1]])) { |
|
296 | - unset($data['languages'][$missingPlural]); |
|
293 | + foreach ( array_keys( array_diff_key( $data[ 'languages' ], $data[ 'plurals' ] ) ) as $missingPlural ) { |
|
294 | + if ( preg_match( '/^([a-z]{2,3})_/', $missingPlural, $m ) ) { |
|
295 | + if ( ! isset( $data[ 'plurals' ][ $m[ 1 ] ] ) ) { |
|
296 | + unset( $data[ 'languages' ][ $missingPlural ] ); |
|
297 | 297 | } |
298 | 298 | } else { |
299 | - unset($data['languages'][$missingPlural]); |
|
299 | + unset( $data[ 'languages' ][ $missingPlural ] ); |
|
300 | 300 | } |
301 | 301 | } |
302 | 302 | // Fix the languages for which we have plurals |
@@ -313,30 +313,30 @@ discard block |
||
313 | 313 | 'nah' => 'Nahuatl', |
314 | 314 | 'smi' => 'Sami', |
315 | 315 | ); |
316 | - foreach (array_keys(array_diff_key($data['plurals'], $data['languages'])) as $missingLanguage) { |
|
317 | - if (isset($formerCodes[$missingLanguage]) && isset($data['languages'][$formerCodes[$missingLanguage]])) { |
|
318 | - $data['languages'][$missingLanguage] = $data['languages'][$formerCodes[$missingLanguage]]; |
|
319 | - $data['supersededLanguages'][$missingLanguage] = $formerCodes[$missingLanguage]; |
|
316 | + foreach ( array_keys( array_diff_key( $data[ 'plurals' ], $data[ 'languages' ] ) ) as $missingLanguage ) { |
|
317 | + if ( isset( $formerCodes[ $missingLanguage ] ) && isset( $data[ 'languages' ][ $formerCodes[ $missingLanguage ] ] ) ) { |
|
318 | + $data[ 'languages' ][ $missingLanguage ] = $data[ 'languages' ][ $formerCodes[ $missingLanguage ] ]; |
|
319 | + $data[ 'supersededLanguages' ][ $missingLanguage ] = $formerCodes[ $missingLanguage ]; |
|
320 | 320 | } else { |
321 | - if (isset($knownMissingLanguages[$missingLanguage])) { |
|
322 | - $data['languages'][$missingLanguage] = $knownMissingLanguages[$missingLanguage]; |
|
321 | + if ( isset( $knownMissingLanguages[ $missingLanguage ] ) ) { |
|
322 | + $data[ 'languages' ][ $missingLanguage ] = $knownMissingLanguages[ $missingLanguage ]; |
|
323 | 323 | } else { |
324 | - throw new Exception("We have the plural rule for the language '{$missingLanguage}' but we don't have its language name"); |
|
324 | + throw new Exception( "We have the plural rule for the language '{$missingLanguage}' but we don't have its language name" ); |
|
325 | 325 | } |
326 | 326 | } |
327 | 327 | } |
328 | - ksort($data['languages'], SORT_STRING); |
|
329 | - ksort($data['territories'], SORT_STRING); |
|
330 | - ksort($data['plurals'], SORT_STRING); |
|
331 | - ksort($data['scripts'], SORT_STRING); |
|
332 | - ksort($data['standAloneScripts'], SORT_STRING); |
|
333 | - ksort($data['supersededLanguages'], SORT_STRING); |
|
328 | + ksort( $data[ 'languages' ], SORT_STRING ); |
|
329 | + ksort( $data[ 'territories' ], SORT_STRING ); |
|
330 | + ksort( $data[ 'plurals' ], SORT_STRING ); |
|
331 | + ksort( $data[ 'scripts' ], SORT_STRING ); |
|
332 | + ksort( $data[ 'standAloneScripts' ], SORT_STRING ); |
|
333 | + ksort( $data[ 'supersededLanguages' ], SORT_STRING ); |
|
334 | 334 | self::$data = $data; |
335 | 335 | } |
336 | - if (!isset(self::$data[$key])) { |
|
337 | - throw new Exception("Invalid CLDR data key: '{$key}'"); |
|
336 | + if ( ! isset( self::$data[ $key ] ) ) { |
|
337 | + throw new Exception( "Invalid CLDR data key: '{$key}'" ); |
|
338 | 338 | } |
339 | 339 | |
340 | - return self::$data[$key]; |
|
340 | + return self::$data[ $key ]; |
|
341 | 341 | } |
342 | 342 | } |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Holds the CLDR data. |
9 | 9 | */ |
10 | -class CldrData |
|
11 | -{ |
|
10 | +class CldrData { |
|
12 | 11 | /** |
13 | 12 | * Super-special plural category: this should always be present for any language. |
14 | 13 | * |
@@ -42,8 +41,7 @@ discard block |
||
42 | 41 | * |
43 | 42 | * @return string[] |
44 | 43 | */ |
45 | - public static function getLanguageNames() |
|
46 | - { |
|
44 | + public static function getLanguageNames() { |
|
47 | 45 | return self::getData('languages'); |
48 | 46 | } |
49 | 47 | |
@@ -54,8 +52,7 @@ discard block |
||
54 | 52 | * |
55 | 53 | * @return string[] |
56 | 54 | */ |
57 | - public static function getTerritoryNames() |
|
58 | - { |
|
55 | + public static function getTerritoryNames() { |
|
59 | 56 | return self::getData('territories'); |
60 | 57 | } |
61 | 58 | |
@@ -68,8 +65,7 @@ discard block |
||
68 | 65 | * |
69 | 66 | * @return string[] |
70 | 67 | */ |
71 | - public static function getScriptNames($standAlone) |
|
72 | - { |
|
68 | + public static function getScriptNames($standAlone) { |
|
73 | 69 | return self::getData($standAlone ? 'standAloneScripts' : 'scripts'); |
74 | 70 | } |
75 | 71 | |
@@ -88,8 +84,7 @@ discard block |
||
88 | 84 | * |
89 | 85 | * @return array |
90 | 86 | */ |
91 | - public static function getPlurals() |
|
92 | - { |
|
87 | + public static function getPlurals() { |
|
93 | 88 | return self::getData('plurals'); |
94 | 89 | } |
95 | 90 | |
@@ -98,8 +93,7 @@ discard block |
||
98 | 93 | * |
99 | 94 | * @return array keys are the former language codes, values are the new language/locale codes |
100 | 95 | */ |
101 | - public static function getSupersededLanguages() |
|
102 | - { |
|
96 | + public static function getSupersededLanguages() { |
|
103 | 97 | return self::getData('supersededLanguages'); |
104 | 98 | } |
105 | 99 | |
@@ -110,8 +104,7 @@ discard block |
||
110 | 104 | * |
111 | 105 | * @return array|null Returns an array with the keys 'id' (normalized), 'name', 'supersededBy' (optional), 'territory' (optional), 'script' (optional), 'baseLanguage' (optional), 'categories'. If $id is not valid returns null. |
112 | 106 | */ |
113 | - public static function getLanguageInfo($id) |
|
114 | - { |
|
107 | + public static function getLanguageInfo($id) { |
|
115 | 108 | $result = null; |
116 | 109 | $matches = array(); |
117 | 110 | if (preg_match('/^([a-z]{2,3})(?:[_\-]([a-z]{4}))?(?:[_\-]([a-z]{2}|[0-9]{3}))?(?:$|-)/i', $id, $matches)) { |
@@ -235,8 +228,7 @@ discard block |
||
235 | 228 | * |
236 | 229 | * @return array |
237 | 230 | */ |
238 | - private static function getData($key) |
|
239 | - { |
|
231 | + private static function getData($key) { |
|
240 | 232 | if (!isset(self::$data)) { |
241 | 233 | $fixKeys = function ($list, &$standAlone = null) { |
242 | 234 | $result = array(); |
@@ -15,330 +15,330 @@ |
||
15 | 15 | */ |
16 | 16 | class CldrData |
17 | 17 | { |
18 | - /** |
|
19 | - * Super-special plural category: this should always be present for any language. |
|
20 | - * |
|
21 | - * @var string |
|
22 | - */ |
|
23 | - const OTHER_CATEGORY = 'other'; |
|
18 | + /** |
|
19 | + * Super-special plural category: this should always be present for any language. |
|
20 | + * |
|
21 | + * @var string |
|
22 | + */ |
|
23 | + const OTHER_CATEGORY = 'other'; |
|
24 | 24 | |
25 | - /** |
|
26 | - * The list of the plural categories, sorted from 'zero' to 'other'. |
|
27 | - * |
|
28 | - * @var string[] |
|
29 | - */ |
|
30 | - public static $categories = array('zero', 'one', 'two', 'few', 'many', self::OTHER_CATEGORY); |
|
25 | + /** |
|
26 | + * The list of the plural categories, sorted from 'zero' to 'other'. |
|
27 | + * |
|
28 | + * @var string[] |
|
29 | + */ |
|
30 | + public static $categories = array('zero', 'one', 'two', 'few', 'many', self::OTHER_CATEGORY); |
|
31 | 31 | |
32 | - /** |
|
33 | - * The loaded CLDR data. |
|
34 | - * |
|
35 | - * @var array |
|
36 | - */ |
|
37 | - private static $data; |
|
32 | + /** |
|
33 | + * The loaded CLDR data. |
|
34 | + * |
|
35 | + * @var array |
|
36 | + */ |
|
37 | + private static $data; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - private static $plurals; |
|
39 | + /** |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + private static $plurals; |
|
43 | 43 | |
44 | - /** |
|
45 | - * Returns a dictionary containing the language names. |
|
46 | - * The keys are the language identifiers. |
|
47 | - * The values are the language names in US English. |
|
48 | - * |
|
49 | - * @return string[] |
|
50 | - */ |
|
51 | - public static function getLanguageNames() |
|
52 | - { |
|
53 | - return self::getData('languages'); |
|
54 | - } |
|
44 | + /** |
|
45 | + * Returns a dictionary containing the language names. |
|
46 | + * The keys are the language identifiers. |
|
47 | + * The values are the language names in US English. |
|
48 | + * |
|
49 | + * @return string[] |
|
50 | + */ |
|
51 | + public static function getLanguageNames() |
|
52 | + { |
|
53 | + return self::getData('languages'); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * Return a dictionary containing the territory names (in US English). |
|
58 | - * The keys are the territory identifiers. |
|
59 | - * The values are the territory names in US English. |
|
60 | - * |
|
61 | - * @return string[] |
|
62 | - */ |
|
63 | - public static function getTerritoryNames() |
|
64 | - { |
|
65 | - return self::getData('territories'); |
|
66 | - } |
|
56 | + /** |
|
57 | + * Return a dictionary containing the territory names (in US English). |
|
58 | + * The keys are the territory identifiers. |
|
59 | + * The values are the territory names in US English. |
|
60 | + * |
|
61 | + * @return string[] |
|
62 | + */ |
|
63 | + public static function getTerritoryNames() |
|
64 | + { |
|
65 | + return self::getData('territories'); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * Return a dictionary containing the script names (in US English). |
|
70 | - * The keys are the script identifiers. |
|
71 | - * The values are the script names in US English. |
|
72 | - * |
|
73 | - * @param bool $standAlone set to true to retrieve the stand-alone script names, false otherwise |
|
74 | - * |
|
75 | - * @return string[] |
|
76 | - */ |
|
77 | - public static function getScriptNames($standAlone) |
|
78 | - { |
|
79 | - return self::getData($standAlone ? 'standAloneScripts' : 'scripts'); |
|
80 | - } |
|
68 | + /** |
|
69 | + * Return a dictionary containing the script names (in US English). |
|
70 | + * The keys are the script identifiers. |
|
71 | + * The values are the script names in US English. |
|
72 | + * |
|
73 | + * @param bool $standAlone set to true to retrieve the stand-alone script names, false otherwise |
|
74 | + * |
|
75 | + * @return string[] |
|
76 | + */ |
|
77 | + public static function getScriptNames($standAlone) |
|
78 | + { |
|
79 | + return self::getData($standAlone ? 'standAloneScripts' : 'scripts'); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * A dictionary containing the plural rules. |
|
84 | - * The keys are the language identifiers. |
|
85 | - * The values are arrays whose keys are the CLDR category names and the values are the CLDR category definition. |
|
86 | - * |
|
87 | - * @example The English key-value pair is somethink like this: |
|
88 | - * <code><pre> |
|
89 | - * "en": { |
|
90 | - * "pluralRule-count-one": "i = 1 and v = 0 @integer 1", |
|
91 | - * "pluralRule-count-other": " @integer 0, 2~16, 100, 1000, 10000, 100000, 1000000, … @decimal 0.0~1.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …" |
|
92 | - * } |
|
93 | - * </pre></code> |
|
94 | - * |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - public static function getPlurals() |
|
98 | - { |
|
99 | - return self::getData('plurals'); |
|
100 | - } |
|
82 | + /** |
|
83 | + * A dictionary containing the plural rules. |
|
84 | + * The keys are the language identifiers. |
|
85 | + * The values are arrays whose keys are the CLDR category names and the values are the CLDR category definition. |
|
86 | + * |
|
87 | + * @example The English key-value pair is somethink like this: |
|
88 | + * <code><pre> |
|
89 | + * "en": { |
|
90 | + * "pluralRule-count-one": "i = 1 and v = 0 @integer 1", |
|
91 | + * "pluralRule-count-other": " @integer 0, 2~16, 100, 1000, 10000, 100000, 1000000, … @decimal 0.0~1.5, 10.0, 100.0, 1000.0, 10000.0, 100000.0, 1000000.0, …" |
|
92 | + * } |
|
93 | + * </pre></code> |
|
94 | + * |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + public static function getPlurals() |
|
98 | + { |
|
99 | + return self::getData('plurals'); |
|
100 | + } |
|
101 | 101 | |
102 | - /** |
|
103 | - * Return a list of superseded language codes. |
|
104 | - * |
|
105 | - * @return array keys are the former language codes, values are the new language/locale codes |
|
106 | - */ |
|
107 | - public static function getSupersededLanguages() |
|
108 | - { |
|
109 | - return self::getData('supersededLanguages'); |
|
110 | - } |
|
102 | + /** |
|
103 | + * Return a list of superseded language codes. |
|
104 | + * |
|
105 | + * @return array keys are the former language codes, values are the new language/locale codes |
|
106 | + */ |
|
107 | + public static function getSupersededLanguages() |
|
108 | + { |
|
109 | + return self::getData('supersededLanguages'); |
|
110 | + } |
|
111 | 111 | |
112 | - /** |
|
113 | - * Retrieve the name of a language, as well as if a language code is deprecated in favor of another language code. |
|
114 | - * |
|
115 | - * @param string $id the language identifier |
|
116 | - * |
|
117 | - * @return array|null Returns an array with the keys 'id' (normalized), 'name', 'supersededBy' (optional), 'territory' (optional), 'script' (optional), 'baseLanguage' (optional), 'categories'. If $id is not valid returns null. |
|
118 | - */ |
|
119 | - public static function getLanguageInfo($id) |
|
120 | - { |
|
121 | - $result = null; |
|
122 | - $matches = array(); |
|
123 | - if (preg_match('/^([a-z]{2,3})(?:[_\-]([a-z]{4}))?(?:[_\-]([a-z]{2}|[0-9]{3}))?(?:$|-)/i', $id, $matches)) { |
|
124 | - $languageId = strtolower($matches[1]); |
|
125 | - $scriptId = (isset($matches[2]) && ($matches[2] !== '')) ? ucfirst(strtolower($matches[2])) : null; |
|
126 | - $territoryId = (isset($matches[3]) && ($matches[3] !== '')) ? strtoupper($matches[3]) : null; |
|
127 | - $normalizedId = $languageId; |
|
128 | - if (isset($scriptId)) { |
|
129 | - $normalizedId .= '_' . $scriptId; |
|
130 | - } |
|
131 | - if (isset($territoryId)) { |
|
132 | - $normalizedId .= '_' . $territoryId; |
|
133 | - } |
|
134 | - // Structure precedence: see Likely Subtags - http://www.unicode.org/reports/tr35/tr35-31/tr35.html#Likely_Subtags |
|
135 | - $variants = array(); |
|
136 | - $variantsWithScript = array(); |
|
137 | - $variantsWithTerritory = array(); |
|
138 | - if (isset($scriptId) && isset($territoryId)) { |
|
139 | - $variantsWithTerritory[] = $variantsWithScript[] = $variants[] = "{$languageId}_{$scriptId}_{$territoryId}"; |
|
140 | - } |
|
141 | - if (isset($scriptId)) { |
|
142 | - $variantsWithScript[] = $variants[] = "{$languageId}_{$scriptId}"; |
|
143 | - } |
|
144 | - if (isset($territoryId)) { |
|
145 | - $variantsWithTerritory[] = $variants[] = "{$languageId}_{$territoryId}"; |
|
146 | - } |
|
147 | - $variants[] = $languageId; |
|
148 | - $allGood = true; |
|
149 | - $scriptName = null; |
|
150 | - $scriptStandAloneName = null; |
|
151 | - if (isset($scriptId)) { |
|
152 | - $scriptNames = self::getScriptNames(false); |
|
153 | - if (isset($scriptNames[$scriptId])) { |
|
154 | - $scriptName = $scriptNames[$scriptId]; |
|
155 | - $scriptStandAloneNames = self::getScriptNames(true); |
|
156 | - $scriptStandAloneName = $scriptStandAloneNames[$scriptId]; |
|
157 | - } else { |
|
158 | - $allGood = false; |
|
159 | - } |
|
160 | - } |
|
161 | - $territoryName = null; |
|
162 | - if (isset($territoryId)) { |
|
163 | - $territoryNames = self::getTerritoryNames(); |
|
164 | - if (isset($territoryNames[$territoryId])) { |
|
165 | - if ($territoryId !== '001') { |
|
166 | - $territoryName = $territoryNames[$territoryId]; |
|
167 | - } |
|
168 | - } else { |
|
169 | - $allGood = false; |
|
170 | - } |
|
171 | - } |
|
172 | - $languageName = null; |
|
173 | - $languageNames = self::getLanguageNames(); |
|
174 | - foreach ($variants as $variant) { |
|
175 | - if (isset($languageNames[$variant])) { |
|
176 | - $languageName = $languageNames[$variant]; |
|
177 | - if (isset($scriptName) && (!in_array($variant, $variantsWithScript))) { |
|
178 | - $languageName = $scriptName . ' ' . $languageName; |
|
179 | - } |
|
180 | - if (isset($territoryName) && (!in_array($variant, $variantsWithTerritory))) { |
|
181 | - $languageName .= ' (' . $territoryNames[$territoryId] . ')'; |
|
182 | - } |
|
183 | - break; |
|
184 | - } |
|
185 | - } |
|
186 | - if (!isset($languageName)) { |
|
187 | - $allGood = false; |
|
188 | - } |
|
189 | - $baseLanguage = null; |
|
190 | - if (isset($scriptId) || isset($territoryId)) { |
|
191 | - if (isset($languageNames[$languageId]) && ($languageNames[$languageId] !== $languageName)) { |
|
192 | - $baseLanguage = $languageNames[$languageId]; |
|
193 | - } |
|
194 | - } |
|
195 | - $plural = null; |
|
196 | - $plurals = self::getPlurals(); |
|
197 | - foreach ($variants as $variant) { |
|
198 | - if (isset($plurals[$variant])) { |
|
199 | - $plural = $plurals[$variant]; |
|
200 | - break; |
|
201 | - } |
|
202 | - } |
|
203 | - if (!isset($plural)) { |
|
204 | - $allGood = false; |
|
205 | - } |
|
206 | - $supersededBy = null; |
|
207 | - $supersededBys = self::getSupersededLanguages(); |
|
208 | - foreach ($variants as $variant) { |
|
209 | - if (isset($supersededBys[$variant])) { |
|
210 | - $supersededBy = $supersededBys[$variant]; |
|
211 | - break; |
|
212 | - } |
|
213 | - } |
|
214 | - if ($allGood) { |
|
215 | - $result = array(); |
|
216 | - $result['id'] = $normalizedId; |
|
217 | - $result['name'] = $languageName; |
|
218 | - if (isset($supersededBy)) { |
|
219 | - $result['supersededBy'] = $supersededBy; |
|
220 | - } |
|
221 | - if (isset($scriptStandAloneName)) { |
|
222 | - $result['script'] = $scriptStandAloneName; |
|
223 | - } |
|
224 | - if (isset($territoryName)) { |
|
225 | - $result['territory'] = $territoryName; |
|
226 | - } |
|
227 | - if (isset($baseLanguage)) { |
|
228 | - $result['baseLanguage'] = $baseLanguage; |
|
229 | - } |
|
230 | - $result['categories'] = $plural; |
|
231 | - } |
|
232 | - } |
|
112 | + /** |
|
113 | + * Retrieve the name of a language, as well as if a language code is deprecated in favor of another language code. |
|
114 | + * |
|
115 | + * @param string $id the language identifier |
|
116 | + * |
|
117 | + * @return array|null Returns an array with the keys 'id' (normalized), 'name', 'supersededBy' (optional), 'territory' (optional), 'script' (optional), 'baseLanguage' (optional), 'categories'. If $id is not valid returns null. |
|
118 | + */ |
|
119 | + public static function getLanguageInfo($id) |
|
120 | + { |
|
121 | + $result = null; |
|
122 | + $matches = array(); |
|
123 | + if (preg_match('/^([a-z]{2,3})(?:[_\-]([a-z]{4}))?(?:[_\-]([a-z]{2}|[0-9]{3}))?(?:$|-)/i', $id, $matches)) { |
|
124 | + $languageId = strtolower($matches[1]); |
|
125 | + $scriptId = (isset($matches[2]) && ($matches[2] !== '')) ? ucfirst(strtolower($matches[2])) : null; |
|
126 | + $territoryId = (isset($matches[3]) && ($matches[3] !== '')) ? strtoupper($matches[3]) : null; |
|
127 | + $normalizedId = $languageId; |
|
128 | + if (isset($scriptId)) { |
|
129 | + $normalizedId .= '_' . $scriptId; |
|
130 | + } |
|
131 | + if (isset($territoryId)) { |
|
132 | + $normalizedId .= '_' . $territoryId; |
|
133 | + } |
|
134 | + // Structure precedence: see Likely Subtags - http://www.unicode.org/reports/tr35/tr35-31/tr35.html#Likely_Subtags |
|
135 | + $variants = array(); |
|
136 | + $variantsWithScript = array(); |
|
137 | + $variantsWithTerritory = array(); |
|
138 | + if (isset($scriptId) && isset($territoryId)) { |
|
139 | + $variantsWithTerritory[] = $variantsWithScript[] = $variants[] = "{$languageId}_{$scriptId}_{$territoryId}"; |
|
140 | + } |
|
141 | + if (isset($scriptId)) { |
|
142 | + $variantsWithScript[] = $variants[] = "{$languageId}_{$scriptId}"; |
|
143 | + } |
|
144 | + if (isset($territoryId)) { |
|
145 | + $variantsWithTerritory[] = $variants[] = "{$languageId}_{$territoryId}"; |
|
146 | + } |
|
147 | + $variants[] = $languageId; |
|
148 | + $allGood = true; |
|
149 | + $scriptName = null; |
|
150 | + $scriptStandAloneName = null; |
|
151 | + if (isset($scriptId)) { |
|
152 | + $scriptNames = self::getScriptNames(false); |
|
153 | + if (isset($scriptNames[$scriptId])) { |
|
154 | + $scriptName = $scriptNames[$scriptId]; |
|
155 | + $scriptStandAloneNames = self::getScriptNames(true); |
|
156 | + $scriptStandAloneName = $scriptStandAloneNames[$scriptId]; |
|
157 | + } else { |
|
158 | + $allGood = false; |
|
159 | + } |
|
160 | + } |
|
161 | + $territoryName = null; |
|
162 | + if (isset($territoryId)) { |
|
163 | + $territoryNames = self::getTerritoryNames(); |
|
164 | + if (isset($territoryNames[$territoryId])) { |
|
165 | + if ($territoryId !== '001') { |
|
166 | + $territoryName = $territoryNames[$territoryId]; |
|
167 | + } |
|
168 | + } else { |
|
169 | + $allGood = false; |
|
170 | + } |
|
171 | + } |
|
172 | + $languageName = null; |
|
173 | + $languageNames = self::getLanguageNames(); |
|
174 | + foreach ($variants as $variant) { |
|
175 | + if (isset($languageNames[$variant])) { |
|
176 | + $languageName = $languageNames[$variant]; |
|
177 | + if (isset($scriptName) && (!in_array($variant, $variantsWithScript))) { |
|
178 | + $languageName = $scriptName . ' ' . $languageName; |
|
179 | + } |
|
180 | + if (isset($territoryName) && (!in_array($variant, $variantsWithTerritory))) { |
|
181 | + $languageName .= ' (' . $territoryNames[$territoryId] . ')'; |
|
182 | + } |
|
183 | + break; |
|
184 | + } |
|
185 | + } |
|
186 | + if (!isset($languageName)) { |
|
187 | + $allGood = false; |
|
188 | + } |
|
189 | + $baseLanguage = null; |
|
190 | + if (isset($scriptId) || isset($territoryId)) { |
|
191 | + if (isset($languageNames[$languageId]) && ($languageNames[$languageId] !== $languageName)) { |
|
192 | + $baseLanguage = $languageNames[$languageId]; |
|
193 | + } |
|
194 | + } |
|
195 | + $plural = null; |
|
196 | + $plurals = self::getPlurals(); |
|
197 | + foreach ($variants as $variant) { |
|
198 | + if (isset($plurals[$variant])) { |
|
199 | + $plural = $plurals[$variant]; |
|
200 | + break; |
|
201 | + } |
|
202 | + } |
|
203 | + if (!isset($plural)) { |
|
204 | + $allGood = false; |
|
205 | + } |
|
206 | + $supersededBy = null; |
|
207 | + $supersededBys = self::getSupersededLanguages(); |
|
208 | + foreach ($variants as $variant) { |
|
209 | + if (isset($supersededBys[$variant])) { |
|
210 | + $supersededBy = $supersededBys[$variant]; |
|
211 | + break; |
|
212 | + } |
|
213 | + } |
|
214 | + if ($allGood) { |
|
215 | + $result = array(); |
|
216 | + $result['id'] = $normalizedId; |
|
217 | + $result['name'] = $languageName; |
|
218 | + if (isset($supersededBy)) { |
|
219 | + $result['supersededBy'] = $supersededBy; |
|
220 | + } |
|
221 | + if (isset($scriptStandAloneName)) { |
|
222 | + $result['script'] = $scriptStandAloneName; |
|
223 | + } |
|
224 | + if (isset($territoryName)) { |
|
225 | + $result['territory'] = $territoryName; |
|
226 | + } |
|
227 | + if (isset($baseLanguage)) { |
|
228 | + $result['baseLanguage'] = $baseLanguage; |
|
229 | + } |
|
230 | + $result['categories'] = $plural; |
|
231 | + } |
|
232 | + } |
|
233 | 233 | |
234 | - return $result; |
|
235 | - } |
|
234 | + return $result; |
|
235 | + } |
|
236 | 236 | |
237 | - /** |
|
238 | - * Returns the loaded CLDR data. |
|
239 | - * |
|
240 | - * @param string $key Can be 'languages', 'territories', 'plurals', 'supersededLanguages', 'scripts', 'standAloneScripts' |
|
241 | - * |
|
242 | - * @return array |
|
243 | - */ |
|
244 | - private static function getData($key) |
|
245 | - { |
|
246 | - if (!isset(self::$data)) { |
|
247 | - $fixKeys = function ($list, &$standAlone = null) { |
|
248 | - $result = array(); |
|
249 | - $standAlone = array(); |
|
250 | - $match = null; |
|
251 | - foreach ($list as $key => $value) { |
|
252 | - $variant = ''; |
|
253 | - if (preg_match('/^(.+)-alt-(short|variant|stand-alone|long|menu)$/', $key, $match)) { |
|
254 | - $key = $match[1]; |
|
255 | - $variant = $match[2]; |
|
256 | - } |
|
257 | - $key = str_replace('-', '_', $key); |
|
258 | - switch ($key) { |
|
259 | - case 'root': // Language: Root |
|
260 | - case 'und': // Language: Unknown Language |
|
261 | - case 'zxx': // Language: No linguistic content |
|
262 | - case 'ZZ': // Territory: Unknown Region |
|
263 | - case 'Zinh': // Script: Inherited |
|
264 | - case 'Zmth': // Script: Mathematical Notation |
|
265 | - case 'Zsym': // Script: Symbols |
|
266 | - case 'Zxxx': // Script: Unwritten |
|
267 | - case 'Zyyy': // Script: Common |
|
268 | - case 'Zzzz': // Script: Unknown Script |
|
269 | - break; |
|
270 | - default: |
|
271 | - switch ($variant) { |
|
272 | - case 'stand-alone': |
|
273 | - $standAlone[$key] = $value; |
|
274 | - break; |
|
275 | - case '': |
|
276 | - $result[$key] = $value; |
|
277 | - break; |
|
278 | - } |
|
279 | - break; |
|
280 | - } |
|
281 | - } |
|
237 | + /** |
|
238 | + * Returns the loaded CLDR data. |
|
239 | + * |
|
240 | + * @param string $key Can be 'languages', 'territories', 'plurals', 'supersededLanguages', 'scripts', 'standAloneScripts' |
|
241 | + * |
|
242 | + * @return array |
|
243 | + */ |
|
244 | + private static function getData($key) |
|
245 | + { |
|
246 | + if (!isset(self::$data)) { |
|
247 | + $fixKeys = function ($list, &$standAlone = null) { |
|
248 | + $result = array(); |
|
249 | + $standAlone = array(); |
|
250 | + $match = null; |
|
251 | + foreach ($list as $key => $value) { |
|
252 | + $variant = ''; |
|
253 | + if (preg_match('/^(.+)-alt-(short|variant|stand-alone|long|menu)$/', $key, $match)) { |
|
254 | + $key = $match[1]; |
|
255 | + $variant = $match[2]; |
|
256 | + } |
|
257 | + $key = str_replace('-', '_', $key); |
|
258 | + switch ($key) { |
|
259 | + case 'root': // Language: Root |
|
260 | + case 'und': // Language: Unknown Language |
|
261 | + case 'zxx': // Language: No linguistic content |
|
262 | + case 'ZZ': // Territory: Unknown Region |
|
263 | + case 'Zinh': // Script: Inherited |
|
264 | + case 'Zmth': // Script: Mathematical Notation |
|
265 | + case 'Zsym': // Script: Symbols |
|
266 | + case 'Zxxx': // Script: Unwritten |
|
267 | + case 'Zyyy': // Script: Common |
|
268 | + case 'Zzzz': // Script: Unknown Script |
|
269 | + break; |
|
270 | + default: |
|
271 | + switch ($variant) { |
|
272 | + case 'stand-alone': |
|
273 | + $standAlone[$key] = $value; |
|
274 | + break; |
|
275 | + case '': |
|
276 | + $result[$key] = $value; |
|
277 | + break; |
|
278 | + } |
|
279 | + break; |
|
280 | + } |
|
281 | + } |
|
282 | 282 | |
283 | - return $result; |
|
284 | - }; |
|
285 | - $data = array(); |
|
286 | - $json = json_decode(file_get_contents(__DIR__ . '/cldr-data/main/en-US/languages.json'), true); |
|
287 | - $data['languages'] = $fixKeys($json['main']['en-US']['localeDisplayNames']['languages']); |
|
288 | - $json = json_decode(file_get_contents(__DIR__ . '/cldr-data/main/en-US/territories.json'), true); |
|
289 | - $data['territories'] = $fixKeys($json['main']['en-US']['localeDisplayNames']['territories']); |
|
290 | - $json = json_decode(file_get_contents(__DIR__ . '/cldr-data/supplemental/plurals.json'), true); |
|
291 | - $data['plurals'] = $fixKeys($json['supplemental']['plurals-type-cardinal']); |
|
292 | - $json = json_decode(file_get_contents(__DIR__ . '/cldr-data/main/en-US/scripts.json'), true); |
|
293 | - $data['scripts'] = $fixKeys($json['main']['en-US']['localeDisplayNames']['scripts'], $data['standAloneScripts']); |
|
294 | - $data['standAloneScripts'] = array_merge($data['scripts'], $data['standAloneScripts']); |
|
295 | - $data['scripts'] = array_merge($data['standAloneScripts'], $data['scripts']); |
|
296 | - $data['supersededLanguages'] = array(); |
|
297 | - // Remove the languages for which we don't have plurals |
|
298 | - $m = null; |
|
299 | - foreach (array_keys(array_diff_key($data['languages'], $data['plurals'])) as $missingPlural) { |
|
300 | - if (preg_match('/^([a-z]{2,3})_/', $missingPlural, $m)) { |
|
301 | - if (!isset($data['plurals'][$m[1]])) { |
|
302 | - unset($data['languages'][$missingPlural]); |
|
303 | - } |
|
304 | - } else { |
|
305 | - unset($data['languages'][$missingPlural]); |
|
306 | - } |
|
307 | - } |
|
308 | - // Fix the languages for which we have plurals |
|
309 | - $formerCodes = array( |
|
310 | - 'jw' => 'jv', // former Javanese |
|
311 | - 'mo' => 'ro_MD', // former Moldavian |
|
312 | - ); |
|
313 | - $knownMissingLanguages = array( |
|
314 | - 'guw' => 'Gun', |
|
315 | - 'nah' => 'Nahuatl', |
|
316 | - 'smi' => 'Sami', |
|
317 | - ); |
|
318 | - foreach (array_keys(array_diff_key($data['plurals'], $data['languages'])) as $missingLanguage) { |
|
319 | - if (isset($formerCodes[$missingLanguage]) && isset($data['languages'][$formerCodes[$missingLanguage]])) { |
|
320 | - $data['languages'][$missingLanguage] = $data['languages'][$formerCodes[$missingLanguage]]; |
|
321 | - $data['supersededLanguages'][$missingLanguage] = $formerCodes[$missingLanguage]; |
|
322 | - } else { |
|
323 | - if (isset($knownMissingLanguages[$missingLanguage])) { |
|
324 | - $data['languages'][$missingLanguage] = $knownMissingLanguages[$missingLanguage]; |
|
325 | - } else { |
|
326 | - throw new Exception("We have the plural rule for the language '{$missingLanguage}' but we don't have its language name"); |
|
327 | - } |
|
328 | - } |
|
329 | - } |
|
330 | - ksort($data['languages'], SORT_STRING); |
|
331 | - ksort($data['territories'], SORT_STRING); |
|
332 | - ksort($data['plurals'], SORT_STRING); |
|
333 | - ksort($data['scripts'], SORT_STRING); |
|
334 | - ksort($data['standAloneScripts'], SORT_STRING); |
|
335 | - ksort($data['supersededLanguages'], SORT_STRING); |
|
336 | - self::$data = $data; |
|
337 | - } |
|
338 | - if (!isset(self::$data[$key])) { |
|
339 | - throw new Exception("Invalid CLDR data key: '{$key}'"); |
|
340 | - } |
|
283 | + return $result; |
|
284 | + }; |
|
285 | + $data = array(); |
|
286 | + $json = json_decode(file_get_contents(__DIR__ . '/cldr-data/main/en-US/languages.json'), true); |
|
287 | + $data['languages'] = $fixKeys($json['main']['en-US']['localeDisplayNames']['languages']); |
|
288 | + $json = json_decode(file_get_contents(__DIR__ . '/cldr-data/main/en-US/territories.json'), true); |
|
289 | + $data['territories'] = $fixKeys($json['main']['en-US']['localeDisplayNames']['territories']); |
|
290 | + $json = json_decode(file_get_contents(__DIR__ . '/cldr-data/supplemental/plurals.json'), true); |
|
291 | + $data['plurals'] = $fixKeys($json['supplemental']['plurals-type-cardinal']); |
|
292 | + $json = json_decode(file_get_contents(__DIR__ . '/cldr-data/main/en-US/scripts.json'), true); |
|
293 | + $data['scripts'] = $fixKeys($json['main']['en-US']['localeDisplayNames']['scripts'], $data['standAloneScripts']); |
|
294 | + $data['standAloneScripts'] = array_merge($data['scripts'], $data['standAloneScripts']); |
|
295 | + $data['scripts'] = array_merge($data['standAloneScripts'], $data['scripts']); |
|
296 | + $data['supersededLanguages'] = array(); |
|
297 | + // Remove the languages for which we don't have plurals |
|
298 | + $m = null; |
|
299 | + foreach (array_keys(array_diff_key($data['languages'], $data['plurals'])) as $missingPlural) { |
|
300 | + if (preg_match('/^([a-z]{2,3})_/', $missingPlural, $m)) { |
|
301 | + if (!isset($data['plurals'][$m[1]])) { |
|
302 | + unset($data['languages'][$missingPlural]); |
|
303 | + } |
|
304 | + } else { |
|
305 | + unset($data['languages'][$missingPlural]); |
|
306 | + } |
|
307 | + } |
|
308 | + // Fix the languages for which we have plurals |
|
309 | + $formerCodes = array( |
|
310 | + 'jw' => 'jv', // former Javanese |
|
311 | + 'mo' => 'ro_MD', // former Moldavian |
|
312 | + ); |
|
313 | + $knownMissingLanguages = array( |
|
314 | + 'guw' => 'Gun', |
|
315 | + 'nah' => 'Nahuatl', |
|
316 | + 'smi' => 'Sami', |
|
317 | + ); |
|
318 | + foreach (array_keys(array_diff_key($data['plurals'], $data['languages'])) as $missingLanguage) { |
|
319 | + if (isset($formerCodes[$missingLanguage]) && isset($data['languages'][$formerCodes[$missingLanguage]])) { |
|
320 | + $data['languages'][$missingLanguage] = $data['languages'][$formerCodes[$missingLanguage]]; |
|
321 | + $data['supersededLanguages'][$missingLanguage] = $formerCodes[$missingLanguage]; |
|
322 | + } else { |
|
323 | + if (isset($knownMissingLanguages[$missingLanguage])) { |
|
324 | + $data['languages'][$missingLanguage] = $knownMissingLanguages[$missingLanguage]; |
|
325 | + } else { |
|
326 | + throw new Exception("We have the plural rule for the language '{$missingLanguage}' but we don't have its language name"); |
|
327 | + } |
|
328 | + } |
|
329 | + } |
|
330 | + ksort($data['languages'], SORT_STRING); |
|
331 | + ksort($data['territories'], SORT_STRING); |
|
332 | + ksort($data['plurals'], SORT_STRING); |
|
333 | + ksort($data['scripts'], SORT_STRING); |
|
334 | + ksort($data['standAloneScripts'], SORT_STRING); |
|
335 | + ksort($data['supersededLanguages'], SORT_STRING); |
|
336 | + self::$data = $data; |
|
337 | + } |
|
338 | + if (!isset(self::$data[$key])) { |
|
339 | + throw new Exception("Invalid CLDR data key: '{$key}'"); |
|
340 | + } |
|
341 | 341 | |
342 | - return self::$data[$key]; |
|
343 | - } |
|
342 | + return self::$data[$key]; |
|
343 | + } |
|
344 | 344 | } |
@@ -9,145 +9,145 @@ |
||
9 | 9 | */ |
10 | 10 | abstract class Exporter |
11 | 11 | { |
12 | - /** |
|
13 | - * @var array |
|
14 | - */ |
|
15 | - private static $exporters; |
|
12 | + /** |
|
13 | + * @var array |
|
14 | + */ |
|
15 | + private static $exporters; |
|
16 | 16 | |
17 | - /** |
|
18 | - * Return the list of all the available exporters. Keys are the exporter handles, values are the exporter class names. |
|
19 | - * |
|
20 | - * @param bool $onlyForPublicUse if true, internal exporters will be omitted |
|
21 | - * |
|
22 | - * @return string[] |
|
23 | - */ |
|
24 | - final public static function getExporters($onlyForPublicUse = false) |
|
25 | - { |
|
26 | - if (!isset(self::$exporters)) { |
|
27 | - $exporters = array(); |
|
28 | - $m = null; |
|
29 | - foreach (scandir(__DIR__) as $f) { |
|
30 | - if (preg_match('/^(\w+)\.php$/', $f, $m)) { |
|
31 | - if ($f !== basename(__FILE__)) { |
|
32 | - $exporters[strtolower($m[1])] = $m[1]; |
|
33 | - } |
|
34 | - } |
|
35 | - } |
|
36 | - self::$exporters = $exporters; |
|
37 | - } |
|
38 | - if ($onlyForPublicUse) { |
|
39 | - $result = array(); |
|
40 | - foreach (self::$exporters as $handle => $class) { |
|
41 | - if (call_user_func(self::getExporterClassName($handle) . '::isForPublicUse') === true) { |
|
42 | - $result[$handle] = $class; |
|
43 | - } |
|
44 | - } |
|
45 | - } else { |
|
46 | - $result = self::$exporters; |
|
47 | - } |
|
17 | + /** |
|
18 | + * Return the list of all the available exporters. Keys are the exporter handles, values are the exporter class names. |
|
19 | + * |
|
20 | + * @param bool $onlyForPublicUse if true, internal exporters will be omitted |
|
21 | + * |
|
22 | + * @return string[] |
|
23 | + */ |
|
24 | + final public static function getExporters($onlyForPublicUse = false) |
|
25 | + { |
|
26 | + if (!isset(self::$exporters)) { |
|
27 | + $exporters = array(); |
|
28 | + $m = null; |
|
29 | + foreach (scandir(__DIR__) as $f) { |
|
30 | + if (preg_match('/^(\w+)\.php$/', $f, $m)) { |
|
31 | + if ($f !== basename(__FILE__)) { |
|
32 | + $exporters[strtolower($m[1])] = $m[1]; |
|
33 | + } |
|
34 | + } |
|
35 | + } |
|
36 | + self::$exporters = $exporters; |
|
37 | + } |
|
38 | + if ($onlyForPublicUse) { |
|
39 | + $result = array(); |
|
40 | + foreach (self::$exporters as $handle => $class) { |
|
41 | + if (call_user_func(self::getExporterClassName($handle) . '::isForPublicUse') === true) { |
|
42 | + $result[$handle] = $class; |
|
43 | + } |
|
44 | + } |
|
45 | + } else { |
|
46 | + $result = self::$exporters; |
|
47 | + } |
|
48 | 48 | |
49 | - return $result; |
|
50 | - } |
|
49 | + return $result; |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Return the description of a specific exporter. |
|
54 | - * |
|
55 | - * @param string $exporterHandle the handle of the exporter |
|
56 | - * |
|
57 | - * @throws \Exception throws an Exception if $exporterHandle is not valid |
|
58 | - * |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - final public static function getExporterDescription($exporterHandle) |
|
62 | - { |
|
63 | - $exporters = self::getExporters(); |
|
64 | - if (!isset($exporters[$exporterHandle])) { |
|
65 | - throw new Exception("Invalid exporter handle: '{$exporterHandle}'"); |
|
66 | - } |
|
52 | + /** |
|
53 | + * Return the description of a specific exporter. |
|
54 | + * |
|
55 | + * @param string $exporterHandle the handle of the exporter |
|
56 | + * |
|
57 | + * @throws \Exception throws an Exception if $exporterHandle is not valid |
|
58 | + * |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + final public static function getExporterDescription($exporterHandle) |
|
62 | + { |
|
63 | + $exporters = self::getExporters(); |
|
64 | + if (!isset($exporters[$exporterHandle])) { |
|
65 | + throw new Exception("Invalid exporter handle: '{$exporterHandle}'"); |
|
66 | + } |
|
67 | 67 | |
68 | - return call_user_func(self::getExporterClassName($exporterHandle) . '::getDescription'); |
|
69 | - } |
|
68 | + return call_user_func(self::getExporterClassName($exporterHandle) . '::getDescription'); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Returns the fully qualified class name of a exporter given its handle. |
|
73 | - * |
|
74 | - * @param string $exporterHandle the exporter class handle |
|
75 | - * |
|
76 | - * @return string |
|
77 | - */ |
|
78 | - final public static function getExporterClassName($exporterHandle) |
|
79 | - { |
|
80 | - return __NAMESPACE__ . '\\' . ucfirst(strtolower($exporterHandle)); |
|
81 | - } |
|
71 | + /** |
|
72 | + * Returns the fully qualified class name of a exporter given its handle. |
|
73 | + * |
|
74 | + * @param string $exporterHandle the exporter class handle |
|
75 | + * |
|
76 | + * @return string |
|
77 | + */ |
|
78 | + final public static function getExporterClassName($exporterHandle) |
|
79 | + { |
|
80 | + return __NAMESPACE__ . '\\' . ucfirst(strtolower($exporterHandle)); |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Convert a list of Language instances to string. |
|
85 | - * |
|
86 | - * @param \Gettext\Languages\Language[] $languages the Language instances to convert |
|
87 | - * @param array|null $options |
|
88 | - * |
|
89 | - * @return string |
|
90 | - */ |
|
91 | - final public static function toString($languages, $options = null) |
|
92 | - { |
|
93 | - if (isset($options) && is_array($options)) { |
|
94 | - if (isset($options['us-ascii']) && $options['us-ascii']) { |
|
95 | - $asciiList = array(); |
|
96 | - foreach ($languages as $language) { |
|
97 | - $asciiList[] = $language->getUSAsciiClone(); |
|
98 | - } |
|
99 | - $languages = $asciiList; |
|
100 | - } |
|
101 | - } |
|
83 | + /** |
|
84 | + * Convert a list of Language instances to string. |
|
85 | + * |
|
86 | + * @param \Gettext\Languages\Language[] $languages the Language instances to convert |
|
87 | + * @param array|null $options |
|
88 | + * |
|
89 | + * @return string |
|
90 | + */ |
|
91 | + final public static function toString($languages, $options = null) |
|
92 | + { |
|
93 | + if (isset($options) && is_array($options)) { |
|
94 | + if (isset($options['us-ascii']) && $options['us-ascii']) { |
|
95 | + $asciiList = array(); |
|
96 | + foreach ($languages as $language) { |
|
97 | + $asciiList[] = $language->getUSAsciiClone(); |
|
98 | + } |
|
99 | + $languages = $asciiList; |
|
100 | + } |
|
101 | + } |
|
102 | 102 | |
103 | - return static::toStringDo($languages); |
|
104 | - } |
|
103 | + return static::toStringDo($languages); |
|
104 | + } |
|
105 | 105 | |
106 | - /** |
|
107 | - * Save the Language instances to a file. |
|
108 | - * |
|
109 | - * @param \Gettext\Languages\Language[] $languages the Language instances to convert |
|
110 | - * @param array|null $options |
|
111 | - * |
|
112 | - * @throws \Exception |
|
113 | - */ |
|
114 | - final public static function toFile($languages, $filename, $options = null) |
|
115 | - { |
|
116 | - $data = self::toString($languages, $options); |
|
117 | - if (@file_put_contents($filename, $data) === false) { |
|
118 | - throw new Exception("Error writing data to '{$filename}'"); |
|
119 | - } |
|
120 | - } |
|
106 | + /** |
|
107 | + * Save the Language instances to a file. |
|
108 | + * |
|
109 | + * @param \Gettext\Languages\Language[] $languages the Language instances to convert |
|
110 | + * @param array|null $options |
|
111 | + * |
|
112 | + * @throws \Exception |
|
113 | + */ |
|
114 | + final public static function toFile($languages, $filename, $options = null) |
|
115 | + { |
|
116 | + $data = self::toString($languages, $options); |
|
117 | + if (@file_put_contents($filename, $data) === false) { |
|
118 | + throw new Exception("Error writing data to '{$filename}'"); |
|
119 | + } |
|
120 | + } |
|
121 | 121 | |
122 | - /** |
|
123 | - * Is this exporter for public use? |
|
124 | - * |
|
125 | - * @return bool |
|
126 | - */ |
|
127 | - public static function isForPublicUse() |
|
128 | - { |
|
129 | - return true; |
|
130 | - } |
|
122 | + /** |
|
123 | + * Is this exporter for public use? |
|
124 | + * |
|
125 | + * @return bool |
|
126 | + */ |
|
127 | + public static function isForPublicUse() |
|
128 | + { |
|
129 | + return true; |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * Return a short description of the exporter. |
|
134 | - * |
|
135 | - * @return string |
|
136 | - */ |
|
137 | - public static function getDescription() |
|
138 | - { |
|
139 | - throw new Exception(get_called_class() . ' does not implement the method ' . __FUNCTION__); |
|
140 | - } |
|
132 | + /** |
|
133 | + * Return a short description of the exporter. |
|
134 | + * |
|
135 | + * @return string |
|
136 | + */ |
|
137 | + public static function getDescription() |
|
138 | + { |
|
139 | + throw new Exception(get_called_class() . ' does not implement the method ' . __FUNCTION__); |
|
140 | + } |
|
141 | 141 | |
142 | - /** |
|
143 | - * Convert a list of Language instances to string. |
|
144 | - * |
|
145 | - * @param \Gettext\Languages\Language[] $languages the Language instances to convert |
|
146 | - * |
|
147 | - * @return string |
|
148 | - */ |
|
149 | - protected static function toStringDo($languages) |
|
150 | - { |
|
151 | - throw new Exception(get_called_class() . ' does not implement the method ' . __FUNCTION__); |
|
152 | - } |
|
142 | + /** |
|
143 | + * Convert a list of Language instances to string. |
|
144 | + * |
|
145 | + * @param \Gettext\Languages\Language[] $languages the Language instances to convert |
|
146 | + * |
|
147 | + * @return string |
|
148 | + */ |
|
149 | + protected static function toStringDo($languages) |
|
150 | + { |
|
151 | + throw new Exception(get_called_class() . ' does not implement the method ' . __FUNCTION__); |
|
152 | + } |
|
153 | 153 | } |
@@ -21,25 +21,25 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @return string[] |
23 | 23 | */ |
24 | - final public static function getExporters($onlyForPublicUse = false) |
|
24 | + final public static function getExporters( $onlyForPublicUse = false ) |
|
25 | 25 | { |
26 | - if (!isset(self::$exporters)) { |
|
26 | + if ( ! isset( self::$exporters ) ) { |
|
27 | 27 | $exporters = array(); |
28 | 28 | $m = null; |
29 | - foreach (scandir(__DIR__) as $f) { |
|
30 | - if (preg_match('/^(\w+)\.php$/', $f, $m)) { |
|
31 | - if ($f !== basename(__FILE__)) { |
|
32 | - $exporters[strtolower($m[1])] = $m[1]; |
|
29 | + foreach ( scandir( __DIR__ ) as $f ) { |
|
30 | + if ( preg_match( '/^(\w+)\.php$/', $f, $m ) ) { |
|
31 | + if ( $f !== basename( __FILE__ ) ) { |
|
32 | + $exporters[ strtolower( $m[ 1 ] ) ] = $m[ 1 ]; |
|
33 | 33 | } |
34 | 34 | } |
35 | 35 | } |
36 | 36 | self::$exporters = $exporters; |
37 | 37 | } |
38 | - if ($onlyForPublicUse) { |
|
38 | + if ( $onlyForPublicUse ) { |
|
39 | 39 | $result = array(); |
40 | - foreach (self::$exporters as $handle => $class) { |
|
41 | - if (call_user_func(self::getExporterClassName($handle) . '::isForPublicUse') === true) { |
|
42 | - $result[$handle] = $class; |
|
40 | + foreach ( self::$exporters as $handle => $class ) { |
|
41 | + if ( call_user_func( self::getExporterClassName( $handle ) . '::isForPublicUse' ) === true ) { |
|
42 | + $result[ $handle ] = $class; |
|
43 | 43 | } |
44 | 44 | } |
45 | 45 | } else { |
@@ -58,14 +58,14 @@ discard block |
||
58 | 58 | * |
59 | 59 | * @return string |
60 | 60 | */ |
61 | - final public static function getExporterDescription($exporterHandle) |
|
61 | + final public static function getExporterDescription( $exporterHandle ) |
|
62 | 62 | { |
63 | 63 | $exporters = self::getExporters(); |
64 | - if (!isset($exporters[$exporterHandle])) { |
|
65 | - throw new Exception("Invalid exporter handle: '{$exporterHandle}'"); |
|
64 | + if ( ! isset( $exporters[ $exporterHandle ] ) ) { |
|
65 | + throw new Exception( "Invalid exporter handle: '{$exporterHandle}'" ); |
|
66 | 66 | } |
67 | 67 | |
68 | - return call_user_func(self::getExporterClassName($exporterHandle) . '::getDescription'); |
|
68 | + return call_user_func( self::getExporterClassName( $exporterHandle ) . '::getDescription' ); |
|
69 | 69 | } |
70 | 70 | |
71 | 71 | /** |
@@ -75,9 +75,9 @@ discard block |
||
75 | 75 | * |
76 | 76 | * @return string |
77 | 77 | */ |
78 | - final public static function getExporterClassName($exporterHandle) |
|
78 | + final public static function getExporterClassName( $exporterHandle ) |
|
79 | 79 | { |
80 | - return __NAMESPACE__ . '\\' . ucfirst(strtolower($exporterHandle)); |
|
80 | + return __NAMESPACE__ . '\\' . ucfirst( strtolower( $exporterHandle ) ); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | /** |
@@ -88,19 +88,19 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @return string |
90 | 90 | */ |
91 | - final public static function toString($languages, $options = null) |
|
91 | + final public static function toString( $languages, $options = null ) |
|
92 | 92 | { |
93 | - if (isset($options) && is_array($options)) { |
|
94 | - if (isset($options['us-ascii']) && $options['us-ascii']) { |
|
93 | + if ( isset( $options ) && is_array( $options ) ) { |
|
94 | + if ( isset( $options[ 'us-ascii' ] ) && $options[ 'us-ascii' ] ) { |
|
95 | 95 | $asciiList = array(); |
96 | - foreach ($languages as $language) { |
|
97 | - $asciiList[] = $language->getUSAsciiClone(); |
|
96 | + foreach ( $languages as $language ) { |
|
97 | + $asciiList[ ] = $language->getUSAsciiClone(); |
|
98 | 98 | } |
99 | 99 | $languages = $asciiList; |
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
103 | - return static::toStringDo($languages); |
|
103 | + return static::toStringDo( $languages ); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | /** |
@@ -111,11 +111,11 @@ discard block |
||
111 | 111 | * |
112 | 112 | * @throws \Exception |
113 | 113 | */ |
114 | - final public static function toFile($languages, $filename, $options = null) |
|
114 | + final public static function toFile( $languages, $filename, $options = null ) |
|
115 | 115 | { |
116 | - $data = self::toString($languages, $options); |
|
117 | - if (@file_put_contents($filename, $data) === false) { |
|
118 | - throw new Exception("Error writing data to '{$filename}'"); |
|
116 | + $data = self::toString( $languages, $options ); |
|
117 | + if ( @file_put_contents( $filename, $data ) === false ) { |
|
118 | + throw new Exception( "Error writing data to '{$filename}'" ); |
|
119 | 119 | } |
120 | 120 | } |
121 | 121 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | */ |
137 | 137 | public static function getDescription() |
138 | 138 | { |
139 | - throw new Exception(get_called_class() . ' does not implement the method ' . __FUNCTION__); |
|
139 | + throw new Exception( get_called_class() . ' does not implement the method ' . __FUNCTION__ ); |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | /** |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | * |
147 | 147 | * @return string |
148 | 148 | */ |
149 | - protected static function toStringDo($languages) |
|
149 | + protected static function toStringDo( $languages ) |
|
150 | 150 | { |
151 | - throw new Exception(get_called_class() . ' does not implement the method ' . __FUNCTION__); |
|
151 | + throw new Exception( get_called_class() . ' does not implement the method ' . __FUNCTION__ ); |
|
152 | 152 | } |
153 | 153 | } |
@@ -7,8 +7,7 @@ discard block |
||
7 | 7 | /** |
8 | 8 | * Base class for all the exporters. |
9 | 9 | */ |
10 | -abstract class Exporter |
|
11 | -{ |
|
10 | +abstract class Exporter { |
|
12 | 11 | /** |
13 | 12 | * @var array |
14 | 13 | */ |
@@ -21,8 +20,7 @@ discard block |
||
21 | 20 | * |
22 | 21 | * @return string[] |
23 | 22 | */ |
24 | - final public static function getExporters($onlyForPublicUse = false) |
|
25 | - { |
|
23 | + final public static function getExporters($onlyForPublicUse = false) { |
|
26 | 24 | if (!isset(self::$exporters)) { |
27 | 25 | $exporters = array(); |
28 | 26 | $m = null; |
@@ -58,8 +56,7 @@ discard block |
||
58 | 56 | * |
59 | 57 | * @return string |
60 | 58 | */ |
61 | - final public static function getExporterDescription($exporterHandle) |
|
62 | - { |
|
59 | + final public static function getExporterDescription($exporterHandle) { |
|
63 | 60 | $exporters = self::getExporters(); |
64 | 61 | if (!isset($exporters[$exporterHandle])) { |
65 | 62 | throw new Exception("Invalid exporter handle: '{$exporterHandle}'"); |
@@ -75,8 +72,7 @@ discard block |
||
75 | 72 | * |
76 | 73 | * @return string |
77 | 74 | */ |
78 | - final public static function getExporterClassName($exporterHandle) |
|
79 | - { |
|
75 | + final public static function getExporterClassName($exporterHandle) { |
|
80 | 76 | return __NAMESPACE__ . '\\' . ucfirst(strtolower($exporterHandle)); |
81 | 77 | } |
82 | 78 | |
@@ -88,8 +84,7 @@ discard block |
||
88 | 84 | * |
89 | 85 | * @return string |
90 | 86 | */ |
91 | - final public static function toString($languages, $options = null) |
|
92 | - { |
|
87 | + final public static function toString($languages, $options = null) { |
|
93 | 88 | if (isset($options) && is_array($options)) { |
94 | 89 | if (isset($options['us-ascii']) && $options['us-ascii']) { |
95 | 90 | $asciiList = array(); |
@@ -111,8 +106,7 @@ discard block |
||
111 | 106 | * |
112 | 107 | * @throws \Exception |
113 | 108 | */ |
114 | - final public static function toFile($languages, $filename, $options = null) |
|
115 | - { |
|
109 | + final public static function toFile($languages, $filename, $options = null) { |
|
116 | 110 | $data = self::toString($languages, $options); |
117 | 111 | if (@file_put_contents($filename, $data) === false) { |
118 | 112 | throw new Exception("Error writing data to '{$filename}'"); |
@@ -124,8 +118,7 @@ discard block |
||
124 | 118 | * |
125 | 119 | * @return bool |
126 | 120 | */ |
127 | - public static function isForPublicUse() |
|
128 | - { |
|
121 | + public static function isForPublicUse() { |
|
129 | 122 | return true; |
130 | 123 | } |
131 | 124 | |
@@ -134,8 +127,7 @@ discard block |
||
134 | 127 | * |
135 | 128 | * @return string |
136 | 129 | */ |
137 | - public static function getDescription() |
|
138 | - { |
|
130 | + public static function getDescription() { |
|
139 | 131 | throw new Exception(get_called_class() . ' does not implement the method ' . __FUNCTION__); |
140 | 132 | } |
141 | 133 | |
@@ -146,8 +138,7 @@ discard block |
||
146 | 138 | * |
147 | 139 | * @return string |
148 | 140 | */ |
149 | - protected static function toStringDo($languages) |
|
150 | - { |
|
141 | + protected static function toStringDo($languages) { |
|
151 | 142 | throw new Exception(get_called_class() . ' does not implement the method ' . __FUNCTION__); |
152 | 143 | } |
153 | 144 | } |
@@ -4,66 +4,66 @@ |
||
4 | 4 | |
5 | 5 | class Html 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 HTML table'; |
|
15 | - } |
|
7 | + /** |
|
8 | + * {@inheritdoc} |
|
9 | + * |
|
10 | + * @see \Gettext\Languages\Exporter\Exporter::getDescription() |
|
11 | + */ |
|
12 | + public static function getDescription() |
|
13 | + { |
|
14 | + return 'Build a HTML table'; |
|
15 | + } |
|
16 | 16 | |
17 | - /** |
|
18 | - * {@inheritdoc} |
|
19 | - * |
|
20 | - * @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
|
21 | - */ |
|
22 | - protected static function toStringDo($languages) |
|
23 | - { |
|
24 | - return self::buildTable($languages, false); |
|
25 | - } |
|
17 | + /** |
|
18 | + * {@inheritdoc} |
|
19 | + * |
|
20 | + * @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
|
21 | + */ |
|
22 | + protected static function toStringDo($languages) |
|
23 | + { |
|
24 | + return self::buildTable($languages, false); |
|
25 | + } |
|
26 | 26 | |
27 | - protected static function h($str) |
|
28 | - { |
|
29 | - return htmlspecialchars($str, ENT_COMPAT, 'UTF-8'); |
|
30 | - } |
|
27 | + protected static function h($str) |
|
28 | + { |
|
29 | + return htmlspecialchars($str, ENT_COMPAT, 'UTF-8'); |
|
30 | + } |
|
31 | 31 | |
32 | - protected static function buildTable($languages, $forDocs) |
|
33 | - { |
|
34 | - $prefix = $forDocs ? ' ' : ''; |
|
35 | - $lines = array(); |
|
36 | - $lines[] = $prefix . '<table' . ($forDocs ? ' class="table table-bordered table-condensed table-striped"' : '') . '>'; |
|
37 | - $lines[] = $prefix . ' <thead>'; |
|
38 | - $lines[] = $prefix . ' <tr>'; |
|
39 | - $lines[] = $prefix . ' <th>Language code</th>'; |
|
40 | - $lines[] = $prefix . ' <th>Language name</th>'; |
|
41 | - $lines[] = $prefix . ' <th># plurals</th>'; |
|
42 | - $lines[] = $prefix . ' <th>Formula</th>'; |
|
43 | - $lines[] = $prefix . ' <th>Plurals</th>'; |
|
44 | - $lines[] = $prefix . ' </tr>'; |
|
45 | - $lines[] = $prefix . ' </thead>'; |
|
46 | - $lines[] = $prefix . ' <tbody>'; |
|
47 | - foreach ($languages as $lc) { |
|
48 | - $lines[] = $prefix . ' <tr>'; |
|
49 | - $lines[] = $prefix . ' <td>' . $lc->id . '</td>'; |
|
50 | - $name = self::h($lc->name); |
|
51 | - if (isset($lc->supersededBy)) { |
|
52 | - $name .= '<br /><small><span>Superseded by</span> ' . $lc->supersededBy . '</small>'; |
|
53 | - } |
|
54 | - $lines[] = $prefix . ' <td>' . $name . '</td>'; |
|
55 | - $lines[] = $prefix . ' <td>' . count($lc->categories) . '</td>'; |
|
56 | - $lines[] = $prefix . ' <td>' . self::h($lc->formula) . '</td>'; |
|
57 | - $cases = array(); |
|
58 | - foreach ($lc->categories as $c) { |
|
59 | - $cases[] = '<li><span>' . $c->id . '</span><code>' . self::h($c->examples) . '</code></li>'; |
|
60 | - } |
|
61 | - $lines[] = $prefix . ' <td><ol' . ($forDocs ? ' class="cases"' : '') . ' start="0">' . implode('', $cases) . '</ol></td>'; |
|
62 | - $lines[] = $prefix . ' </tr>'; |
|
63 | - } |
|
64 | - $lines[] = $prefix . ' </tbody>'; |
|
65 | - $lines[] = $prefix . '</table>'; |
|
32 | + protected static function buildTable($languages, $forDocs) |
|
33 | + { |
|
34 | + $prefix = $forDocs ? ' ' : ''; |
|
35 | + $lines = array(); |
|
36 | + $lines[] = $prefix . '<table' . ($forDocs ? ' class="table table-bordered table-condensed table-striped"' : '') . '>'; |
|
37 | + $lines[] = $prefix . ' <thead>'; |
|
38 | + $lines[] = $prefix . ' <tr>'; |
|
39 | + $lines[] = $prefix . ' <th>Language code</th>'; |
|
40 | + $lines[] = $prefix . ' <th>Language name</th>'; |
|
41 | + $lines[] = $prefix . ' <th># plurals</th>'; |
|
42 | + $lines[] = $prefix . ' <th>Formula</th>'; |
|
43 | + $lines[] = $prefix . ' <th>Plurals</th>'; |
|
44 | + $lines[] = $prefix . ' </tr>'; |
|
45 | + $lines[] = $prefix . ' </thead>'; |
|
46 | + $lines[] = $prefix . ' <tbody>'; |
|
47 | + foreach ($languages as $lc) { |
|
48 | + $lines[] = $prefix . ' <tr>'; |
|
49 | + $lines[] = $prefix . ' <td>' . $lc->id . '</td>'; |
|
50 | + $name = self::h($lc->name); |
|
51 | + if (isset($lc->supersededBy)) { |
|
52 | + $name .= '<br /><small><span>Superseded by</span> ' . $lc->supersededBy . '</small>'; |
|
53 | + } |
|
54 | + $lines[] = $prefix . ' <td>' . $name . '</td>'; |
|
55 | + $lines[] = $prefix . ' <td>' . count($lc->categories) . '</td>'; |
|
56 | + $lines[] = $prefix . ' <td>' . self::h($lc->formula) . '</td>'; |
|
57 | + $cases = array(); |
|
58 | + foreach ($lc->categories as $c) { |
|
59 | + $cases[] = '<li><span>' . $c->id . '</span><code>' . self::h($c->examples) . '</code></li>'; |
|
60 | + } |
|
61 | + $lines[] = $prefix . ' <td><ol' . ($forDocs ? ' class="cases"' : '') . ' start="0">' . implode('', $cases) . '</ol></td>'; |
|
62 | + $lines[] = $prefix . ' </tr>'; |
|
63 | + } |
|
64 | + $lines[] = $prefix . ' </tbody>'; |
|
65 | + $lines[] = $prefix . '</table>'; |
|
66 | 66 | |
67 | - return implode("\n", $lines); |
|
68 | - } |
|
67 | + return implode("\n", $lines); |
|
68 | + } |
|
69 | 69 | } |
@@ -19,51 +19,51 @@ |
||
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 | - return self::buildTable($languages, false); |
|
24 | + return self::buildTable( $languages, false ); |
|
25 | 25 | } |
26 | 26 | |
27 | - protected static function h($str) |
|
27 | + protected static function h( $str ) |
|
28 | 28 | { |
29 | - return htmlspecialchars($str, ENT_COMPAT, 'UTF-8'); |
|
29 | + return htmlspecialchars( $str, ENT_COMPAT, 'UTF-8' ); |
|
30 | 30 | } |
31 | 31 | |
32 | - protected static function buildTable($languages, $forDocs) |
|
32 | + protected static function buildTable( $languages, $forDocs ) |
|
33 | 33 | { |
34 | 34 | $prefix = $forDocs ? ' ' : ''; |
35 | 35 | $lines = array(); |
36 | - $lines[] = $prefix . '<table' . ($forDocs ? ' class="table table-bordered table-condensed table-striped"' : '') . '>'; |
|
37 | - $lines[] = $prefix . ' <thead>'; |
|
38 | - $lines[] = $prefix . ' <tr>'; |
|
39 | - $lines[] = $prefix . ' <th>Language code</th>'; |
|
40 | - $lines[] = $prefix . ' <th>Language name</th>'; |
|
41 | - $lines[] = $prefix . ' <th># plurals</th>'; |
|
42 | - $lines[] = $prefix . ' <th>Formula</th>'; |
|
43 | - $lines[] = $prefix . ' <th>Plurals</th>'; |
|
44 | - $lines[] = $prefix . ' </tr>'; |
|
45 | - $lines[] = $prefix . ' </thead>'; |
|
46 | - $lines[] = $prefix . ' <tbody>'; |
|
47 | - foreach ($languages as $lc) { |
|
48 | - $lines[] = $prefix . ' <tr>'; |
|
49 | - $lines[] = $prefix . ' <td>' . $lc->id . '</td>'; |
|
50 | - $name = self::h($lc->name); |
|
51 | - if (isset($lc->supersededBy)) { |
|
36 | + $lines[ ] = $prefix . '<table' . ( $forDocs ? ' class="table table-bordered table-condensed table-striped"' : '' ) . '>'; |
|
37 | + $lines[ ] = $prefix . ' <thead>'; |
|
38 | + $lines[ ] = $prefix . ' <tr>'; |
|
39 | + $lines[ ] = $prefix . ' <th>Language code</th>'; |
|
40 | + $lines[ ] = $prefix . ' <th>Language name</th>'; |
|
41 | + $lines[ ] = $prefix . ' <th># plurals</th>'; |
|
42 | + $lines[ ] = $prefix . ' <th>Formula</th>'; |
|
43 | + $lines[ ] = $prefix . ' <th>Plurals</th>'; |
|
44 | + $lines[ ] = $prefix . ' </tr>'; |
|
45 | + $lines[ ] = $prefix . ' </thead>'; |
|
46 | + $lines[ ] = $prefix . ' <tbody>'; |
|
47 | + foreach ( $languages as $lc ) { |
|
48 | + $lines[ ] = $prefix . ' <tr>'; |
|
49 | + $lines[ ] = $prefix . ' <td>' . $lc->id . '</td>'; |
|
50 | + $name = self::h( $lc->name ); |
|
51 | + if ( isset( $lc->supersededBy ) ) { |
|
52 | 52 | $name .= '<br /><small><span>Superseded by</span> ' . $lc->supersededBy . '</small>'; |
53 | 53 | } |
54 | - $lines[] = $prefix . ' <td>' . $name . '</td>'; |
|
55 | - $lines[] = $prefix . ' <td>' . count($lc->categories) . '</td>'; |
|
56 | - $lines[] = $prefix . ' <td>' . self::h($lc->formula) . '</td>'; |
|
54 | + $lines[ ] = $prefix . ' <td>' . $name . '</td>'; |
|
55 | + $lines[ ] = $prefix . ' <td>' . count( $lc->categories ) . '</td>'; |
|
56 | + $lines[ ] = $prefix . ' <td>' . self::h( $lc->formula ) . '</td>'; |
|
57 | 57 | $cases = array(); |
58 | - foreach ($lc->categories as $c) { |
|
59 | - $cases[] = '<li><span>' . $c->id . '</span><code>' . self::h($c->examples) . '</code></li>'; |
|
58 | + foreach ( $lc->categories as $c ) { |
|
59 | + $cases[ ] = '<li><span>' . $c->id . '</span><code>' . self::h( $c->examples ) . '</code></li>'; |
|
60 | 60 | } |
61 | - $lines[] = $prefix . ' <td><ol' . ($forDocs ? ' class="cases"' : '') . ' start="0">' . implode('', $cases) . '</ol></td>'; |
|
62 | - $lines[] = $prefix . ' </tr>'; |
|
61 | + $lines[ ] = $prefix . ' <td><ol' . ( $forDocs ? ' class="cases"' : '' ) . ' start="0">' . implode( '', $cases ) . '</ol></td>'; |
|
62 | + $lines[ ] = $prefix . ' </tr>'; |
|
63 | 63 | } |
64 | - $lines[] = $prefix . ' </tbody>'; |
|
65 | - $lines[] = $prefix . '</table>'; |
|
64 | + $lines[ ] = $prefix . ' </tbody>'; |
|
65 | + $lines[ ] = $prefix . '</table>'; |
|
66 | 66 | |
67 | - return implode("\n", $lines); |
|
67 | + return implode( "\n", $lines ); |
|
68 | 68 | } |
69 | 69 | } |
@@ -2,15 +2,13 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace Gettext\Languages\Exporter; |
4 | 4 | |
5 | -class Html extends Exporter |
|
6 | -{ |
|
5 | +class Html 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 HTML table'; |
15 | 13 | } |
16 | 14 | |
@@ -19,18 +17,15 @@ 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 | return self::buildTable($languages, false); |
25 | 22 | } |
26 | 23 | |
27 | - protected static function h($str) |
|
28 | - { |
|
24 | + protected static function h($str) { |
|
29 | 25 | return htmlspecialchars($str, ENT_COMPAT, 'UTF-8'); |
30 | 26 | } |
31 | 27 | |
32 | - protected static function buildTable($languages, $forDocs) |
|
33 | - { |
|
28 | + protected static function buildTable($languages, $forDocs) { |
|
34 | 29 | $prefix = $forDocs ? ' ' : ''; |
35 | 30 | $lines = array(); |
36 | 31 | $lines[] = $prefix . '<table' . ($forDocs ? ' class="table table-bordered table-condensed table-striped"' : '') . '>'; |
@@ -4,57 +4,57 @@ |
||
4 | 4 | |
5 | 5 | class Xml 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 an XML file - schema available at http://mlocati.github.io/cldr-to-gettext-plural-rules/GettextLanguages.xsd'; |
|
15 | - } |
|
7 | + /** |
|
8 | + * {@inheritdoc} |
|
9 | + * |
|
10 | + * @see \Gettext\Languages\Exporter\Exporter::getDescription() |
|
11 | + */ |
|
12 | + public static function getDescription() |
|
13 | + { |
|
14 | + return 'Build an XML file - schema available at http://mlocati.github.io/cldr-to-gettext-plural-rules/GettextLanguages.xsd'; |
|
15 | + } |
|
16 | 16 | |
17 | - /** |
|
18 | - * {@inheritdoc} |
|
19 | - * |
|
20 | - * @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
|
21 | - */ |
|
22 | - protected static function toStringDo($languages) |
|
23 | - { |
|
24 | - $xml = new \DOMDocument('1.0', 'UTF-8'); |
|
25 | - $xml->loadXML('<languages |
|
17 | + /** |
|
18 | + * {@inheritdoc} |
|
19 | + * |
|
20 | + * @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
|
21 | + */ |
|
22 | + protected static function toStringDo($languages) |
|
23 | + { |
|
24 | + $xml = new \DOMDocument('1.0', 'UTF-8'); |
|
25 | + $xml->loadXML('<languages |
|
26 | 26 | xmlns="https://github.com/mlocati/cldr-to-gettext-plural-rules" |
27 | 27 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
28 | 28 | xsi:schemaLocation="https://github.com/mlocati/cldr-to-gettext-plural-rules http://mlocati.github.io/cldr-to-gettext-plural-rules/GettextLanguages.xsd" |
29 | 29 | />'); |
30 | - $xLanguages = $xml->firstChild; |
|
31 | - foreach ($languages as $language) { |
|
32 | - $xLanguage = $xml->createElement('language'); |
|
33 | - $xLanguage->setAttribute('id', $language->id); |
|
34 | - $xLanguage->setAttribute('name', $language->name); |
|
35 | - if (isset($language->supersededBy)) { |
|
36 | - $xLanguage->setAttribute('supersededBy', $language->supersededBy); |
|
37 | - } |
|
38 | - if (isset($language->script)) { |
|
39 | - $xLanguage->setAttribute('script', $language->script); |
|
40 | - } |
|
41 | - if (isset($language->territory)) { |
|
42 | - $xLanguage->setAttribute('territory', $language->territory); |
|
43 | - } |
|
44 | - if (isset($language->baseLanguage)) { |
|
45 | - $xLanguage->setAttribute('baseLanguage', $language->baseLanguage); |
|
46 | - } |
|
47 | - $xLanguage->setAttribute('formula', $language->formula); |
|
48 | - foreach ($language->categories as $category) { |
|
49 | - $xCategory = $xml->createElement('category'); |
|
50 | - $xCategory->setAttribute('id', $category->id); |
|
51 | - $xCategory->setAttribute('examples', $category->examples); |
|
52 | - $xLanguage->appendChild($xCategory); |
|
53 | - } |
|
54 | - $xLanguages->appendChild($xLanguage); |
|
55 | - } |
|
56 | - $xml->formatOutput = true; |
|
30 | + $xLanguages = $xml->firstChild; |
|
31 | + foreach ($languages as $language) { |
|
32 | + $xLanguage = $xml->createElement('language'); |
|
33 | + $xLanguage->setAttribute('id', $language->id); |
|
34 | + $xLanguage->setAttribute('name', $language->name); |
|
35 | + if (isset($language->supersededBy)) { |
|
36 | + $xLanguage->setAttribute('supersededBy', $language->supersededBy); |
|
37 | + } |
|
38 | + if (isset($language->script)) { |
|
39 | + $xLanguage->setAttribute('script', $language->script); |
|
40 | + } |
|
41 | + if (isset($language->territory)) { |
|
42 | + $xLanguage->setAttribute('territory', $language->territory); |
|
43 | + } |
|
44 | + if (isset($language->baseLanguage)) { |
|
45 | + $xLanguage->setAttribute('baseLanguage', $language->baseLanguage); |
|
46 | + } |
|
47 | + $xLanguage->setAttribute('formula', $language->formula); |
|
48 | + foreach ($language->categories as $category) { |
|
49 | + $xCategory = $xml->createElement('category'); |
|
50 | + $xCategory->setAttribute('id', $category->id); |
|
51 | + $xCategory->setAttribute('examples', $category->examples); |
|
52 | + $xLanguage->appendChild($xCategory); |
|
53 | + } |
|
54 | + $xLanguages->appendChild($xLanguage); |
|
55 | + } |
|
56 | + $xml->formatOutput = true; |
|
57 | 57 | |
58 | - return $xml->saveXML(); |
|
59 | - } |
|
58 | + return $xml->saveXML(); |
|
59 | + } |
|
60 | 60 | } |
@@ -19,39 +19,39 @@ |
||
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 | - $xml = new \DOMDocument('1.0', 'UTF-8'); |
|
25 | - $xml->loadXML('<languages |
|
24 | + $xml = new \DOMDocument( '1.0', 'UTF-8' ); |
|
25 | + $xml->loadXML( '<languages |
|
26 | 26 | xmlns="https://github.com/mlocati/cldr-to-gettext-plural-rules" |
27 | 27 | xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
28 | 28 | xsi:schemaLocation="https://github.com/mlocati/cldr-to-gettext-plural-rules http://mlocati.github.io/cldr-to-gettext-plural-rules/GettextLanguages.xsd" |
29 | 29 | />'); |
30 | 30 | $xLanguages = $xml->firstChild; |
31 | - foreach ($languages as $language) { |
|
32 | - $xLanguage = $xml->createElement('language'); |
|
33 | - $xLanguage->setAttribute('id', $language->id); |
|
34 | - $xLanguage->setAttribute('name', $language->name); |
|
35 | - if (isset($language->supersededBy)) { |
|
36 | - $xLanguage->setAttribute('supersededBy', $language->supersededBy); |
|
31 | + foreach ( $languages as $language ) { |
|
32 | + $xLanguage = $xml->createElement( 'language' ); |
|
33 | + $xLanguage->setAttribute( 'id', $language->id ); |
|
34 | + $xLanguage->setAttribute( 'name', $language->name ); |
|
35 | + if ( isset( $language->supersededBy ) ) { |
|
36 | + $xLanguage->setAttribute( 'supersededBy', $language->supersededBy ); |
|
37 | 37 | } |
38 | - if (isset($language->script)) { |
|
39 | - $xLanguage->setAttribute('script', $language->script); |
|
38 | + if ( isset( $language->script ) ) { |
|
39 | + $xLanguage->setAttribute( 'script', $language->script ); |
|
40 | 40 | } |
41 | - if (isset($language->territory)) { |
|
42 | - $xLanguage->setAttribute('territory', $language->territory); |
|
41 | + if ( isset( $language->territory ) ) { |
|
42 | + $xLanguage->setAttribute( 'territory', $language->territory ); |
|
43 | 43 | } |
44 | - if (isset($language->baseLanguage)) { |
|
45 | - $xLanguage->setAttribute('baseLanguage', $language->baseLanguage); |
|
44 | + if ( isset( $language->baseLanguage ) ) { |
|
45 | + $xLanguage->setAttribute( 'baseLanguage', $language->baseLanguage ); |
|
46 | 46 | } |
47 | - $xLanguage->setAttribute('formula', $language->formula); |
|
48 | - foreach ($language->categories as $category) { |
|
49 | - $xCategory = $xml->createElement('category'); |
|
50 | - $xCategory->setAttribute('id', $category->id); |
|
51 | - $xCategory->setAttribute('examples', $category->examples); |
|
52 | - $xLanguage->appendChild($xCategory); |
|
47 | + $xLanguage->setAttribute( 'formula', $language->formula ); |
|
48 | + foreach ( $language->categories as $category ) { |
|
49 | + $xCategory = $xml->createElement( 'category' ); |
|
50 | + $xCategory->setAttribute( 'id', $category->id ); |
|
51 | + $xCategory->setAttribute( 'examples', $category->examples ); |
|
52 | + $xLanguage->appendChild( $xCategory ); |
|
53 | 53 | } |
54 | - $xLanguages->appendChild($xLanguage); |
|
54 | + $xLanguages->appendChild( $xLanguage ); |
|
55 | 55 | } |
56 | 56 | $xml->formatOutput = true; |
57 | 57 |
@@ -2,15 +2,13 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace Gettext\Languages\Exporter; |
4 | 4 | |
5 | -class Xml extends Exporter |
|
6 | -{ |
|
5 | +class Xml 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 an XML file - schema available at http://mlocati.github.io/cldr-to-gettext-plural-rules/GettextLanguages.xsd'; |
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 | $xml = new \DOMDocument('1.0', 'UTF-8'); |
25 | 22 | $xml->loadXML('<languages |
26 | 23 | xmlns="https://github.com/mlocati/cldr-to-gettext-plural-rules" |
@@ -4,34 +4,34 @@ discard block |
||
4 | 4 | |
5 | 5 | class Docs extends Html |
6 | 6 | { |
7 | - /** |
|
8 | - * {@inheritdoc} |
|
9 | - * |
|
10 | - * @see \Gettext\Languages\Exporter\Exporter::isForPublicUse() |
|
11 | - */ |
|
12 | - public static function isForPublicUse() |
|
13 | - { |
|
14 | - return false; |
|
15 | - } |
|
7 | + /** |
|
8 | + * {@inheritdoc} |
|
9 | + * |
|
10 | + * @see \Gettext\Languages\Exporter\Exporter::isForPublicUse() |
|
11 | + */ |
|
12 | + public static function isForPublicUse() |
|
13 | + { |
|
14 | + return false; |
|
15 | + } |
|
16 | 16 | |
17 | - /** |
|
18 | - * {@inheritdoc} |
|
19 | - * |
|
20 | - * @see \Gettext\Languages\Exporter\Exporter::getDescription() |
|
21 | - */ |
|
22 | - public static function getDescription() |
|
23 | - { |
|
24 | - return 'Build the page https://php-gettext.github.io/Languages/'; |
|
25 | - } |
|
17 | + /** |
|
18 | + * {@inheritdoc} |
|
19 | + * |
|
20 | + * @see \Gettext\Languages\Exporter\Exporter::getDescription() |
|
21 | + */ |
|
22 | + public static function getDescription() |
|
23 | + { |
|
24 | + return 'Build the page https://php-gettext.github.io/Languages/'; |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * {@inheritdoc} |
|
29 | - * |
|
30 | - * @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
|
31 | - */ |
|
32 | - protected static function toStringDo($languages) |
|
33 | - { |
|
34 | - $result = <<<'EOT' |
|
27 | + /** |
|
28 | + * {@inheritdoc} |
|
29 | + * |
|
30 | + * @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
|
31 | + */ |
|
32 | + protected static function toStringDo($languages) |
|
33 | + { |
|
34 | + $result = <<<'EOT' |
|
35 | 35 | <!doctype html> |
36 | 36 | <html lang="en"> |
37 | 37 | <head> |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | <div class="container-fluid"> |
50 | 50 | |
51 | 51 | EOT; |
52 | - $result .= static::buildTable($languages, true); |
|
53 | - $result .= <<<'EOT' |
|
52 | + $result .= static::buildTable($languages, true); |
|
53 | + $result .= <<<'EOT' |
|
54 | 54 | |
55 | 55 | </div> |
56 | 56 | <script src="//code.jquery.com/jquery-1.11.2.min.js"></script> |
@@ -59,6 +59,6 @@ discard block |
||
59 | 59 | </html> |
60 | 60 | EOT; |
61 | 61 | |
62 | - return $result; |
|
63 | - } |
|
62 | + return $result; |
|
63 | + } |
|
64 | 64 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * |
30 | 30 | * @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
31 | 31 | */ |
32 | - protected static function toStringDo($languages) |
|
32 | + protected static function toStringDo( $languages ) |
|
33 | 33 | { |
34 | 34 | $result = <<<'EOT' |
35 | 35 | <!doctype html> |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | <div class="container-fluid"> |
50 | 50 | |
51 | 51 | EOT; |
52 | - $result .= static::buildTable($languages, true); |
|
52 | + $result .= static::buildTable( $languages, true ); |
|
53 | 53 | $result .= <<<'EOT' |
54 | 54 | |
55 | 55 | </div> |
@@ -2,15 +2,13 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace Gettext\Languages\Exporter; |
4 | 4 | |
5 | -class Docs extends Html |
|
6 | -{ |
|
5 | +class Docs extends Html { |
|
7 | 6 | /** |
8 | 7 | * {@inheritdoc} |
9 | 8 | * |
10 | 9 | * @see \Gettext\Languages\Exporter\Exporter::isForPublicUse() |
11 | 10 | */ |
12 | - public static function isForPublicUse() |
|
13 | - { |
|
11 | + public static function isForPublicUse() { |
|
14 | 12 | return false; |
15 | 13 | } |
16 | 14 | |
@@ -19,8 +17,7 @@ discard block |
||
19 | 17 | * |
20 | 18 | * @see \Gettext\Languages\Exporter\Exporter::getDescription() |
21 | 19 | */ |
22 | - public static function getDescription() |
|
23 | - { |
|
20 | + public static function getDescription() { |
|
24 | 21 | return 'Build the page https://php-gettext.github.io/Languages/'; |
25 | 22 | } |
26 | 23 | |
@@ -29,8 +26,7 @@ discard block |
||
29 | 26 | * |
30 | 27 | * @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
31 | 28 | */ |
32 | - protected static function toStringDo($languages) |
|
33 | - { |
|
29 | + protected static function toStringDo($languages) { |
|
34 | 30 | $result = <<<'EOT' |
35 | 31 | <!doctype html> |
36 | 32 | <html lang="en"> |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | <a href="https://github.com/php-gettext/Languages" class="hidden-xs"><img style="position: fixed; top: 0; right: 0; border: 0; z-index: 2000" src="https://s3.amazonaws.com/github/ribbons/forkme_right_red_aa0000.png" alt="Fork me on GitHub"></a> |
49 | 49 | <div class="container-fluid"> |
50 | 50 | |
51 | -EOT; |
|
51 | +eot; |
|
52 | 52 | $result .= static::buildTable($languages, true); |
53 | 53 | $result .= <<<'EOT' |
54 | 54 | |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | <script src="script.js"></script> |
58 | 58 | </body> |
59 | 59 | </html> |
60 | -EOT; |
|
60 | +eot; |
|
61 | 61 | |
62 | 62 | return $result; |
63 | 63 | } |
@@ -6,32 +6,32 @@ |
||
6 | 6 | |
7 | 7 | class Po extends Exporter |
8 | 8 | { |
9 | - /** |
|
10 | - * {@inheritdoc} |
|
11 | - * |
|
12 | - * @see \Gettext\Languages\Exporter\Exporter::getDescription() |
|
13 | - */ |
|
14 | - public static function getDescription() |
|
15 | - { |
|
16 | - return 'Build a string to be used for gettext .po files'; |
|
17 | - } |
|
9 | + /** |
|
10 | + * {@inheritdoc} |
|
11 | + * |
|
12 | + * @see \Gettext\Languages\Exporter\Exporter::getDescription() |
|
13 | + */ |
|
14 | + public static function getDescription() |
|
15 | + { |
|
16 | + return 'Build a string to be used for gettext .po files'; |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * {@inheritdoc} |
|
21 | - * |
|
22 | - * @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
|
23 | - */ |
|
24 | - protected static function toStringDo($languages) |
|
25 | - { |
|
26 | - if (count($languages) !== 1) { |
|
27 | - throw new Exception('The ' . get_called_class() . ' exporter can only export one language'); |
|
28 | - } |
|
29 | - $language = $languages[0]; |
|
30 | - $lines = array(); |
|
31 | - $lines[] = '"Language: ' . $language->id . '\n"'; |
|
32 | - $lines[] = '"Plural-Forms: nplurals=' . count($language->categories) . '; plural=' . $language->formula . '\n"'; |
|
33 | - $lines[] = ''; |
|
19 | + /** |
|
20 | + * {@inheritdoc} |
|
21 | + * |
|
22 | + * @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
|
23 | + */ |
|
24 | + protected static function toStringDo($languages) |
|
25 | + { |
|
26 | + if (count($languages) !== 1) { |
|
27 | + throw new Exception('The ' . get_called_class() . ' exporter can only export one language'); |
|
28 | + } |
|
29 | + $language = $languages[0]; |
|
30 | + $lines = array(); |
|
31 | + $lines[] = '"Language: ' . $language->id . '\n"'; |
|
32 | + $lines[] = '"Plural-Forms: nplurals=' . count($language->categories) . '; plural=' . $language->formula . '\n"'; |
|
33 | + $lines[] = ''; |
|
34 | 34 | |
35 | - return implode("\n", $lines); |
|
36 | - } |
|
35 | + return implode("\n", $lines); |
|
36 | + } |
|
37 | 37 | } |
@@ -21,17 +21,17 @@ |
||
21 | 21 | * |
22 | 22 | * @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
23 | 23 | */ |
24 | - protected static function toStringDo($languages) |
|
24 | + protected static function toStringDo( $languages ) |
|
25 | 25 | { |
26 | - if (count($languages) !== 1) { |
|
27 | - throw new Exception('The ' . get_called_class() . ' exporter can only export one language'); |
|
26 | + if ( count( $languages ) !== 1 ) { |
|
27 | + throw new Exception( 'The ' . get_called_class() . ' exporter can only export one language' ); |
|
28 | 28 | } |
29 | - $language = $languages[0]; |
|
29 | + $language = $languages[ 0 ]; |
|
30 | 30 | $lines = array(); |
31 | - $lines[] = '"Language: ' . $language->id . '\n"'; |
|
32 | - $lines[] = '"Plural-Forms: nplurals=' . count($language->categories) . '; plural=' . $language->formula . '\n"'; |
|
33 | - $lines[] = ''; |
|
31 | + $lines[ ] = '"Language: ' . $language->id . '\n"'; |
|
32 | + $lines[ ] = '"Plural-Forms: nplurals=' . count( $language->categories ) . '; plural=' . $language->formula . '\n"'; |
|
33 | + $lines[ ] = ''; |
|
34 | 34 | |
35 | - return implode("\n", $lines); |
|
35 | + return implode( "\n", $lines ); |
|
36 | 36 | } |
37 | 37 | } |
@@ -4,15 +4,13 @@ discard block |
||
4 | 4 | |
5 | 5 | use Exception; |
6 | 6 | |
7 | -class Po extends Exporter |
|
8 | -{ |
|
7 | +class Po extends Exporter { |
|
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 a string to be used for gettext .po files'; |
17 | 15 | } |
18 | 16 | |
@@ -21,8 +19,7 @@ discard block |
||
21 | 19 | * |
22 | 20 | * @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
23 | 21 | */ |
24 | - protected static function toStringDo($languages) |
|
25 | - { |
|
22 | + protected static function toStringDo($languages) { |
|
26 | 23 | if (count($languages) !== 1) { |
27 | 24 | throw new Exception('The ' . get_called_class() . ' exporter can only export one language'); |
28 | 25 | } |
@@ -4,68 +4,68 @@ |
||
4 | 4 | |
5 | 5 | class Json 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 compressed JSON-encoded file'; |
|
15 | - } |
|
7 | + /** |
|
8 | + * {@inheritdoc} |
|
9 | + * |
|
10 | + * @see \Gettext\Languages\Exporter\Exporter::getDescription() |
|
11 | + */ |
|
12 | + public static function getDescription() |
|
13 | + { |
|
14 | + return 'Build a compressed JSON-encoded file'; |
|
15 | + } |
|
16 | 16 | |
17 | - /** |
|
18 | - * Return the options for json_encode. |
|
19 | - * |
|
20 | - * @return int |
|
21 | - */ |
|
22 | - protected static function getEncodeOptions() |
|
23 | - { |
|
24 | - $result = 0; |
|
25 | - if (defined('\JSON_UNESCAPED_SLASHES')) { |
|
26 | - $result |= \JSON_UNESCAPED_SLASHES; |
|
27 | - } |
|
28 | - if (defined('\JSON_UNESCAPED_UNICODE')) { |
|
29 | - $result |= \JSON_UNESCAPED_UNICODE; |
|
30 | - } |
|
17 | + /** |
|
18 | + * Return the options for json_encode. |
|
19 | + * |
|
20 | + * @return int |
|
21 | + */ |
|
22 | + protected static function getEncodeOptions() |
|
23 | + { |
|
24 | + $result = 0; |
|
25 | + if (defined('\JSON_UNESCAPED_SLASHES')) { |
|
26 | + $result |= \JSON_UNESCAPED_SLASHES; |
|
27 | + } |
|
28 | + if (defined('\JSON_UNESCAPED_UNICODE')) { |
|
29 | + $result |= \JSON_UNESCAPED_UNICODE; |
|
30 | + } |
|
31 | 31 | |
32 | - return $result; |
|
33 | - } |
|
32 | + return $result; |
|
33 | + } |
|
34 | 34 | |
35 | - /** |
|
36 | - * {@inheritdoc} |
|
37 | - * |
|
38 | - * @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
|
39 | - */ |
|
40 | - protected static function toStringDo($languages) |
|
41 | - { |
|
42 | - $list = array(); |
|
43 | - foreach ($languages as $language) { |
|
44 | - $item = array(); |
|
45 | - $item['name'] = $language->name; |
|
46 | - if (isset($language->supersededBy)) { |
|
47 | - $item['supersededBy'] = $language->supersededBy; |
|
48 | - } |
|
49 | - if (isset($language->script)) { |
|
50 | - $item['script'] = $language->script; |
|
51 | - } |
|
52 | - if (isset($language->territory)) { |
|
53 | - $item['territory'] = $language->territory; |
|
54 | - } |
|
55 | - if (isset($language->baseLanguage)) { |
|
56 | - $item['baseLanguage'] = $language->baseLanguage; |
|
57 | - } |
|
58 | - $item['formula'] = $language->formula; |
|
59 | - $item['plurals'] = count($language->categories); |
|
60 | - $item['cases'] = array(); |
|
61 | - $item['examples'] = array(); |
|
62 | - foreach ($language->categories as $category) { |
|
63 | - $item['cases'][] = $category->id; |
|
64 | - $item['examples'][$category->id] = $category->examples; |
|
65 | - } |
|
66 | - $list[$language->id] = $item; |
|
67 | - } |
|
35 | + /** |
|
36 | + * {@inheritdoc} |
|
37 | + * |
|
38 | + * @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
|
39 | + */ |
|
40 | + protected static function toStringDo($languages) |
|
41 | + { |
|
42 | + $list = array(); |
|
43 | + foreach ($languages as $language) { |
|
44 | + $item = array(); |
|
45 | + $item['name'] = $language->name; |
|
46 | + if (isset($language->supersededBy)) { |
|
47 | + $item['supersededBy'] = $language->supersededBy; |
|
48 | + } |
|
49 | + if (isset($language->script)) { |
|
50 | + $item['script'] = $language->script; |
|
51 | + } |
|
52 | + if (isset($language->territory)) { |
|
53 | + $item['territory'] = $language->territory; |
|
54 | + } |
|
55 | + if (isset($language->baseLanguage)) { |
|
56 | + $item['baseLanguage'] = $language->baseLanguage; |
|
57 | + } |
|
58 | + $item['formula'] = $language->formula; |
|
59 | + $item['plurals'] = count($language->categories); |
|
60 | + $item['cases'] = array(); |
|
61 | + $item['examples'] = array(); |
|
62 | + foreach ($language->categories as $category) { |
|
63 | + $item['cases'][] = $category->id; |
|
64 | + $item['examples'][$category->id] = $category->examples; |
|
65 | + } |
|
66 | + $list[$language->id] = $item; |
|
67 | + } |
|
68 | 68 | |
69 | - return json_encode($list, static::getEncodeOptions()); |
|
70 | - } |
|
69 | + return json_encode($list, static::getEncodeOptions()); |
|
70 | + } |
|
71 | 71 | } |
@@ -22,10 +22,10 @@ discard block |
||
22 | 22 | protected static function getEncodeOptions() |
23 | 23 | { |
24 | 24 | $result = 0; |
25 | - if (defined('\JSON_UNESCAPED_SLASHES')) { |
|
25 | + if ( defined( '\JSON_UNESCAPED_SLASHES' ) ) { |
|
26 | 26 | $result |= \JSON_UNESCAPED_SLASHES; |
27 | 27 | } |
28 | - if (defined('\JSON_UNESCAPED_UNICODE')) { |
|
28 | + if ( defined( '\JSON_UNESCAPED_UNICODE' ) ) { |
|
29 | 29 | $result |= \JSON_UNESCAPED_UNICODE; |
30 | 30 | } |
31 | 31 | |
@@ -37,35 +37,35 @@ discard block |
||
37 | 37 | * |
38 | 38 | * @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
39 | 39 | */ |
40 | - protected static function toStringDo($languages) |
|
40 | + protected static function toStringDo( $languages ) |
|
41 | 41 | { |
42 | 42 | $list = array(); |
43 | - foreach ($languages as $language) { |
|
43 | + foreach ( $languages as $language ) { |
|
44 | 44 | $item = array(); |
45 | - $item['name'] = $language->name; |
|
46 | - if (isset($language->supersededBy)) { |
|
47 | - $item['supersededBy'] = $language->supersededBy; |
|
45 | + $item[ 'name' ] = $language->name; |
|
46 | + if ( isset( $language->supersededBy ) ) { |
|
47 | + $item[ 'supersededBy' ] = $language->supersededBy; |
|
48 | 48 | } |
49 | - if (isset($language->script)) { |
|
50 | - $item['script'] = $language->script; |
|
49 | + if ( isset( $language->script ) ) { |
|
50 | + $item[ 'script' ] = $language->script; |
|
51 | 51 | } |
52 | - if (isset($language->territory)) { |
|
53 | - $item['territory'] = $language->territory; |
|
52 | + if ( isset( $language->territory ) ) { |
|
53 | + $item[ 'territory' ] = $language->territory; |
|
54 | 54 | } |
55 | - if (isset($language->baseLanguage)) { |
|
56 | - $item['baseLanguage'] = $language->baseLanguage; |
|
55 | + if ( isset( $language->baseLanguage ) ) { |
|
56 | + $item[ 'baseLanguage' ] = $language->baseLanguage; |
|
57 | 57 | } |
58 | - $item['formula'] = $language->formula; |
|
59 | - $item['plurals'] = count($language->categories); |
|
60 | - $item['cases'] = array(); |
|
61 | - $item['examples'] = array(); |
|
62 | - foreach ($language->categories as $category) { |
|
63 | - $item['cases'][] = $category->id; |
|
64 | - $item['examples'][$category->id] = $category->examples; |
|
58 | + $item[ 'formula' ] = $language->formula; |
|
59 | + $item[ 'plurals' ] = count( $language->categories ); |
|
60 | + $item[ 'cases' ] = array(); |
|
61 | + $item[ 'examples' ] = array(); |
|
62 | + foreach ( $language->categories as $category ) { |
|
63 | + $item[ 'cases' ][ ] = $category->id; |
|
64 | + $item[ 'examples' ][ $category->id ] = $category->examples; |
|
65 | 65 | } |
66 | - $list[$language->id] = $item; |
|
66 | + $list[ $language->id ] = $item; |
|
67 | 67 | } |
68 | 68 | |
69 | - return json_encode($list, static::getEncodeOptions()); |
|
69 | + return json_encode( $list, static::getEncodeOptions() ); |
|
70 | 70 | } |
71 | 71 | } |
@@ -2,15 +2,13 @@ discard block |
||
2 | 2 | |
3 | 3 | namespace Gettext\Languages\Exporter; |
4 | 4 | |
5 | -class Json extends Exporter |
|
6 | -{ |
|
5 | +class Json 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 compressed JSON-encoded file'; |
15 | 13 | } |
16 | 14 | |
@@ -19,8 +17,7 @@ discard block |
||
19 | 17 | * |
20 | 18 | * @return int |
21 | 19 | */ |
22 | - protected static function getEncodeOptions() |
|
23 | - { |
|
20 | + protected static function getEncodeOptions() { |
|
24 | 21 | $result = 0; |
25 | 22 | if (defined('\JSON_UNESCAPED_SLASHES')) { |
26 | 23 | $result |= \JSON_UNESCAPED_SLASHES; |
@@ -37,8 +34,7 @@ discard block |
||
37 | 34 | * |
38 | 35 | * @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
39 | 36 | */ |
40 | - protected static function toStringDo($languages) |
|
41 | - { |
|
37 | + protected static function toStringDo($languages) { |
|
42 | 38 | $list = array(); |
43 | 39 | foreach ($languages as $language) { |
44 | 40 | $item = array(); |