i18n (internationalization) in symfony
I am using the __('text')
construct in symfo开发者_StackOverflow社区ny so I can then internationalise. However I have tried to use it in a setFlash message as follows
$this->getUser()->setFlash('error', __('message'));
in the actions/actions.class.php but it give me an error
Fatal error: Call to undefined function __()
So am I to assume that I cannot use the __()
at the action level but only the template level?
In an action you have to use __() using the context:
echo $this->getContext()->getI18N()->__('message');
You can also use:
sfProjectConfiguration::getActive()->loadHelpers(array('I18N'));
$this->getUser()->setFlash('error', __('message'));
Best option if you are to do this is add this method to your actions.class.php:
public function preExecute()
{
sfProjectConfiguration::getActive()->loadHelpers(array('I18N'));
parent::preExecute();
}
It worked great for me! Thank you
You can also do $this->loadHelpers(array('I18N')); in your ProjectConfiguration class or frontend|backendConfiguration classes
Regards
精彩评论