@@ -96,12 +96,14 @@ Register the composer autoloader in composer.json:
9696Add 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
111113use League\Container\Container;
112114use Odan\Twig\TwigTranslationExtension;
115+ use Slim\Views\Twig;
113116use Symfony\Component\Translation\Formatter\MessageFormatter;
114117use Symfony\Component\Translation\IdentityTranslator;
115118use Symfony\Component\Translation\Loader\MoFileLoader;
116119use 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.
229231The compilation step generates the PHP cache files that can be parsed from Poedit.
230232This 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+
232246File: `bin/parse-twig.php`
233247
234248```php
235249use 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
251267echo "Done\n";
268+
269+ return 0;
252270```
253271
254272To run this script just enter: `php bin/parse-twig.php`
0 commit comments