| 1 |
<?php |
| 2 |
|
| 3 |
namespace Gettext\Languages\Exporter; |
| 4 |
|
| 5 |
class Ruby extends Exporter |
| 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 |
} |
| 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[] = ''; |
| 57 |
|
| 58 |
return implode("\n", $lines); |
| 59 |
} |
| 60 |
} |
| 61 |
|