@@ -13,12 +13,12 @@ |
||
13 | 13 | */ |
14 | 14 | class LogLevel |
15 | 15 | { |
16 | - const EMERGENCY = 'emergency'; |
|
17 | - const ALERT = 'alert'; |
|
18 | - const CRITICAL = 'critical'; |
|
19 | - const ERROR = 'error'; |
|
20 | - const WARNING = 'warning'; |
|
21 | - const NOTICE = 'notice'; |
|
22 | - const INFO = 'info'; |
|
23 | - const DEBUG = 'debug'; |
|
16 | + const EMERGENCY = 'emergency'; |
|
17 | + const ALERT = 'alert'; |
|
18 | + const CRITICAL = 'critical'; |
|
19 | + const ERROR = 'error'; |
|
20 | + const WARNING = 'warning'; |
|
21 | + const NOTICE = 'notice'; |
|
22 | + const INFO = 'info'; |
|
23 | + const DEBUG = 'debug'; |
|
24 | 24 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -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 | } |
@@ -4,58 +4,58 @@ |
||
4 | 4 | |
5 | 5 | class Php 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 PHP array'; |
|
15 | - } |
|
7 | + /** |
|
8 | + * {@inheritdoc} |
|
9 | + * |
|
10 | + * @see \Gettext\Languages\Exporter\Exporter::getDescription() |
|
11 | + */ |
|
12 | + public static function getDescription() |
|
13 | + { |
|
14 | + return 'Build a PHP array'; |
|
15 | + } |
|
16 | 16 | |
17 | - /** |
|
18 | - * {@inheritdoc} |
|
19 | - * |
|
20 | - * @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
|
21 | - */ |
|
22 | - protected static function toStringDo($languages) |
|
23 | - { |
|
24 | - $lines = array(); |
|
25 | - $lines[] = '<?php'; |
|
26 | - $lines[] = 'return array('; |
|
27 | - foreach ($languages as $lc) { |
|
28 | - $lines[] = ' \'' . $lc->id . '\' => array('; |
|
29 | - $lines[] = ' \'name\' => \'' . addslashes($lc->name) . '\','; |
|
30 | - if (isset($lc->supersededBy)) { |
|
31 | - $lines[] = ' \'supersededBy\' => \'' . $lc->supersededBy . '\','; |
|
32 | - } |
|
33 | - if (isset($lc->script)) { |
|
34 | - $lines[] = ' \'script\' => \'' . addslashes($lc->script) . '\','; |
|
35 | - } |
|
36 | - if (isset($lc->territory)) { |
|
37 | - $lines[] = ' \'territory\' => \'' . addslashes($lc->territory) . '\','; |
|
38 | - } |
|
39 | - if (isset($lc->baseLanguage)) { |
|
40 | - $lines[] = ' \'baseLanguage\' => \'' . addslashes($lc->baseLanguage) . '\','; |
|
41 | - } |
|
42 | - $lines[] = ' \'formula\' => \'' . $lc->formula . '\','; |
|
43 | - $lines[] = ' \'plurals\' => ' . count($lc->categories) . ','; |
|
44 | - $catNames = array(); |
|
45 | - foreach ($lc->categories as $c) { |
|
46 | - $catNames[] = "'{$c->id}'"; |
|
47 | - } |
|
48 | - $lines[] = ' \'cases\' => array(' . implode(', ', $catNames) . '),'; |
|
49 | - $lines[] = ' \'examples\' => array('; |
|
50 | - foreach ($lc->categories as $c) { |
|
51 | - $lines[] = ' \'' . $c->id . '\' => \'' . $c->examples . '\','; |
|
52 | - } |
|
53 | - $lines[] = ' ),'; |
|
54 | - $lines[] = ' ),'; |
|
55 | - } |
|
56 | - $lines[] = ');'; |
|
57 | - $lines[] = ''; |
|
17 | + /** |
|
18 | + * {@inheritdoc} |
|
19 | + * |
|
20 | + * @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
|
21 | + */ |
|
22 | + protected static function toStringDo($languages) |
|
23 | + { |
|
24 | + $lines = array(); |
|
25 | + $lines[] = '<?php'; |
|
26 | + $lines[] = 'return array('; |
|
27 | + foreach ($languages as $lc) { |
|
28 | + $lines[] = ' \'' . $lc->id . '\' => array('; |
|
29 | + $lines[] = ' \'name\' => \'' . addslashes($lc->name) . '\','; |
|
30 | + if (isset($lc->supersededBy)) { |
|
31 | + $lines[] = ' \'supersededBy\' => \'' . $lc->supersededBy . '\','; |
|
32 | + } |
|
33 | + if (isset($lc->script)) { |
|
34 | + $lines[] = ' \'script\' => \'' . addslashes($lc->script) . '\','; |
|
35 | + } |
|
36 | + if (isset($lc->territory)) { |
|
37 | + $lines[] = ' \'territory\' => \'' . addslashes($lc->territory) . '\','; |
|
38 | + } |
|
39 | + if (isset($lc->baseLanguage)) { |
|
40 | + $lines[] = ' \'baseLanguage\' => \'' . addslashes($lc->baseLanguage) . '\','; |
|
41 | + } |
|
42 | + $lines[] = ' \'formula\' => \'' . $lc->formula . '\','; |
|
43 | + $lines[] = ' \'plurals\' => ' . count($lc->categories) . ','; |
|
44 | + $catNames = array(); |
|
45 | + foreach ($lc->categories as $c) { |
|
46 | + $catNames[] = "'{$c->id}'"; |
|
47 | + } |
|
48 | + $lines[] = ' \'cases\' => array(' . implode(', ', $catNames) . '),'; |
|
49 | + $lines[] = ' \'examples\' => array('; |
|
50 | + foreach ($lc->categories as $c) { |
|
51 | + $lines[] = ' \'' . $c->id . '\' => \'' . $c->examples . '\','; |
|
52 | + } |
|
53 | + $lines[] = ' ),'; |
|
54 | + $lines[] = ' ),'; |
|
55 | + } |
|
56 | + $lines[] = ');'; |
|
57 | + $lines[] = ''; |
|
58 | 58 | |
59 | - return implode("\n", $lines); |
|
60 | - } |
|
59 | + return implode("\n", $lines); |
|
60 | + } |
|
61 | 61 | } |