zf3 翻译路线 - 找不到翻译器

问题描述 投票:0回答:2

我需要实现一个多语言站点。比我需要使用 i18n 和翻译器,但我对路由翻译器有一些问题

这是我的 module.config.php

{
return [
    'router' => [
        'router' => [
            'router_class'           => TranslatorAwareTreeRouteStack::class,
        ],
        'routes' => [
            'home' => [
                'type' => Literal::class,
                'options' => [
                    'route'    => '/',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
            'application' => [
                'type'    => Segment::class,
                'options' => [
                    'route'    => '/{contact}',
                    'defaults' => [
                        'controller' => Controller\IndexController::class,
                        'action'     => 'index',
                    ],
                ],
            ],
        ],
    ]};
    }

这是我的 Module.php 类

 public function onBootstrap(MvcEvent $e)
    {
        /** @var \Zend\Mvc\I18n\Translator $translator */

        $translator = $e->getApplication()->getServiceManager()->get('MvcTranslator');
        $translator->addTranslationFilePattern(
            'phpArray',
            Resources::getBasePath(),
            Resources::getPatternForValidator()
        );
        AbstractValidator::setDefaultTranslator($translator);
    }       

当我启动应用程序时出现此错误

Zend\Router\Exception\RuntimeException: No translator provided in ..vendor\zendframework\zend-router\src\Http\Segment.php on line 372   

如何将翻译器传递给段类?我需要使用不同的类进行翻译?

routes zend-framework3
2个回答
0
投票

问题是配置。我搬这个

'router' => [
        'router_class' => \Zend\Mvc\I18n\Router\TranslatorAwareTreeRouteStack::class,
        'routes' => [

        ],
    ],

在全局配置中,一切正常。


-1
投票

解释这种程度的冒险是一项艰巨的工作。确实是一个高质量的翻译器。此外,这将需要大量投资和资产。我真的很喜欢完成作品的性质。假设我真的想做出准确而出色的解释,我通常只会去找有保证的口译员,仔细阅读这个网站来了解调查,并理解这是一个不错的选择。我承认在这种情况下,选择一个经过验证的选择来获得高质量的结果是更明智的做法。

https://thewordpoint.com/services/certified

© www.soinside.com 2019 - 2024. All rights reserved.