2

I use Sprout Email on a website to send transactional email (about 15 different types).

The website gets now translated to 3 languages (DE/FR/EN). It is all fine, but of course, also the transactional emails need to be in three languages.

As Sprout Email does not really support localization, it is still somehow possible by adding 3 "Email Body" fields to the email field layout:

  • emailBodyDe
  • emailBodyFr
  • emailBodyEn

In the mail template, I can then chose which body to use. All good so far.

{% set locale = object.locale %}
{% set emailBody = email.htmlEmailBodyDe %}
{% set emailSubject = email.subjectLine %}
{% switch locale %}
    {% case "fr" %}
        {% set emailBody = email.htmlEmailBodyDe %}
        {# ... set subject!? ... #}
    {% case "en" %}
        {% set emailBody = email.htmlEmailBodyEn %}
        {# ... set subject!? ... #}
{% endswitch %}

But I can't translate the subject line. There is just one fixed field in Sprout Email for that.

Any suggestions how I can also make the subject field multi-language?

1

First, we'll be adding native support for localization in Craft 3. This is a bit trickier in Craft 2 right now.

Two thoughts. You could set up 3 different emails (each managed in a different language) to be triggered off the same event. Not ideal, but an option.

Aside from that, Sprout Email does run the subjectLine field through renderObjectTemplate so you could use a field in whatever is triggering your event as a dynamic variable for the Subject Line.

  • 1
    Yes, I went with the second idea you provided. My current subject line looks like this: {% switch object.orderLocale %}{% case 'de' %}Deine Buchungsbestätigung...{% case 'fr' %}...{% case 'en' %}...{% endswitch %}, Not ideal, but it works so far :) – exophunk Apr 17 '18 at 14:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.