3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

How to Japanize Validation of Zend Framework 2.3

Last updated at Posted at 2014-12-03

エラーメッセージの翻訳を行うには、以下の様にします。

ロケールを日本語とする

module/Application/config/module.config.php
// 'locale' => 'en_US',
'locale' => 'ja_JP'

翻訳ファイルを設定する

module/Application/Module.php
public function onBootstrap(MvcEvent $e)
{
    $eventManager        = $e->getApplication()->getEventManager();
    $moduleRouteListener = new ModuleRouteListener();
    $moduleRouteListener->attach($eventManager);

    // 以下を追加
    $sm = $e->getApplication()->getServiceManager();
    $translator = $sm->get('MvcTranslator');
    $translator->addTranslationFile(
        'phpArray',
        'vendor/zendframework/zendframework/resources/languages/ja/' .
        'Zend_Validate.php',
        'default',
        'ja_JP'
    );

    \Zend\Validator\AbstractValidator::setDefaultTranslator(
        new \Zend\Mvc\I18n\Translator($translator)
    );
}

実行結果

名称未設定.png

Zend_Validate.php の指定がダサいです。なんか _DIR_ とか使って格好良くしたいんですけど、力不足ですすいません。

以下を参考にしました。
http://stackoverflow.com/questions/23151917/zf2-3-translate-validation-message

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?