Zend Framework 2-翻译标准表单验证和错误消息 [英] Zend Framework 2 - Translate Standard Form Validation and Error messages
问题描述
我正在编写一个完整的德语应用程序,因此基本上需要将所有内容都设置为德语.
I'm writing a complete German application and therefore need to set basically everything to German.
我的问题:将表单验证设置为德语的最佳和最简便的方法是什么?
My question: What is the best and easiest way to set for example the form validation to German?
我找到了此页面,但找不到弄清楚如何使此代码正常工作:
I found this page but couldn't figure out how to get this code working:
Zend_Validate_Abstract::setDefaultTranslator($translate);
有人可以给我一些使用建议吗?
Could anyone give me some advice how to use this?
由于@Gordon,我将以下内容放入了Application/Module.php:
Thanks to @Gordon I put the following into my Application/Module.php:
use Zend\I18n\Translator\Translator;
use Zend\Validator\AbstractValidator;
class Module
{
public function onBootstrap(MvcEvent $e)
{
...
$translator = new Translator();
$translator->addTranslationFile(
'phpArray',
'resources/languages/de.php',
'default',
'de_DE'
);
AbstractValidator::setDefaultTranslator($translator);
...
}
修改2:
好吧,这很奇怪.当我设置de_DE
时,我收到消息无法打开de.php文件-这是正确的,因为"de"是一个包含另外两个PHP文件的文件夹.
Edit 2:
Alright, this is odd. When I set de_DE
I get the message that the de.php file couldn't be opened - which is true because "de" is a folder containing two other PHP files.
无法打开文件资源/语言/de.php进行阅读
Could not open file resources/languages/de.php for reading
更改文件夹或其中的任何现有文件的路径都无济于事...
Altering the path to the folder or to any existing file within it doesnt help...
当我将"de_DE"更改为"de"或"de_de"时,什么也没有发生.没有错误和英语验证错误.有任何线索吗?
When I change the "de_DE" to "de" or "de_de" then nothing happens. No error and English validation errors. Any clues?
推荐答案
最后,我在@Gordon的帮助下找到了答案!
Finally I found with help of @Gordon the answer!
我将以下内容放入了Application/Module.php:
I put the following into my Application/Module.php:
use Zend\I18n\Translator\Translator;
use Zend\Validator\AbstractValidator;
class Module
{
public function onBootstrap(MvcEvent $e)
{
...
$translator = new Translator();
$translator->addTranslationFile(
'phpArray',
'vendor/zendframework/zendframework/resources/languages/Zend_Validate.php',
'default',
'de_DE'
);
AbstractValidator::setDefaultTranslator($translator);
...
}
然后,您需要启用php5-intl.转到php.ini并启用extension=php_intl.dll
.
Then you need to enable php5-intl. Go to php.ini and enable extension=php_intl.dll
.
最后,我需要在Gordon和文档提供的功能中添加完整路径(从供应商开始).
Finally I needed to add the full path (starting with vendor) in the funciton provided by Gordon and the docs.
这篇关于Zend Framework 2-翻译标准表单验证和错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!