aboutsummaryrefslogtreecommitdiffhomepage
path: root/locale/tools/fillCache.php
blob: bdd9cc581297680a4ea76c810a6928e8627cad95 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php

// this script compile all twig templates and put it in cahce to get Poedit (or xgettext) to extract phrases fron chached templates.

// gettext command line tools:
// msgunfmt - get po from mo
// msgfmt - get mo from po
// xgettext - extract phrases from files


		$siteRoot = dirname(__FILE__) . '/../..';

		require_once  $siteRoot . '/vendor/twig/twig/lib/Twig/Autoloader.php';
		Twig_Autoloader::register();

		require_once  $siteRoot . '/vendor/twig/extensions/lib/Twig/Extensions/Autoloader.php';
		Twig_Extensions_Autoloader::register();

		//$tplDir = $siteRoot.'/themes/default';
		$tplDirRoot = $siteRoot.'/themes/';
		$tmpDir =  $siteRoot. '/cache/';

		foreach (new IteratorIterator(new DirectoryIterator($tplDirRoot)) as $tplDir) {

			if ($tplDir->isDir() and $tplDir!='.' and $tplDir!='..') {
				echo "\n$tplDir\n";

				$loader = new Twig_Loader_Filesystem($tplDirRoot.$tplDir);

				// force auto-reload to always have the latest version of the template
				$twig = new Twig_Environment($loader, array(
						'cache' => $tmpDir,
						'auto_reload' => true
				));

				$twig->addExtension(new Twig_Extensions_Extension_I18n());

				$filter = new Twig_SimpleFilter('getDomain', 'Tools::getDomain');
				$twig->addFilter($filter);

				$filter = new Twig_SimpleFilter('getReadingTime', 'Tools::getReadingTime');
				$twig->addFilter($filter);

				$filter = new Twig_SimpleFilter('getPrettyFilename', function($string) { return str_replace($siteRoot, '', $string); });
				$twig->addFilter($filter);

// 				// iterate over all your templates
				foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tplDirRoot.$tplDir), RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
						// force compilation
					if ($file->isFile() and pathinfo($file, PATHINFO_EXTENSION)=='twig') {
							echo "\t$file\n";
							$twig->loadTemplate(str_replace($tplDirRoot.$tplDir.'/', '', $file));
					}
				}

			}

		}