Symfony i18n and add_empty form

I have this widget:

$this->setWidget('slug', new sfWidgetFormDoctrineChoice(array('model' 
=> 'MyTable', 'method' => 'myMethod', 'key_method' => 'myMethod', 
'add_empty' => 'Select option'))); 

OK, what should I do to translate "Choose an Option"?

I cannot use the __ () helper inside the form and adding this line to my XLIFF file does not translate automatically.

If this is not possible, what workaround should I implement? I cannot find in any way, and not one of them can find any advice in the official documentation.

Thank!

+3
source share
2 answers

I think I solved this:

$translated_text = $this->widgetSchema->getFormFormatter()->translate('String to translate');
+5
source

You can use the helper form inside, try the following:

public function setup()
{
  sfContext::getInstance()->getConfiguration()->loadHelpers(array('I18n'));

  $this->setWidget('slug', new sfWidgetFormDoctrineChoice(array('model' 
    => 'MyTable', 'method' => 'myMethod', 'key_method' => 'myMethod', 
    'add_empty' => __('Select option'))); 
  ...
}
0
source

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


All Articles