Skip to content
This repository was archived by the owner on Oct 22, 2021. It is now read-only.

Commit d2c2705

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents fd6b959 + b9d553e commit d2c2705

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

README.md

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,14 @@ Register the composer autoloader in composer.json:
9696
Add settings:
9797

9898
```php
99-
// View settings
100-
$settings['twig'] = [
101-
'path' => '/path/to/templates',
102-
// Should be set to true in production
103-
'cache_enabled' => false,
104-
'cache_path' => '/path/to/temp/twig-cache',
99+
// Locale settings
100+
$settings['locale'] = [
101+
'path' => '/path/to/resources/locale',
102+
'cache' => '/path/to/locale-cache',
103+
'locale' => 'en_US',
104+
'domain' => 'messages',
105+
// Should be set to false in production
106+
'debug' => false,
105107
];
106108
```
107109

@@ -110,11 +112,11 @@ Add a new container entry:
110112
```php
111113
use League\Container\Container;
112114
use Odan\Twig\TwigTranslationExtension;
115+
use Slim\Views\Twig;
113116
use Symfony\Component\Translation\Formatter\MessageFormatter;
114117
use Symfony\Component\Translation\IdentityTranslator;
115118
use Symfony\Component\Translation\Loader\MoFileLoader;
116119
use Symfony\Component\Translation\Translator;
117-
use Twig\Environment as Twig;
118120

119121
$container = new Container();
120122

@@ -229,26 +231,42 @@ You need to iterate and compile all your Twig templates.
229231
The compilation step generates the PHP cache files that can be parsed from Poedit.
230232
This script is only an example and must be adapted to your individual environment.
231233

234+
Twig settings:
235+
236+
```php
237+
// Twig settings
238+
$settings['twig'] = [
239+
'path' => '/path/to/twig/templates',
240+
// Should be set to true in production
241+
'cache_enabled' => true,
242+
'cache_path' => '/path/to/twig-cache', // <---
243+
];
244+
```
245+
232246
File: `bin/parse-twig.php`
233247

234248
```php
235249
use Odan\Twig\TwigCompiler;
236-
use Slim\App;
237-
use Twig\Environment as Twig;
250+
use Slim\Views\Twig;
251+
252+
// Bootstrap Slim application
238253

239254
/** @var App $app */
240255
$app = require __DIR__ . '/../config/bootstrap.php';
241256

257+
// Read twig settings
242258
$settings = $app->getContainer()->get('settings')['twig'];
243-
$templatePath = (string)$settings['path'];
244259
$cachePath = (string)$settings['cache_path'];
245260

246-
$twig = $app->getContainer()->get(Twig::class);
261+
$twig = $app->getContainer()->get(Twig::class)->getEnvironment();
247262

263+
// Compile twig templates (*.twig) to PHP code
248264
$compiler = new TwigCompiler($twig, $cachePath, true);
249265
$compiler->compile();
250266

251267
echo "Done\n";
268+
269+
return 0;
252270
```
253271

254272
To run this script just enter: `php bin/parse-twig.php`

0 commit comments

Comments
 (0)