How to utilize template versions for multiple language support

So it seems I can send different email that is written by different language for each customers(localization) according to the docs, but how can I exactly do that? It says I need to activate and change through API, But I couldn't figure out how to achieve it. or do I need to use substitutions and send message bundles from our backend? Any help would be appreciated!
Technical details:
- sendgrid-nodejs Version: master (latest commit: [13af4a6])
- Node.js Version: 6.12.3
Hello @ifndefdeadmau5,
Here is the API documentation on this feature. Here is how to use this SDK to make that API call.
I hope that helps!
With Best Regards,
Elmer
Thank you for getting back to me @thinkingserious,
I still cannot figure out how 'activate specific template version' actually can be used. I was thinking of scenario that I have 2 versions of template that is written by more than 2 languages, maybe English and Spanish, or whatever.
Then, I make a message send API call with specific template versions that matches with user's language
export function sendSendGridEmail()
{
sgMail.setApiKey(config.get('sendgrid.API_KEY'));
sgMail.setSubstitutionWrappers('{{', '}}');
const msg = {
to: '[email protected]',
from: '[email protected]',
subject: 'Sending with SendGrid is Fun',
text: 'and easy to do anywhere, even with Node.js',
html: '<strong>and easy to do anywhere, even with Node.js</strong>',
templateId: isUserLocaleEnglish ? ENGLISH_TEMPLATE_ID : SPANISH_TEMPLATE_ID, // This line!
substitutions: {
name: 'Some One',
city: 'Denver',
},
};
sgMail.send(msg);
}
But above example requires 2 separate templates, not the one template of different version. Which can lead to generate separate templates but content is related. What am I missing here? please enlighten me. Thank you again and look forward to hear from you!
Hello @ifndefdeadmau5,
You can have multiple versions per template. Then you can use the SDK to activate a particular version.
First, you would create multiple versions of your template. Then you would activate the desired version before you made the above call.
With Best Regards,
Elmer
Good morning @thinkingserious,
Thank you for your quick response and I haven't imagine such a work around. Now I understand how to do it, but one question is why not activate all template versions at the first time then just let user can use it without bothering with Activate/Deactivate things?
My concern is, what if more than two users whose using different languages do some actions at the same time(exactly same), so our server needs to address 2 request at the same time. Then which template version would be activated?
below is part of our server code, to just let you know my situation
export async function sendSendGridEmail() {
const locale = 'ko';
const isEnglishUser = locale === 'en';
const PASSWORD_RESET_TEMPLATE_ID = '2096abb7-a9f8-413f-96a1-b9df0644b313';
const { versions } = await getTemplate(PASSWORD_RESET_TEMPLATE_ID);
const KO_VER = _.find(versions, { name: 'Korean' }).id;
const EN_VER = _.find(versions, { name: 'English' }).id;
await activateVersion(PASSWORD_RESET_TEMPLATE_ID, isEnglishUser ? EN_VER : KO_VER);
sgMail.setSubstitutionWrappers('{{', '}}');
const msg = {
to: '[email protected]',
from: '[email protected]',
templateId: PASSWORD_RESET_TEMPLATE_ID,
substitutions: {
username: 'Test Username',
},
};
sgMail.send(msg);
}
Hello @ifndefdeadmau5,
That's a valid concern.
It seems that what you really need is our new (in beta) templating system. To join the beta, please email [email protected].
With Best Regards,
Elmer
I was also looking at transactional templates to see how we could use template versions for different locale-specific emails.
I agree, it seems strange to have to activate a particular template version before using it. This isn't the best solution for our high transaction software. I'd expect to be able to specify which version to use in the POST /mail/send request.
Hey @andyblack19 No need for versioning with the new templates we have introduced. In your account you should see an option for "Transactional" templates. There you can create one template that will serve many languages. You will likely want to take a look at the docs here and an example here.
I did read that page.. but completely missed the multiple language section! Thanks for your help
It appears that using "Design Editor" mode templates is not possible with the handlebars strategy mentioned above. If one wants to have multiple templates for different use cases with at least two different languages, are you supposed to be copy pasting the template code to each template when the general layout is changed? Why isn't there a way to have a top level shareable layouts?
Also, it would seem that you have to localize the subject of email at server side, instead of in the template content where you are already setting the template body for each language? It doesn't make sense to separate subject and body in this way. Or have I overlooked something?
Hello @raine
It appears that using "Design Editor" mode templates is not possible with the handlebars strategy mentioned above.
You are correct the specific design of the language template found here was not designed to work in the "Design Editor" mode. You could still create something similar in the "Design Editor" using a Code Module.
If one wants to have multiple templates for different use cases with at least two different languages, are you supposed to be copy pasting the template code to each template when the general layout is changed? Why isn't there a way to have a top level shareable layouts?
This is actually something that has been brought up to our engineers. I would still recommend you use the feedback button when you are logged in to your account to let our engineers know this is wanted. The more people who submit feedback like that the more likely it is that we will see an improvement like that. The feedback button is one of the best ways to get feedback directly to our engineers when it comes to anything outside of code libraries. I personally have put in a vote for something similar to what you are looking for.
Also, it would seem that you have to localize the subject of email at server side, instead of in the template content where you are already setting the template body for each language? It doesn't make sense to separate subject and body in this way. Or have I overlooked something?
I think you have overlooked something. I know from my own personal testing that handlebars work in setting the subject of a template. Though I may not be understanding your wording correctly. I know the subject has not been visually designed to support this though so it is best to create the code and content in something like a text editor and paste it into the subject field after. This is another area where using the feedback button is recommended. Please feel free to suggest what you think would be a better way of doing this.
Please correct anything I goofed on and give me further details so I can better understand.
Kyle
How does the example of multiple languages address translation of the email subject line?
@esiqveland
In the subject line in the template you would use something like this:
{{#if english}}
Hello
{{else if spanish}}
Hola
{{else if french}}
Bonjour
{{/if}}
You basically use the same structure that is in the HTML content. Please let us know if you have further questions.
Hi @kylearoberts, is there a way how to check variable value in the conditional? So instead of checking multiple variables like english or spanish, I'd just check if language variable equals en or es. This doesn't make much difference in the template itself, but it does on the backend where I have to translate language code variable into specially named variable in dynamic template data.
I checked Handlebars briefly and it doesn't seem to support it by default. But maybe SendGrid has some custom helpers built in.
@tlinhart
Thanks for the great question. As it stands right now, the system will not work that way, but we will likely have something later on that will allow something like that. When we do make such a change we will likely update our docs and examples for how to use transactional templates.
Hi, I'm currently using the new template system for my multi language emails. The main problem is the subject field limited length. Basically, my subject content is like this:
{{#if english}} Hello blah blah... {{else if spanish}} Hello blah blah... {{else if french}} Hello blah blah... {{/if}}
But there are a few problems:
- The subject field length is not enough for more than a few languages. I had to cut down the text and variable names just to stay within the limits. But this will obviously not work should we have to add a new language.
- The editor shows a single line field for entering subject which is unsuitable for working with template subjects.
- The editor subject field happily cuts down text entered from pasting. This will lead to a template error since the syntax will be wrong due to removed template scripting code
@bragma
I have run into the same issue as you. This is also not the first time we have heard this. We love getting feedback like this because it helps us improve our products. I have made sure to get your feedback to our engineering team and I can tell you this is one of the areas they want to improve things. When they get a chance to work on improvements this is likely to be one of them. Thank you again for the feedback.
@thinkingserious +1 I need localization feature
@thinkingserious huge +1 for this feature. Really nice feature to be able to deal with all the language of an e-mail within the same template but as stated previously it is not usable due to the subject limitation.
@thinkingserious mega +1 for this feature - We also need this feature, for us, the use-case is a bit different, we want to offload the creation/maintaining of templates to our marketing guys, only these people aren't programmers, so we need plain WYSIWYG templates per language. Having 1 separate version per language would be the answer to our problem.
The following would be even better:
1 - the ability to set a default version ( when no version is selected, or invalid version is provided the default version would take over )
2 - just have an extra parameter in the POST /mail/send API to add a version
We have a platform with more than 12 languages and counting (yes we like a challenge) so we need specific marketing people for different languages, they don't code so plain templates. Also, we plan on having a massive amount of users, so first setting the required template to active, then sending an email would result in concurrency problems where wrong templates will be chosen.
Thanks so much,