ZF3 zend-mvc-skeleton 国际化不起作用
ZF3 zend-mvc-skeleton internationalization not working
我正在尝试评估现在是否是开始迁移到 ZF3(或继续使用 ZF2 开发我的应用程序)的合适时机。因此,我安装了 mvc-skeleton 应用程序并完成了 MVC 教程 (here),在我到达国际化部分之前它一直运行良好。
我安装了组件(即 zend-i18n 和 zend-mvc-i18n 组件),创建了翻译文件(即 en_US.mo 和 en_US.po)并将它们复制到我的 module/Application/language/
文件夹,在应用配置文件中添加配置。
// in a module's module.config.php:
'translator' => [
'locale' => 'en_US',
'translation_file_patterns' => [
[
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
],
],
],
当然,在 layout.phtml 文件中添加了要翻译的文本
<p>© 2016 by Examples Ltd. <?= $this->translate('All rights reserved') ?></p>
但是,由于某种原因它无法正常工作
Zend\ServiceManager\Exception\ServiceNotFoundException
File:
my_install_path/zend-mvc-skeleton-application/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php:133
Message:
A plugin by the name "translate" was not found in the plugin manager Zend\View\HelperPluginManager
Stack trace:
#0 /my-own-install-path/vendor/zendframework/zend-view/src/Renderer/PhpRenderer.php(373): Zend\ServiceManager\AbstractPluginManager->get('translate', NULL)
#1 /my-own-install-path/vendor/zendframework/zend-view/src/Renderer/PhpRenderer.php(391): Zend\View\Renderer\PhpRenderer->plugin('translate')
#2 /my-own-install-path/module/Application/view/application/index/index.phtml(1): Zend\View\Renderer\PhpRenderer->__call('translate', Array)
#3 /my-own-install-path/module/Application/view/application/index/index.phtml(1): Zend\View\Renderer\PhpRenderer->translate('Dr Job')
#4 /my-own-install-path/vendor/zendframework/zend-view/src/Renderer/PhpRenderer.php(502): include('/Applications/M...')
#5 /my-own-install-path/vendor/zendframework/zend-view/src/View.php(207): Zend\View\Renderer\PhpRenderer->render(Object(Zend\View\Model\ViewModel))
#6 /my-own-install-path/vendor/zendframework/zend-view/src/View.php(236): Zend\View\View->render(Object(Zend\View\Model\ViewModel))
#7 /my-own-install-path/vendor/zendframework/zend-view/src/View.php(200): Zend\View\View->renderChildren(Object(Zend\View\Model\ViewModel))
#8 /my-own-install-path/vendor/zendframework/zend-mvc/src/View/Http/DefaultRenderingStrategy.php(105): Zend\View\View->render(Object(Zend\View\Model\ViewModel))
#9 /my-own-install-path/vendor/zendframework/zend-eventmanager/src/EventManager.php(271): Zend\Mvc\View\Http\DefaultRenderingStrategy->render(Object(Zend\Mvc\MvcEvent))
#10 /my-own-install-path/vendor/zendframework/zend-eventmanager/src/EventManager.php(143): Zend\EventManager\EventManager->triggerListeners(Object(Zend\Mvc\MvcEvent))
#11 /my-own-install-path/vendor/zendframework/zend-mvc/src/Application.php(369): Zend\EventManager\EventManager->triggerEvent(Object(Zend\Mvc\MvcEvent))
#12 /my-own-install-path/vendor/zendframework/zend-mvc/src/Application.php(348): Zend\Mvc\Application->completeRequest(Object(Zend\Mvc\MvcEvent))
#13 /my-own-install-path/public/index.php(43): Zend\Mvc\Application->run()
#14 {main}
我的问题很简单。你成功了吗?或者你知道它有什么问题吗?任何帮助将不胜感激。非常感谢。
我用这个配置工作:
'translator' => [
'locale' => 'cs_CZ',
'translation_file_patterns' => [
[
'type' => 'gettext',
'base_dir' => APPLICATION_MODULE_ROOT . '/language',
'pattern' => '%s.mo',
],
],
],
你用哪些模块安装了zf3?
zend-servicemanager 你安装了吗?
它似乎找不到翻译视图助手。尝试将此添加到您的配置文件中:
'view_helpers' => [
'invokables' => [
'translate' => \Zend\I18n\View\Helper\Translate::class
]
]
我还发现我需要注册服务:
'service_manager' => [
'factories' => [
\Zend\I18n\Translator\TranslatorInterface::class => \Zend\I18n\Translator\TranslatorServiceFactory::class,
]
]
我从 samsonasik here 那里得到了 "plain vanilla" 解决方案。解决方案是要求:
$ composer require zendframework/zend-mvc-i18n
然后注册为模块:
'modules' => [
'Zend\I18n',
'Zend\Mvc\I18n',
// ...
],
我正在尝试评估现在是否是开始迁移到 ZF3(或继续使用 ZF2 开发我的应用程序)的合适时机。因此,我安装了 mvc-skeleton 应用程序并完成了 MVC 教程 (here),在我到达国际化部分之前它一直运行良好。
我安装了组件(即 zend-i18n 和 zend-mvc-i18n 组件),创建了翻译文件(即 en_US.mo 和 en_US.po)并将它们复制到我的 module/Application/language/
文件夹,在应用配置文件中添加配置。
// in a module's module.config.php:
'translator' => [
'locale' => 'en_US',
'translation_file_patterns' => [
[
'type' => 'gettext',
'base_dir' => __DIR__ . '/../language',
'pattern' => '%s.mo',
],
],
],
当然,在 layout.phtml 文件中添加了要翻译的文本
<p>© 2016 by Examples Ltd. <?= $this->translate('All rights reserved') ?></p>
但是,由于某种原因它无法正常工作
Zend\ServiceManager\Exception\ServiceNotFoundException
File:
my_install_path/zend-mvc-skeleton-application/vendor/zendframework/zend-servicemanager/src/AbstractPluginManager.php:133
Message:
A plugin by the name "translate" was not found in the plugin manager Zend\View\HelperPluginManager
Stack trace:
#0 /my-own-install-path/vendor/zendframework/zend-view/src/Renderer/PhpRenderer.php(373): Zend\ServiceManager\AbstractPluginManager->get('translate', NULL)
#1 /my-own-install-path/vendor/zendframework/zend-view/src/Renderer/PhpRenderer.php(391): Zend\View\Renderer\PhpRenderer->plugin('translate')
#2 /my-own-install-path/module/Application/view/application/index/index.phtml(1): Zend\View\Renderer\PhpRenderer->__call('translate', Array)
#3 /my-own-install-path/module/Application/view/application/index/index.phtml(1): Zend\View\Renderer\PhpRenderer->translate('Dr Job')
#4 /my-own-install-path/vendor/zendframework/zend-view/src/Renderer/PhpRenderer.php(502): include('/Applications/M...')
#5 /my-own-install-path/vendor/zendframework/zend-view/src/View.php(207): Zend\View\Renderer\PhpRenderer->render(Object(Zend\View\Model\ViewModel))
#6 /my-own-install-path/vendor/zendframework/zend-view/src/View.php(236): Zend\View\View->render(Object(Zend\View\Model\ViewModel))
#7 /my-own-install-path/vendor/zendframework/zend-view/src/View.php(200): Zend\View\View->renderChildren(Object(Zend\View\Model\ViewModel))
#8 /my-own-install-path/vendor/zendframework/zend-mvc/src/View/Http/DefaultRenderingStrategy.php(105): Zend\View\View->render(Object(Zend\View\Model\ViewModel))
#9 /my-own-install-path/vendor/zendframework/zend-eventmanager/src/EventManager.php(271): Zend\Mvc\View\Http\DefaultRenderingStrategy->render(Object(Zend\Mvc\MvcEvent))
#10 /my-own-install-path/vendor/zendframework/zend-eventmanager/src/EventManager.php(143): Zend\EventManager\EventManager->triggerListeners(Object(Zend\Mvc\MvcEvent))
#11 /my-own-install-path/vendor/zendframework/zend-mvc/src/Application.php(369): Zend\EventManager\EventManager->triggerEvent(Object(Zend\Mvc\MvcEvent))
#12 /my-own-install-path/vendor/zendframework/zend-mvc/src/Application.php(348): Zend\Mvc\Application->completeRequest(Object(Zend\Mvc\MvcEvent))
#13 /my-own-install-path/public/index.php(43): Zend\Mvc\Application->run()
#14 {main}
我的问题很简单。你成功了吗?或者你知道它有什么问题吗?任何帮助将不胜感激。非常感谢。
我用这个配置工作:
'translator' => [
'locale' => 'cs_CZ',
'translation_file_patterns' => [
[
'type' => 'gettext',
'base_dir' => APPLICATION_MODULE_ROOT . '/language',
'pattern' => '%s.mo',
],
],
],
你用哪些模块安装了zf3? zend-servicemanager 你安装了吗?
它似乎找不到翻译视图助手。尝试将此添加到您的配置文件中:
'view_helpers' => [
'invokables' => [
'translate' => \Zend\I18n\View\Helper\Translate::class
]
]
我还发现我需要注册服务:
'service_manager' => [
'factories' => [
\Zend\I18n\Translator\TranslatorInterface::class => \Zend\I18n\Translator\TranslatorServiceFactory::class,
]
]
我从 samsonasik here 那里得到了 "plain vanilla" 解决方案。解决方案是要求:
$ composer require zendframework/zend-mvc-i18n
然后注册为模块:
'modules' => [
'Zend\I18n',
'Zend\Mvc\I18n',
// ...
],