1

I'm trying to use a Visualforce Email Template to translate content into another language. Even if I hard-code the language, when I click "Send Test & Verify Merge Fields", the email does not get translated.

I have set up the French language in the Translation Settings and made sure it is activated. Is there another setting or piece of setup that I'm missing?

Thanks in advance!

Here is my Visualforce code:

<messaging:emailTemplate subject="Test VF Template" recipientType="Contact" relatedToType="Innovation__c" language="fr">
<messaging:plainTextEmailBody >

   Dear {!relatedTo.Applicant_Name__c},
   This should all be in French. But its not.

</messaging:plainTextEmailBody>
</messaging:emailTemplate>
0

1 Answer 1

1

The language attribute just sets the language of the email with regards to labels.
It doesn't mean that it will take this specific template if the recipient language is French.

You need to create Custom Labels for the text you want to have translated. You can then set translated values for each of the languages that you support in those labels. In your example then the French value will be displayed.

You can also make it dynamic based on the language of the recipient with something like this:

<messaging:emailTemplate recipientType="Contact"
    relatedToType="Account"
    language="{!recipient.language__c}"
    subject="{!$Label.email_subject}"
    replyTo="[email protected]" >

    <messaging:htmlEmailBody >
    <html>
        <body>
        <p>{!$Label.email_greeting} {!recipient.name}--</p>
        <p>{!$Label.email_body}</p>
        </body>
    </html>
    </messaging:htmlEmailBody>

</messaging:emailTemplate>

This takes a custom field on Contact, language__c, which contains language keys like fr, en, de etc.

https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_compref_messaging_emailTemplate.htm

Update:

You can use parameters in your label. This way you don't need 2 labels in your example, one for 'Dear' and one for the rest of the text, but just 1.
If you define your label as 'Dear {0}, This should all be in French. But its not.', you can then use the following code to merge the {!relatedTo.Applicant_Name__c} into the label like this:

<apex:outputText value="{!$Label.YourLabelName}" >
    <apex:param value="{!relatedTo.Applicant_Name__c}" />
</apex:outputText>
3
  • Thanks @Folkert. That's disappointing to hear since I need to find a way to translate 30+ email templates into 3 different languages, so creating custom labels for all the content is not feasible nor sustainable. Any thoughts on using a custom object to store records of the email content and translating that some how? Or any other suggested approaches for solving for this problem?
    – JustinF
    Commented May 28, 2018 at 17:01
  • @JustinF Yea, it can be a pain to maintain them all, but there are some tricks to make your life easier. I'll update the answer.
    – Folkert
    Commented May 29, 2018 at 7:37
  • I had similar challenge/frustration recently - namely getting my custom label translations to work for each email using a dynamic language variable in the visualforce component. Here's my solution for my situation in case helpful: salesforce.stackexchange.com/a/337663/43223 Commented Mar 23, 2021 at 18:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .