OroPlatform Forums

Covering OroPlatform topics, including community updates and company announcements.

Forums Forums OroPlatform OroPlatform – How do I? Questions How to translate in oro email

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

Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.

  • Creator
    Topic
  • #35972

    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
  • #35973

    Andrey Mishchenko
    Participant

    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.

    #35974

    Artem Liubeznyi
    Spectator

    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)

The forum ‘OroPlatform – How do I? Questions’ is closed to new topics and replies.

Back to top