3 // this script compile all twig templates and put it in cahce to get Poedit (or xgettext) to extract phrases fron chached templates.
5 // gettext command line tools:
6 // msgunfmt - get po from mo
7 // msgfmt - get mo from po
8 // xgettext - extract phrases from files
11 $siteRoot = dirname(__FILE__
) . '/../..';
13 require_once $siteRoot . '/vendor/twig/twig/lib/Twig/Autoloader.php';
14 Twig_Autoloader
::register();
16 require_once $siteRoot . '/vendor/twig/extensions/lib/Twig/Extensions/Autoloader.php';
17 Twig_Extensions_Autoloader
::register();
19 //$tplDir = $siteRoot.'/themes/default';
20 $tplDirRoot = $siteRoot.'/themes/';
21 $tmpDir = $siteRoot. '/cache/';
23 foreach (new IteratorIterator(new DirectoryIterator($tplDirRoot)) as $tplDir) {
25 if ($tplDir->isDir() and $tplDir!='.' and $tplDir!='..') {
28 $loader = new Twig_Loader_Filesystem($tplDirRoot.$tplDir);
30 // force auto-reload to always have the latest version of the template
31 $twig = new Twig_Environment($loader, array(
36 $twig->addExtension(new Twig_Extensions_Extension_I18n());
38 $filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain');
39 $twig->addFilter($filter);
41 $filter = new Twig_SimpleFilter('getReadingTime', 'Tools::getReadingTime');
42 $twig->addFilter($filter);
44 $filter = new Twig_SimpleFilter('getPrettyFilename', function($string) { return str_replace($siteRoot
, '', $
string); });
45 $twig->addFilter($filter);
47 // // iterate over all your templates
48 foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tplDirRoot.$tplDir), RecursiveIteratorIterator
::LEAVES_ONLY
) as $file) {
50 if ($file->isFile() and pathinfo($file, PATHINFO_EXTENSION
)=='twig') {
52 $twig->loadTemplate(str_replace($tplDirRoot.$tplDir.'/', '', $file));