9

I want to utilize Sendgrid template versions to support multiple language support.

According to Sendgrid documentation:

A template can only have one active version at a time. If you’ve created a new version with different HTML that you want your customers to start receiving, you’ll need to make that version “Active.”

So, for example I have template with 2 version: English(active) and Russian. Thus, if I want to send email with Russian version, I need to active Russian template version before sending email.

But my concern is following: What if I need to send emails with Russian and English version in the same time? Will Sendgrind be able to supply proper version for 2 simultaneous request?

Hutsul
  • 1,535
  • 4
  • 31
  • 51

5 Answers5

7

I was able to implement multiple languages support for my emails using Sendgrid Dynamic Transactional Templates. The idea here is that you should create transactional template and design it with the help of handlebars if/else conditional statements. For e.g.: Adding support of English and Russian language for your template can look like this:

 <table>
      <tbody>
        {{#if english}}
        <tr>
          <td>
            <div style="text-align: center;"><span style="color:#7a7a7a;"><span style="font-size:12px;">My web site in social networks</span></span></div>
        </td>
      </tr>
      {{else if russian}}
         <tr>
           <td>
            <div style="text-align: center;"><span style="color:#7a7a7a;"><span style="font-size:12px;">Мой Веб сайт в социальных сетях</span></span></div>
        </td>
      </tr>
      {{/if}}
      </tbody>
    </table>

Then request should contain:

{
    "personalizations": [
    {
      "to": [
        {
          "email": "to_@email.com"
        }
      ],
      "dynamic_template_data": {
        "subject": "Subject_translated_to_desired_language",
        "russian": true
        // other placeholders
      }
    }
  ],

  "from": {"email": "from_@mail.com"},
  "template_id":"dynamic_template_id"
}

If you send this request to Sendgrid, it will send you email content in Russian language.

This example can be very helpful.

Hutsul
  • 1,535
  • 4
  • 31
  • 51
  • 8
    What if I have to manage 20 languages? How can we manage that in this way? – Alessandro Dionisi Jan 23 '20 at 08:03
  • @AlessandroDionisi You can either create a lot of if statements, or supply text/value dynamically via your API. Chances are pretty low that you'd have exactly the same content around the world, so I would recommend the first but it's not very pretty unfortunately. – LoopsGod Dec 02 '20 at 20:34
  • Meanwhile, they added a section into the docu: https://sendgrid.com/docs/for-developers/sending-email/using-handlebars/#multiple-languages – Björn W Mar 20 '21 at 07:46
5

What if I have to manage 20 languages? How can we manage that in this way?

Alessandro Dionisi
  • 2,494
  • 4
  • 33
  • 37
4

Maybe you could try to use this api . https://sendgrid.api-docs.io/v3.0/send-test-email/marketing-campaigns-send-test Looks like what you need.

mail test api: https://api.sendgrid.com/v3/marketing/test/send_email

You can get all the available templates with version using the below api . https://api.sendgrid.com/v3/templates?generations=dynamic Once you have all templates and versions , choose the version_id of your choice based on a version name , you can add to the template in sendgrid.

https://api.sendgrid.com/v3/marketing/test/send_email In the mail test api you should be able to set the below fields.

{
    "template_id": "string (required)",
    "version_id_override": "string (optional)",
    "sender_id": "integer (optional)",
    "custom_unsubscribe_url": "string (optional)",
    "suppression_group_id": "integer (optional)",
    "emails": [
        "string"
    ],
    "from_address": "string (optional)"
}
arjun
  • 73
  • 7
1

Using if/else statements within a signle template for large amount of languages makes it messy because it mixes logic with structure and appearance. IMHO the best option would be to have separate templates for different languages or deliver translated strings via API.

siefca
  • 1,007
  • 13
  • 16
1

Translated versions of your templates should be created/maintained by linguists. If you go with tags {{#if english}}, it complicates for linguists a lot.

Especially when you change your source language copy, maintaining localizations becomes an immense pain (if you have 10 languages, 10 linguists should go through the code and fix their blocks)

The best practice would be using a Translation Management System like this one https://store.crowdin.com/sendgrid-app

So you get a workflow like the following:

  1. A content creator writes an English version of your template
  2. TMS picks up the new template and involves linguists in selected languages
  3. Translated templates go back to your SendGrid
  4. Whenever your English template changes, it all goes from #2

This should be fully automated (all the synchronization, linguists notifications, etc)

You end up having templates like:

  • Welcome email
  • Welcome email [pl]
  • Welcome email [ee]