我们如何在 zend 框架上创建翻译验证错误消息? [英] how we could create translate validate error messages on zend framework?

查看:29
本文介绍了我们如何在 zend 框架上创建翻译验证错误消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

how we could create translate validate error messages on zend framework?

谁能举个例子?

谢谢

推荐答案

来自 关于 Zend_Validate 验证消息的 ZF 手册

From the 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 附带了超过 45 个不同的验证器,以及超过 200 条失败消息.翻译所有这些消息可能是一项繁重的任务.但是为了您的方便,Zend Framework 附带了已经预翻译的验证消息.您可以在 Zend Framework 安装的路径 /resources/languages 中找到它们.[...]
例如,要将所有验证消息翻译成德语,您所要做的就是使用这些资源文件将翻译器附加到 Zend_Validate.

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);

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

Of course, you can also provide your own translations. All you have to do is load make them available to the translation adapter. Basically you just swap out the part shown above to your custom path.

这篇关于我们如何在 zend 框架上创建翻译验证错误消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆