aboutsummaryrefslogtreecommitdiffhomepage
path: root/locale/tools/fillCache.php
diff options
context:
space:
mode:
Diffstat (limited to 'locale/tools/fillCache.php')
-rwxr-xr-xlocale/tools/fillCache.php59
1 files changed, 59 insertions, 0 deletions
diff --git a/locale/tools/fillCache.php b/locale/tools/fillCache.php
new file mode 100755
index 00000000..bdd9cc58
--- /dev/null
+++ b/locale/tools/fillCache.php
@@ -0,0 +1,59 @@
1<?php
2
3// this script compile all twig templates and put it in cahce to get Poedit (or xgettext) to extract phrases fron chached templates.
4
5// gettext command line tools:
6// msgunfmt - get po from mo
7// msgfmt - get mo from po
8// xgettext - extract phrases from files
9
10
11 $siteRoot = dirname(__FILE__) . '/../..';
12
13 require_once $siteRoot . '/vendor/twig/twig/lib/Twig/Autoloader.php';
14 Twig_Autoloader::register();
15
16 require_once $siteRoot . '/vendor/twig/extensions/lib/Twig/Extensions/Autoloader.php';
17 Twig_Extensions_Autoloader::register();
18
19 //$tplDir = $siteRoot.'/themes/default';
20 $tplDirRoot = $siteRoot.'/themes/';
21 $tmpDir = $siteRoot. '/cache/';
22
23 foreach (new IteratorIterator(new DirectoryIterator($tplDirRoot)) as $tplDir) {
24
25 if ($tplDir->isDir() and $tplDir!='.' and $tplDir!='..') {
26 echo "\n$tplDir\n";
27
28 $loader = new Twig_Loader_Filesystem($tplDirRoot.$tplDir);
29
30 // force auto-reload to always have the latest version of the template
31 $twig = new Twig_Environment($loader, array(
32 'cache' => $tmpDir,
33 'auto_reload' => true
34 ));
35
36 $twig->addExtension(new Twig_Extensions_Extension_I18n());
37
38 $filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain');
39 $twig->addFilter($filter);
40
41 $filter = new Twig_SimpleFilter('getReadingTime', 'Tools::getReadingTime');
42 $twig->addFilter($filter);
43
44 $filter = new Twig_SimpleFilter('getPrettyFilename', function($string) { return str_replace($siteRoot, '', $string); });
45 $twig->addFilter($filter);
46
47// // iterate over all your templates
48 foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tplDirRoot.$tplDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
49 // force compilation
50 if ($file->isFile() and pathinfo($file, PATHINFO_EXTENSION)=='twig') {
51 echo "\t$file\n";
52 $twig->loadTemplate(str_replace($tplDirRoot.$tplDir.'/', '', $file));
53 }
54 }
55
56 }
57
58 }
59