KnpLabs / DoctrineBehaviors Translatable - currentLocale = null
Posted
by
Ruben
on Stack Overflow
See other posts from Stack Overflow
or by Ruben
Published on 2013-10-23T11:53:47Z
Indexed on
2013/10/28
9:54 UTC
Read the original article
Hit count: 2374
Using the trait \Knp\DoctrineBehaviors\Model\Translatable\Translation
inside an Entity, I see that the property currentLocale is never setted , so we always obtain the default locale ('en') in all the calls to $this->translate()
.
If I change this getDefaultLocale
, all the translations are made correctly, so I think that is no problem with the fallback.
I tried debug the currentLocaleCallable. I see that if I put a "var_dump ($this->container->get('request'));" in the contructor of currentLocaleCallable, the request have a locale to null. And outside the request has the correct locale.It seems that container is not in the scope: request , i don't know how can I get it to work
I post an issue in github https://github.com/KnpLabs/DoctrineBehaviors/issues/71
EDITED
This service is defined in vendor/knplabs/doctrine-behaviors/config/orm-services.yml and is:
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
EDIT 2: My 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"
© Stack Overflow or respective owner