@@ -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 | } |
@@ -6,27 +6,27 @@ |
||
6 | 6 | |
7 | 7 | class Prettyjson extends Json |
8 | 8 | { |
9 | - /** |
|
10 | - * {@inheritdoc} |
|
11 | - * |
|
12 | - * @see \Gettext\Languages\Exporter\Exporter::getDescription() |
|
13 | - */ |
|
14 | - public static function getDescription() |
|
15 | - { |
|
16 | - return 'Build an uncompressed JSON-encoded file (PHP 5.4 or later is needed)'; |
|
17 | - } |
|
9 | + /** |
|
10 | + * {@inheritdoc} |
|
11 | + * |
|
12 | + * @see \Gettext\Languages\Exporter\Exporter::getDescription() |
|
13 | + */ |
|
14 | + public static function getDescription() |
|
15 | + { |
|
16 | + return 'Build an uncompressed JSON-encoded file (PHP 5.4 or later is needed)'; |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * {@inheritdoc} |
|
21 | - * |
|
22 | - * @see \Gettext\Languages\Exporter\Json::getEncodeOptions() |
|
23 | - */ |
|
24 | - protected static function getEncodeOptions() |
|
25 | - { |
|
26 | - if (!(defined('\JSON_PRETTY_PRINT') && defined('\JSON_UNESCAPED_SLASHES') && defined('\JSON_UNESCAPED_UNICODE'))) { |
|
27 | - throw new Exception('PHP 5.4 or later is required to export uncompressed JSON'); |
|
28 | - } |
|
19 | + /** |
|
20 | + * {@inheritdoc} |
|
21 | + * |
|
22 | + * @see \Gettext\Languages\Exporter\Json::getEncodeOptions() |
|
23 | + */ |
|
24 | + protected static function getEncodeOptions() |
|
25 | + { |
|
26 | + if (!(defined('\JSON_PRETTY_PRINT') && defined('\JSON_UNESCAPED_SLASHES') && defined('\JSON_UNESCAPED_UNICODE'))) { |
|
27 | + throw new Exception('PHP 5.4 or later is required to export uncompressed JSON'); |
|
28 | + } |
|
29 | 29 | |
30 | - return \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE; |
|
31 | - } |
|
30 | + return \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE; |
|
31 | + } |
|
32 | 32 | } |
@@ -4,57 +4,57 @@ |
||
4 | 4 | |
5 | 5 | class Ruby extends Exporter |
6 | 6 | { |
7 | - /** |
|
8 | - * {@inheritdoc} |
|
9 | - * |
|
10 | - * @see \Gettext\Languages\Exporter\Exporter::getDescription() |
|
11 | - */ |
|
12 | - public static function getDescription() |
|
13 | - { |
|
14 | - return 'Build a Ruby hash'; |
|
15 | - } |
|
7 | + /** |
|
8 | + * {@inheritdoc} |
|
9 | + * |
|
10 | + * @see \Gettext\Languages\Exporter\Exporter::getDescription() |
|
11 | + */ |
|
12 | + public static function getDescription() |
|
13 | + { |
|
14 | + return 'Build a Ruby hash'; |
|
15 | + } |
|
16 | 16 | |
17 | - /** |
|
18 | - * {@inheritdoc} |
|
19 | - * |
|
20 | - * @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
|
21 | - */ |
|
22 | - protected static function toStringDo($languages) |
|
23 | - { |
|
24 | - $lines = array(); |
|
25 | - $lines[] = 'PLURAL_RULES = {'; |
|
26 | - foreach ($languages as $lc) { |
|
27 | - $lines[] = ' \'' . $lc->id . '\' => {'; |
|
28 | - $lines[] = ' \'name\' => \'' . addslashes($lc->name) . '\','; |
|
29 | - if (isset($lc->supersededBy)) { |
|
30 | - $lines[] = ' \'supersededBy\' => \'' . $lc->supersededBy . '\','; |
|
31 | - } |
|
32 | - if (isset($lc->script)) { |
|
33 | - $lines[] = ' \'script\' => \'' . addslashes($lc->script) . '\','; |
|
34 | - } |
|
35 | - if (isset($lc->territory)) { |
|
36 | - $lines[] = ' \'territory\' => \'' . addslashes($lc->territory) . '\','; |
|
37 | - } |
|
38 | - if (isset($lc->baseLanguage)) { |
|
39 | - $lines[] = ' \'baseLanguage\' => \'' . addslashes($lc->baseLanguage) . '\','; |
|
40 | - } |
|
41 | - $lines[] = ' \'formula\' => \'' . $lc->formula . '\','; |
|
42 | - $lines[] = ' \'plurals\' => ' . count($lc->categories) . ','; |
|
43 | - $catNames = array(); |
|
44 | - foreach ($lc->categories as $c) { |
|
45 | - $catNames[] = "'{$c->id}'"; |
|
46 | - } |
|
47 | - $lines[] = ' \'cases\' => [' . implode(', ', $catNames) . '],'; |
|
48 | - $lines[] = ' \'examples\' => {'; |
|
49 | - foreach ($lc->categories as $c) { |
|
50 | - $lines[] = ' \'' . $c->id . '\' => \'' . $c->examples . '\','; |
|
51 | - } |
|
52 | - $lines[] = ' },'; |
|
53 | - $lines[] = ' },'; |
|
54 | - } |
|
55 | - $lines[] = '}'; |
|
56 | - $lines[] = ''; |
|
17 | + /** |
|
18 | + * {@inheritdoc} |
|
19 | + * |
|
20 | + * @see \Gettext\Languages\Exporter\Exporter::toStringDo() |
|
21 | + */ |
|
22 | + protected static function toStringDo($languages) |
|
23 | + { |
|
24 | + $lines = array(); |
|
25 | + $lines[] = 'PLURAL_RULES = {'; |
|
26 | + foreach ($languages as $lc) { |
|
27 | + $lines[] = ' \'' . $lc->id . '\' => {'; |
|
28 | + $lines[] = ' \'name\' => \'' . addslashes($lc->name) . '\','; |
|
29 | + if (isset($lc->supersededBy)) { |
|
30 | + $lines[] = ' \'supersededBy\' => \'' . $lc->supersededBy . '\','; |
|
31 | + } |
|
32 | + if (isset($lc->script)) { |
|
33 | + $lines[] = ' \'script\' => \'' . addslashes($lc->script) . '\','; |
|
34 | + } |
|
35 | + if (isset($lc->territory)) { |
|
36 | + $lines[] = ' \'territory\' => \'' . addslashes($lc->territory) . '\','; |
|
37 | + } |
|
38 | + if (isset($lc->baseLanguage)) { |
|
39 | + $lines[] = ' \'baseLanguage\' => \'' . addslashes($lc->baseLanguage) . '\','; |
|
40 | + } |
|
41 | + $lines[] = ' \'formula\' => \'' . $lc->formula . '\','; |
|
42 | + $lines[] = ' \'plurals\' => ' . count($lc->categories) . ','; |
|
43 | + $catNames = array(); |
|
44 | + foreach ($lc->categories as $c) { |
|
45 | + $catNames[] = "'{$c->id}'"; |
|
46 | + } |
|
47 | + $lines[] = ' \'cases\' => [' . implode(', ', $catNames) . '],'; |
|
48 | + $lines[] = ' \'examples\' => {'; |
|
49 | + foreach ($lc->categories as $c) { |
|
50 | + $lines[] = ' \'' . $c->id . '\' => \'' . $c->examples . '\','; |
|
51 | + } |
|
52 | + $lines[] = ' },'; |
|
53 | + $lines[] = ' },'; |
|
54 | + } |
|
55 | + $lines[] = '}'; |
|
56 | + $lines[] = ''; |
|
57 | 57 | |
58 | - return implode("\n", $lines); |
|
59 | - } |
|
58 | + return implode("\n", $lines); |
|
59 | + } |
|
60 | 60 | } |
@@ -9,116 +9,116 @@ |
||
9 | 9 | */ |
10 | 10 | class Category |
11 | 11 | { |
12 | - /** |
|
13 | - * The category identifier (eg 'zero', 'one', ..., 'other'). |
|
14 | - * |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - public $id; |
|
12 | + /** |
|
13 | + * The category identifier (eg 'zero', 'one', ..., 'other'). |
|
14 | + * |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + public $id; |
|
18 | 18 | |
19 | - /** |
|
20 | - * The gettext formula that identifies this category (null if and only if the category is 'other'). |
|
21 | - * |
|
22 | - * @var string|null |
|
23 | - */ |
|
24 | - public $formula; |
|
19 | + /** |
|
20 | + * The gettext formula that identifies this category (null if and only if the category is 'other'). |
|
21 | + * |
|
22 | + * @var string|null |
|
23 | + */ |
|
24 | + public $formula; |
|
25 | 25 | |
26 | - /** |
|
27 | - * The CLDR representation of some exemplar numeric ranges that satisfy this category. |
|
28 | - * |
|
29 | - * @var string|null |
|
30 | - */ |
|
31 | - public $examples; |
|
26 | + /** |
|
27 | + * The CLDR representation of some exemplar numeric ranges that satisfy this category. |
|
28 | + * |
|
29 | + * @var string|null |
|
30 | + */ |
|
31 | + public $examples; |
|
32 | 32 | |
33 | - /** |
|
34 | - * Initialize the instance and parse the formula. |
|
35 | - * |
|
36 | - * @param string $cldrCategoryId the CLDR category identifier (eg 'pluralRule-count-one') |
|
37 | - * @param string $cldrFormulaAndExamples the CLDR formula and examples (eg 'i = 1 and v = 0 @integer 1') |
|
38 | - * |
|
39 | - * @throws \Exception |
|
40 | - */ |
|
41 | - public function __construct($cldrCategoryId, $cldrFormulaAndExamples) |
|
42 | - { |
|
43 | - $matches = array(); |
|
44 | - if (!preg_match('/^pluralRule-count-(.+)$/', $cldrCategoryId, $matches)) { |
|
45 | - throw new Exception("Invalid CLDR category: '{$cldrCategoryId}'"); |
|
46 | - } |
|
47 | - if (!in_array($matches[1], CldrData::$categories)) { |
|
48 | - throw new Exception("Invalid CLDR category: '{$cldrCategoryId}'"); |
|
49 | - } |
|
50 | - $this->id = $matches[1]; |
|
51 | - $cldrFormulaAndExamplesNormalized = trim(preg_replace('/\s+/', ' ', $cldrFormulaAndExamples)); |
|
52 | - if (!preg_match('/^([^@]*)(?:@integer([^@]+))?(?:@decimal(?:[^@]+))?$/', $cldrFormulaAndExamplesNormalized, $matches)) { |
|
53 | - throw new Exception("Invalid CLDR category rule: {$cldrFormulaAndExamples}"); |
|
54 | - } |
|
55 | - $cldrFormula = trim($matches[1]); |
|
56 | - $s = isset($matches[2]) ? trim($matches[2]) : ''; |
|
57 | - $this->examples = ($s === '') ? null : $s; |
|
58 | - switch ($this->id) { |
|
59 | - case CldrData::OTHER_CATEGORY: |
|
60 | - if ($cldrFormula !== '') { |
|
61 | - throw new Exception("The '" . CldrData::OTHER_CATEGORY . "' category should not have any formula, but it has '{$cldrFormula}'"); |
|
62 | - } |
|
63 | - $this->formula = null; |
|
64 | - break; |
|
65 | - default: |
|
66 | - if ($cldrFormula === '') { |
|
67 | - throw new Exception("The '{$this->id}' category does not have a formula"); |
|
68 | - } |
|
69 | - $this->formula = FormulaConverter::convertFormula($cldrFormula); |
|
70 | - break; |
|
71 | - } |
|
72 | - } |
|
33 | + /** |
|
34 | + * Initialize the instance and parse the formula. |
|
35 | + * |
|
36 | + * @param string $cldrCategoryId the CLDR category identifier (eg 'pluralRule-count-one') |
|
37 | + * @param string $cldrFormulaAndExamples the CLDR formula and examples (eg 'i = 1 and v = 0 @integer 1') |
|
38 | + * |
|
39 | + * @throws \Exception |
|
40 | + */ |
|
41 | + public function __construct($cldrCategoryId, $cldrFormulaAndExamples) |
|
42 | + { |
|
43 | + $matches = array(); |
|
44 | + if (!preg_match('/^pluralRule-count-(.+)$/', $cldrCategoryId, $matches)) { |
|
45 | + throw new Exception("Invalid CLDR category: '{$cldrCategoryId}'"); |
|
46 | + } |
|
47 | + if (!in_array($matches[1], CldrData::$categories)) { |
|
48 | + throw new Exception("Invalid CLDR category: '{$cldrCategoryId}'"); |
|
49 | + } |
|
50 | + $this->id = $matches[1]; |
|
51 | + $cldrFormulaAndExamplesNormalized = trim(preg_replace('/\s+/', ' ', $cldrFormulaAndExamples)); |
|
52 | + if (!preg_match('/^([^@]*)(?:@integer([^@]+))?(?:@decimal(?:[^@]+))?$/', $cldrFormulaAndExamplesNormalized, $matches)) { |
|
53 | + throw new Exception("Invalid CLDR category rule: {$cldrFormulaAndExamples}"); |
|
54 | + } |
|
55 | + $cldrFormula = trim($matches[1]); |
|
56 | + $s = isset($matches[2]) ? trim($matches[2]) : ''; |
|
57 | + $this->examples = ($s === '') ? null : $s; |
|
58 | + switch ($this->id) { |
|
59 | + case CldrData::OTHER_CATEGORY: |
|
60 | + if ($cldrFormula !== '') { |
|
61 | + throw new Exception("The '" . CldrData::OTHER_CATEGORY . "' category should not have any formula, but it has '{$cldrFormula}'"); |
|
62 | + } |
|
63 | + $this->formula = null; |
|
64 | + break; |
|
65 | + default: |
|
66 | + if ($cldrFormula === '') { |
|
67 | + throw new Exception("The '{$this->id}' category does not have a formula"); |
|
68 | + } |
|
69 | + $this->formula = FormulaConverter::convertFormula($cldrFormula); |
|
70 | + break; |
|
71 | + } |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Return a list of numbers corresponding to the $examples value. |
|
76 | - * |
|
77 | - * @throws \Exception throws an Exception if we weren't able to expand the examples |
|
78 | - * |
|
79 | - * @return int[] |
|
80 | - */ |
|
81 | - public function getExampleIntegers() |
|
82 | - { |
|
83 | - return self::expandExamples($this->examples); |
|
84 | - } |
|
74 | + /** |
|
75 | + * Return a list of numbers corresponding to the $examples value. |
|
76 | + * |
|
77 | + * @throws \Exception throws an Exception if we weren't able to expand the examples |
|
78 | + * |
|
79 | + * @return int[] |
|
80 | + */ |
|
81 | + public function getExampleIntegers() |
|
82 | + { |
|
83 | + return self::expandExamples($this->examples); |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Expand a list of examples as defined by CLDR. |
|
88 | - * |
|
89 | - * @param string $examples A string like '1, 2, 5...7, …'. |
|
90 | - * |
|
91 | - * @throws \Exception throws an Exception if we weren't able to expand $examples |
|
92 | - * |
|
93 | - * @return int[] |
|
94 | - */ |
|
95 | - public static function expandExamples($examples) |
|
96 | - { |
|
97 | - $result = array(); |
|
98 | - $m = null; |
|
99 | - if (substr($examples, -strlen(', …')) === ', …') { |
|
100 | - $examples = substr($examples, 0, strlen($examples) - strlen(', …')); |
|
101 | - } |
|
102 | - foreach (explode(',', str_replace(' ', '', $examples)) as $range) { |
|
103 | - if (preg_match('/^(?<num>\d+)((c|e)(?<exp>\d+))?$/', $range, $m)) { |
|
104 | - $result[] = (int) (isset($m['exp']) ? ($m['num'] . str_repeat('0', (int) $m['exp'])) : $range); |
|
105 | - } elseif (preg_match('/^(\d+)~(\d+)$/', $range, $m)) { |
|
106 | - $from = (int) $m[1]; |
|
107 | - $to = (int) $m[2]; |
|
108 | - $delta = $to - $from; |
|
109 | - $step = (int) max(1, $delta / 100); |
|
110 | - for ($i = $from; $i < $to; $i += $step) { |
|
111 | - $result[] = $i; |
|
112 | - } |
|
113 | - $result[] = $to; |
|
114 | - } else { |
|
115 | - throw new Exception("Unhandled test range '{$range}' in '{$examples}'"); |
|
116 | - } |
|
117 | - } |
|
118 | - if (empty($result)) { |
|
119 | - throw new Exception("No test numbers from '{$examples}'"); |
|
120 | - } |
|
86 | + /** |
|
87 | + * Expand a list of examples as defined by CLDR. |
|
88 | + * |
|
89 | + * @param string $examples A string like '1, 2, 5...7, …'. |
|
90 | + * |
|
91 | + * @throws \Exception throws an Exception if we weren't able to expand $examples |
|
92 | + * |
|
93 | + * @return int[] |
|
94 | + */ |
|
95 | + public static function expandExamples($examples) |
|
96 | + { |
|
97 | + $result = array(); |
|
98 | + $m = null; |
|
99 | + if (substr($examples, -strlen(', …')) === ', …') { |
|
100 | + $examples = substr($examples, 0, strlen($examples) - strlen(', …')); |
|
101 | + } |
|
102 | + foreach (explode(',', str_replace(' ', '', $examples)) as $range) { |
|
103 | + if (preg_match('/^(?<num>\d+)((c|e)(?<exp>\d+))?$/', $range, $m)) { |
|
104 | + $result[] = (int) (isset($m['exp']) ? ($m['num'] . str_repeat('0', (int) $m['exp'])) : $range); |
|
105 | + } elseif (preg_match('/^(\d+)~(\d+)$/', $range, $m)) { |
|
106 | + $from = (int) $m[1]; |
|
107 | + $to = (int) $m[2]; |
|
108 | + $delta = $to - $from; |
|
109 | + $step = (int) max(1, $delta / 100); |
|
110 | + for ($i = $from; $i < $to; $i += $step) { |
|
111 | + $result[] = $i; |
|
112 | + } |
|
113 | + $result[] = $to; |
|
114 | + } else { |
|
115 | + throw new Exception("Unhandled test range '{$range}' in '{$examples}'"); |
|
116 | + } |
|
117 | + } |
|
118 | + if (empty($result)) { |
|
119 | + throw new Exception("No test numbers from '{$examples}'"); |
|
120 | + } |
|
121 | 121 | |
122 | - return $result; |
|
123 | - } |
|
122 | + return $result; |
|
123 | + } |
|
124 | 124 | } |