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