emailsendgridsendgrid-api-v3sendgrid-templates

Sendgrid: use template versions to support multiple languages


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?


Solution

  • 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.