问题描述
我正在与 ZF2 进行斗争,以强制对任何传入的浏览器语言环境进行一种特定的验证消息转换.所以我只希望 ZF2 总是使用它自己提供的错误消息翻译成俄语,这个文件:\vendor\zendframework\zendframework\resources\languages\ru\Zend_Validate.php
I'm fighting with ZF2 to force one specific validation messages translation for any incoming browser locale.So I just want ZF2 to always use it's own provided translations of error messages to russian, this file:\vendor\zendframework\zendframework\resources\languages\ru\Zend_Validate.php
我已经尝试在 onBootstrap
中创建 Translator 并将其设置为默认值:
I've tried creating Translator and setting it as Default at onBootstrap
:
$translator = new \Zend\Mvc\I18n\Translator();
$translator->addTranslationFile(
'phpArray',
'vendor/zendframework/zendframework/resources/languages/ru/Zend_Validate.php',
'default',
'ru_RU'
);
AbstractValidator::setDefaultTranslator($translator);
正如本主题所暗示的 - Zend Framework 2 -翻译标准表单验证和错误消息,但没有效果!
As this topic suggests - Zend Framework 2 - Translate Standard Form Validation and Error messages but no effect!
我尝试在模块配置中强制使用 Locale,但没有结果:
I've tried forcing Locale at module config with the same no results:
'translator' => array(
'locale' => 'ru_RU'
),
我不确定,可能翻译文件 URL 有问题?因为当我尝试 Z-Dumb 翻译器时,它声称有 0 个消息注册了 1 个文件.
I'm not sure, maybe something is wrong with translation file URL? Cause when I try Z-Dumb the translator, it claims having 1 file registered by 0 messages.
无论如何,强制默认验证器翻译始终为俄语的最简单方法是什么?
Anyway, what is the easiest way to force default validator translation to always be russian?
非常感谢!
推荐答案
你提到的路径是 \resources\languages\ru\Zend_Validate.php
但你的配置中的路径是 \资源\语言\Zend_Validate.php
.注意文件夹 ru
的不同.
The path you mention is \resources\languages\ru\Zend_Validate.php
but the path in your config is \resources\languages\Zend_Validate.php
. Mind the difference of the folder ru
.
我希望这已经产生了很大的不同.如果没有,您是否可以尝试在 onBootstrap() 中添加这个来强制使用语言环境:
I would expect this already makes quite a difference. If not, can you try to force the locale with this added in your onBootstrap():
Locale::setDefault('ru_RU');
这篇关于ZF2 对默认验证器消息使用非默认语言环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!