I18n (internationalization) in symfony

I use the construct __('text')in symfony, so I can then internationalize. However, I tried using it in the setFlash message as follows

$this->getUser()->setFlash('error', __('message'));

in actions /actions.class.php, but it gives me an error

Fatal error: Call to undefined function __()

I must assume that I cannot use __()at the action level, but only at the template level?

+3
source share
3 answers

In action, you should use __ () using the context:

echo $this->getContext()->getI18N()->__('message');

You can also use:

sfProjectConfiguration::getActive()->loadHelpers(array('I18N'));
$this->getUser()->setFlash('error', __('message'));
+13
source

The best option if you want to do this is to add this method to your .class.php actions:

public function preExecute()
  {
   sfProjectConfiguration::getActive()->loadHelpers(array('I18N'));
   parent::preExecute();
  }
+3
source

!

$this- > loadHelpers (array ('I18N')); ProjectConfiguration | backendConfiguration classes

+1

Source: https://habr.com/ru/post/1784371/


All Articles