| 1 |
<?php |
| 2 |
|
| 3 |
namespace Gettext\Languages\Exporter; |
| 4 |
|
| 5 |
class Xml extends Exporter |
| 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 https://php-gettext.github.io/Languages/GettextLanguages.xsd'; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* {@inheritdoc} |
| 19 |
* |
| 20 |
* @see \Gettext\Languages\Exporter\Exporter::toStringDoWithOptions() |
| 21 |
*/ |
| 22 |
protected static function toStringDoWithOptions($languages, array $options) |
| 23 |
{ |
| 24 |
$xml = new \DOMDocument('1.0', 'UTF-8'); |
| 25 |
$xml->loadXML('<languages |
| 26 |
xmlns="https://github.com/mlocati/cldr-to-gettext-plural-rules" |
| 27 |
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 28 |
xsi:schemaLocation="https://github.com/mlocati/cldr-to-gettext-plural-rules https://php-gettext.github.io/Languages/GettextLanguages.xsd" |
| 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; |
| 57 |
|
| 58 |
return $xml->saveXML(); |
| 59 |
} |
| 60 |
} |
| 61 |
|