【问题标题】:Symfony form's i18n and add_emptySymfony 表单的 i18n 和 add_empty
【发布时间】:2010-03-15 17:31:01
【问题描述】:

我有这个小部件:

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

好的,我应该如何翻译“选择选项”?

我不能在表单中使用 __() 助手,并添加该字符串 到我的 XLIFF 文件中不会自动翻译它。

如果无法完成,我应该实施什么解决方法?我找不到 无论如何,在官方文档中都找不到任何提示。

谢谢!

【问题讨论】:

    标签: symfony1


    【解决方案1】:

    我想我已经解决了:

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

    【讨论】:

      【解决方案2】:

      你可以在表单中使用助手,试试这个:

      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'))); 
        ...
      }
      

      【讨论】:

      猜你喜欢
      • 2011-11-14
      • 1970-01-01
      • 2011-12-18
      • 2011-02-11
      • 2011-08-23
      • 2012-05-23
      • 1970-01-01
      • 2011-09-14
      • 2021-04-06
      相关资源
      最近更新 更多