ZF2 Use non-en default locale for default Validator messages

扶醉桌前 提交于 2019-12-12 01:41:38

问题


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

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

As this topic suggests - Zend Framework 2 - Translate Standard Form Validation and Error messages but no effect!

I've tried forcing Locale at module config with the same no results:

'translator' => array(
    'locale' => 'ru_RU'
),

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?

Big thanks!


回答1:


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.

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


来源:https://stackoverflow.com/questions/18150506/zf2-use-non-en-default-locale-for-default-validator-messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!