Le 14/02/2011 21:18, violyn a écrit :
hi-
i am trying to use translation in the twig file generated by a
controller.  it doesn't work (the page is generated as normal, with no
translation).
here are the things i have done:

in app/config/config.yml i added this line:
translator: { fallback: en }

i created MyBundle/Resources/translations and put messages.fr_FR.php
there.  that file contains:
<?php

return array(
     'Symfony2 is great' =>  'J\'aime Symfony2',
     'Welcome'    =>  'Bienvenue',
);
?>

in my controller, i include:
use Symfony\Component\Translation\Translator;
use Symfony\Component\Locale\Locale;
This is not needed if you don't use the class in your controller.
also, in my controller, i manually set the locale as follows:
$this->container->get('request')->getSession()->setLocale('fr_FR');

in the twig file generated by the controller i made, i have:
  {% trans %}Welcome{% endtrans %}

However, it displays as Welcome when I use the controller to render
the twig file instead of the translated version.

I have read doc carefully, but I can't tell what I am missing.

Can someone please help me?
Do your clear your cache after enabling the translator ? This requires to re-compile the Twig templates to call the translator.

--
Christophe | Stof

--
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en

Reply via email to