使用\Knp\DoctrineBehaviors\Model\Translatable\Translation
实体内部的特征,我看到属性 currentLocale 从未设置,所以我们总是在所有调用中获取默认语言环境('en')$this->translate()
。
如果我改变这个getDefaultLocale
,所有的翻译都是正确的,所以我认为后备没有问题。
我尝试调试currentLocaleCallable。我看到如果我放一个“var_dump ($this->container->get('request'));” 在 currentLocaleCallable 的构造函数中,请求的语言环境为 null。并且在请求之外具有正确的语言环境。似乎容器不在范围内:请求,我不知道如何让它工作
我在 github https://github.com/KnpLabs/DoctrineBehaviors/issues/71中发布了一个问题
已编辑
该服务在 vendor/knplabs/doctrine-behaviors/config/orm-services.yml 中定义并且是:
knp.doctrine_behaviors.reflection.class_analyzer:
class: "%knp.doctrine_behaviors.reflection.class_analyzer.class%"
public: false
knp.doctrine_behaviors.translatable_listener:
class: "%knp.doctrine_behaviors.translatable_listener.class%"
public: false
arguments:
- "@knp.doctrine_behaviors.reflection.class_analyzer"
- "%knp.doctrine_behaviors.reflection.is_recursive%"
- "@knp.doctrine_behaviors.translatable_listener.current_locale_callable"
tags:
- { name: doctrine.event_subscriber }
knp.doctrine_behaviors.translatable_listener.current_locale_callable:
class: "%knp.doctrine_behaviors.translatable_listener.current_locale_callable.class%"
arguments:
- "@service_container" # lazy request resolution
public: false
编辑 2:我的 composer.json
"php": ">=5.3.3",
"symfony/symfony": "2.3.*",
"doctrine/orm": ">=2.2.3,<2.4-dev",
"doctrine/doctrine-bundle": "1.2.*",
"twig/extensions": "1.0.*",
"symfony/assetic-bundle": "2.3.*",
"symfony/swiftmailer-bundle": "2.3.*",
"symfony/monolog-bundle": "2.3.*",
"sensio/distribution-bundle": "2.3.*",
"sensio/framework-extra-bundle": "2.3.*",
"sensio/generator-bundle": "2.3.*",
"incenteev/composer-parameter-handler": "~2.0",
"friendsofsymfony/user-bundle": "1.3.*",
"avalanche123/imagine-bundle": "v2.1",
"raulfraile/ladybug-bundle": "~1.0",
"genemu/form-bundle": "2.2.*",
"friendsofsymfony/rest-bundle": "0.12.0",
"stof/doctrine-extensions-bundle": "dev-master",
"sonata-project/admin-bundle": "dev-master",
"a2lix/translation-form-bundle": "1.*@dev",
"sonata-project/user-bundle": "dev-master",
"psliwa/pdf-bundle": "dev-master",
"jms/serializer-bundle": "dev-master",
"jms/di-extra-bundle": "dev-master",
"knplabs/doctrine-behaviors": "dev-master",
"sonata-project/doctrine-orm-admin-bundle": "dev-master",
"knplabs/knp-paginator-bundle": "dev-master",
"friendsofsymfony/jsrouting-bundle": "~1.1",
"zendframework/zend-validator": ">=2.0.0-rc2",
"zendframework/zend-barcode": ">=2.0.0-rc2"