-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathextract.php
51 lines (40 loc) · 1.17 KB
/
extract.php
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
<?php
use jblond\TwigTrans\Extract;
use jblond\TwigTrans\Translation;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
use Twig\TwigFilter;
require '../vendor/autoload.php';
error_reporting(E_ALL);
ini_set('display_errors', 'On');
$langCode = 'de_DE';
putenv("LC_ALL=$langCode.UTF-8");
if (setlocale(LC_ALL, "$langCode.UTF-8") === false) {
echo sprintf('Language Code %s not found', $langCode);
}
// set the path to the translation
bindtextdomain("Web_Content", "./locale");
// choose Domain
textdomain("Web_Content");
$twigConfig = [
'cache' => './cache',
'debug' => true,
'auto_reload' => true
];
$twigLoader = new FilesystemLoader('./tpl/');
$twig = new Environment($twigLoader, $twigConfig);
// this is for the filter |trans
$filter = new TwigFilter(
'trans',
function ($context, $string) {
return Translation::transGetText($string, $context);
},
['needs_context' => true]
);
$twig->addFilter($filter);
// load the i18n extension for using the translation tag for twig
// {% trans %}my string{% endtrans %}
$twig->addExtension(new Translation());
$extract = new Extract($twig);
$extract->addTemplate('default.twig');
$extract->extract();