2014-05-16 64 views
2

我目前正在國際化我的cake-php-webapp,它工作得很好。 一切都被翻譯,但表單輸入:表單輸入的翻譯

echo $this->Form->input('name', array('class' => 'form-control')); 

這會產生一個標籤

<label for="UserName">Name</label> 

我怎麼可以指定「名稱」也應該被翻譯?

我認爲這將是我目前所知的最佳方式:

echo $this->Form->input('name', array('class' => 'form-control', 'label'=>__('field_name'))); 

但有沒有指定標籤的方法嗎?

回答

1

在CakePHP 2.3,如果你把一看內置的表單助手類:

public function label($fieldName = null, $text = null, $options = array()) { 

... 

if ($text === null) { 

     if (strpos($fieldName, '.') !== false) { 
      $fieldElements = explode('.', $fieldName); 
      $text = array_pop($fieldElements); 
     } else { 
      $text = $fieldName; 
     } 
     if (substr($text, -3) === '_id') { 
      $text = substr($text, 0, -3); 
     } 

     $text = __(Inflector::humanize(Inflector::underscore($text))); 
    } 

... 

} 

它看起來對我來說,如果你不設置標籤文本,它獲得您的標籤文本從字段名稱,然後調用它的翻譯功能。

您是否嘗試過剛剛創建輸入不指定標籤文本,然後保存一個翻譯,可以自動獲取在相應的.po文件輸入的標籤生成的文本?

+0

當然。對於那些自動生成的標籤,翻譯不會生成,就像我的案例名稱一樣。 – mosquito87