To enter the globule (or all) twig into your translations, you need to redefine the translation. Check this answer if you want a detailed explanation. Here is what I did:
Cancel the translator.class parameter (e.g. in parameters.yml ):
translator.class: Acme\YourBundle\Translation\Translator
Create a new Translator service:
use Symfony\Bundle\FrameworkBundle\Translation\Translator as BaseTranslator; class Translator extends BaseTranslator { }
Finally, replace both trans and transChoice :
public function trans($id, array $parameters = array(), $domain = null, $locale = null) { return parent::trans( $id, array_merge($this->container->get('twig')->getGlobals(), $parameters), $domain, $locale ); } public function transChoice($id, $number, array $parameters = array(), $domain = null, $locale = null) { return parent::transChoice( $id, $number, array_merge($this->container->get('twig')->getGlobals(), $parameters), $domain, $locale ); }
In this example, I enter all. You can enter only one:
array_merge(['%your_global%' => $this->container->get('twig')->getGlobals()['your_global']], $parameters)
ferdynator
source share