Skip to content

Instantly share code, notes, and snippets.

@rredpoppy
Created September 24, 2014 13:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rredpoppy/4f6318d3b6365cf79720 to your computer and use it in GitHub Desktop.
Save rredpoppy/4f6318d3b6365cf79720 to your computer and use it in GitHub Desktop.
Export YAML to .po
<?php
ini_set('display_errors', true);
require '../vendor/autoload.php';
use Symfony\Component\Translation\Loader\YamlFileLoader,
Symfony\Component\Translation\Loader\XliffFileLoader,
Symfony\Component\Translation\MessageCatalogue,
Symfony\Component\Translation\Dumper\PoFileDumper;
use Symfony\Component\Yaml\Yaml;
$exportPath = __DIR__ . '/transPath/Lang';
$yloader = new YamlFileLoader();
$xloader = new XliffFileLoader();
$iterator = new FilesystemIterator(dirname(__FILE__) . 'srcPath');
$yfilter = new RegexIterator($iterator, '/\.(lcode\.yml)$/');
$xfilter = new RegexIterator($iterator, '/\.(lcode\.xliff)$/');
$dumper = new PoFileDumper();
foreach ($yfilter as $file) {
$name = $file->getBasename('.yml');
list($domain, $locale) = explode('.', $name);
$array = $yloader->load($file->getPathname(), $locale, $domain);
$catalogue = new MessageCatalogue($locale);
$catalogue->addCatalogue($array);
$dumper->dump($catalogue, array('path'=> $exportPath));
}
foreach ($xfilter as $file) {
$name = $file->getBasename('.xliff');
list($domain, $locale) = explode('.', $name);
$array = $xloader->load($file->getPathname(), $locale, $domain);
$catalogue = new MessageCatalogue($locale);
$catalogue->addCatalogue($array);
$dumper->dump($catalogue, array('path'=> $exportPath));
}
echo 'Done';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment