Created
September 24, 2014 13:29
-
-
Save rredpoppy/4f6318d3b6365cf79720 to your computer and use it in GitHub Desktop.
Export YAML to .po
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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