gpt4 book ai didi

php - 我们如何在 zend 框架上创建翻译验证错误消息?

转载 作者:行者123 更新时间:2023-12-02 06:44:16 24 4
gpt4 key购买 nike

我们如何在 zend 框架上创建翻译验证错误消息?

谁能举个例子?

谢谢

最佳答案

来自ZF Manual on Zend_Validate Validation Messages

  $validator = new Zend_Validate_GreaterThan();
$validator->setMessage('Please enter a lower value',
Zend_Validate_GreaterThan::NOT_GREATER);

还有:

Zend Framework is shipped with more than 45 different validators with more than 200 failure messages. It can be a tendious task to translate all of these messages. But for your convinience Zend Framework comes with already pre-translated validation messages. You can find them within the path /resources/languages in your Zend Framework installation. [...]
So to translate all validation messages to german for example, all you have to do is to attach a translator to Zend_Validate using these resource files.

  $translator = new Zend_Translate(
'array',
'/resources/languages',
$language,
array('scan' => Zend_Locale::LOCALE_DIRECTORY)
);
Zend_Validate_Abstract::setDefaultTranslator($translator);

当然,您也可以提供自己的翻译。您所要做的就是加载它们以供翻译适配器使用。基本上,您只需将上面显示的部分换成您的自定义路径。

关于php - 我们如何在 zend 框架上创建翻译验证错误消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2626972/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com