Cakephp 表格输入的翻译
我目前正在国际化我的cake php webapp,它运行得非常好。 除表单输入外,所有内容均已翻译:Cakephp 表格输入的翻译,cakephp,internationalization,cakephp-2.3,Cakephp,Internationalization,Cakephp 2.3,我目前正在国际化我的cake php webapp,它运行得非常好。 除表单输入外,所有内容均已翻译: echo $this->Form->input('name', array('class' => 'form-control')); 这将生成一个标签 <label for="UserName">Name</label> 但是有没有不指定标签的方法?在CakePHP 2.3中,如果您查看内置的FormHelper类: public functio
echo $this->Form->input('name', array('class' => 'form-control'));
这将生成一个标签
<label for="UserName">Name</label>
但是有没有不指定标签的方法?在CakePHP 2.3中,如果您查看内置的FormHelper类:
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)));
}
...
}
在我看来,如果不设置标签文本,它将从字段名派生标签文本,然后对其调用translate函数
您是否尝试过只创建一个输入而不指定标签文本,然后将自动为该输入的标签生成的文本的翻译保存到相应的.po文件中?确定。翻译不会为自动生成的标签生成,比如我的案例名称。
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)));
}
...
}