Zend_Form 占位符翻译
我有一个带有 Zend_Form 的 Zend 应用程序,它应该使用 HTML5 placeholder
属性而不是标签,就像这里所做的那样。
class Application_Form_Usereditprofile extends Zend_Form
{
public function init()
{
[...]
$this->addElement('text', 'FirstName', array(
'filters' => [...],
'validators' => [...],
'placeholder'=> 'user_editprofile_firstname', // string I want to translate
));
[...]
}
}
我初始化了 Zend_Translate,因此它应该默认翻译我的表单。这对于标签来说效果很好。但是,占位符将按原样使用,而不进行翻译。
如何翻译占位符字符串?
I have a Zend application with a Zend_Form, which should use the HTML5 placeholder
attribute instead of labels, like done here.
class Application_Form_Usereditprofile extends Zend_Form
{
public function init()
{
[...]
$this->addElement('text', 'FirstName', array(
'filters' => [...],
'validators' => [...],
'placeholder'=> 'user_editprofile_firstname', // string I want to translate
));
[...]
}
}
I initialized Zend_Translate so it should translate my forms by default. This works fine with labels. However, the placeholder gets used as it is, without being translated.
How can I translate the placeholder strings?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
顺便说一句,您可以像这样访问翻译助手
。
plceholder
属性不能替代label
。来自规范:
You can access the the translate helper like this
btw. the
plceholder
attribute is not a substitution for thelabel
.From the spec:
这是我的最终解决方案。它翻译所有占位符。感谢乔纳的回答。
就是这样!
Here is my final solution. It translates all placeholders. Thanks to Jona for the answer.
That's it!
实际上我喜欢让事情自动化,所以我简单地创建了新的 My_Form 类来扩展 Zend_Form 并替换了 render 方法来处理事情:
Actually I like to have things automated, so I've simply made new My_Form class extending Zend_Form and replaced render method to handle things: