Reputation: 35
I'm trying to do some i18n on some Twig templates. The relevant code in index.php is as follows :
// Twig
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__ . '/../src/views',
));
$twig = new \Twig_Environment($app['twig.loader.filesystem']);
$twig->addExtension(new \Twig_Extensions_Extension_I18n());
// User Controller Service Provider for SimpleUser
$app->register($u = new SimpleUser\UserServiceProvider());
$app['twig.loader.filesystem']->addPath(__DIR__.'/../src/views/user','user');
$app['user.controller']->setLayoutTemplate('layout.twig');
$app->mount('/silex-ror/user', $u);
Then, in the twig template being rendered I wrote :
<h1>{% trans %}List users{% endtrans %}</h1>
But I get an error :
Unexpected tag name "trans"
Since I don't get any error when adding the extension, I assume it's simply being completely ignored when I try to render the template, but I'm not sure where I'm making a mistake.
Any help appreciated.
Upvotes: 0
Views: 1190
Reputation: 1287
Register the Translation Provider before:
$app->register(new Silex\Provider\TranslationServiceProvider(), array(
'locale_fallbacks' => array('en'),
));
and then register Twig:
$app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__ . '/../src/views',
));
there is no need to register the Twig i18n extension!
See also Silex TranslationServiceProvider
Upvotes: 2