ssossossosso

Forums

Covering OroCRM topics, including community updates and company announcements.  Subscribe

This topic contains 2 replies, has 3 voices, and was last updated by Artem Liubeznyi Artem Liubeznyi 2 years, 2 months ago.

  • Creator
    Topic
  • #9822

    cardiac
    Participant

    Hi all,

    I’m using the Oro EmailRenderer for rendering an email.

    The problem occurs when I want to translate a variable:

    I get an error:

    The template for Content (English) has syntax error: The filter “trans” does not exist at line 1

    Is it possible to translate in email templates?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Author
    Replies
  • #9835

    Hello, cardiac!

    You are getting this error because Translation Extension is not added into EmailRenderer’s environment.
    Also ‘trans’ filter usage is restricted by Twig’s security policy in sandbox mode (you can find all allowed tags, filters, functions etc at services.yml file of EmailBundle).
    To achieve your goals would be enough to add TranslationExtension to EmailRenderer and resolve usage of ‘trans’ filter. I believe TwigSandboxConfigurationPass class is the right place to add your code:
    const TRANSLATION_EXTENSION_SERVICE_KEY = 'twig.extension.trans';
    ...
    // inside if statement of process method:
    $filters = $securityPolicyDef->getArgument(1); // get allowed filters array
    $filters = array_merge($filters, array('trans')); // add trans filter to it
    $securityPolicyDef->replaceArgument(1, $filters); // set modified argument to definition
    ...
    $rendererDef->addMethodCall(
    'addExtension',
    array($container->getDefinition(self::TRANSLATION_EXTENSION_SERVICE_KEY))
    ); // enable Translation extension for EmailRenderer environment

    That’s it! And don’t forget to clear your cache to recompile service container.

    #10300
    Artem Liubeznyi
    Artem Liubeznyi
    Oro Core

    This will make a good feature, we will add it to our backlog. Thanks for the suggestion!

Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.