aboutsummaryrefslogtreecommitdiffhomepage
path: root/locale/tools/fillCache.php
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2014-02-26 14:56:15 +0100
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2014-02-26 14:56:15 +0100
commit0e7f04b04ed73d4ef320948323742631a3d125e8 (patch)
treec9047a3c375eee5b8801283704e3803e0885d226 /locale/tools/fillCache.php
parent72f7ff058931806f9d0f2ca06d58c47264e33dfb (diff)
parentcbcae4037c02cd6c1ce7c373c6dae390565b7c51 (diff)
downloadwallabag-0e7f04b04ed73d4ef320948323742631a3d125e8.tar.gz
wallabag-0e7f04b04ed73d4ef320948323742631a3d125e8.tar.zst
wallabag-0e7f04b04ed73d4ef320948323742631a3d125e8.zip
Merge pull request #504 from mariroz/dev
translation related: how-to md file added, script to generate php from all twig templates, polish mo file compiled
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