Sendgrid: use template versions to support multiple languages

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": "[email protected]"
        }
      ],
      "dynamic_template_data": {
        "subject": "Subject_translated_to_desired_language",
        "russian": true
        // other placeholders
      }
    }
  ],

  "from": {"email": "[email protected]"},
  "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.


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)"
}