2010-03-15 39 views
3

我有這個小工具:的Symfony形式的國際化和add_empty

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

好吧,我應該怎麼做翻譯的「選擇選項」?

我不能在窗體中使用__()幫助程序,並且將該字符串 添加到我的XLIFF文件中並不會自動翻譯它。

如果無法完成,應實施哪種解決方法?我無法找到 ,在官方文檔中也找不到任何提示。

謝謝!

回答

5

我想我已經解決了它:

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

您可以使用助手裏面的形式,試試這個:

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

這是一個非常醜陋的解決方案,也不會在測試工作。閱讀[爲什麼sfContext :: getInstance()不好](http://webmozarts.com/2009/07/01/why-sfcontextgetinstance-is-bad/)。 – Maerlyn 2012-07-23 09:20:28