2

I have a requirement where on workflow rules I want to send out an email in the users preferred language, Is there a way to create multi-lingual visualforce email templates?

here is the sample Visualforce email template:

<messaging:emailTemplate recipientType="User"
    relatedToType="custom_object"
    subject="Case report for Account: {!relatedTo.name}">

    <messaging:htmlEmailBody>
        <html>
            <body>

            <p>Dear {!recipient.name},</p>
            <p>Below is a list of cases related to {!relatedTo.name}.</p>
            <table border="0" >
                <tr>
                    <th>Case Number</th><th>Origin</th>
                    <th>Creator Email</th><th>Status</th>
                </tr>

            </table>
            <p/> 
            </body>
        </html>
    </messaging:htmlEmailBody>
</messaging:emailTemplate>

So wherever, you see the English text that should be translate to different language based on the user selected language perference.

sample workflow rule selecting the above email template:

enter image description here

2
  • You can try to move all your code into visualforce component, use tag Language there, and specify language somehow (as a object field etc). Inside visualforce component, use custom labels when needed developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/…
    – kurunve
    Commented Mar 2, 2017 at 16:19
  • But I am not sure if that is possible to send same email for couple of users in different language
    – kurunve
    Commented Mar 2, 2017 at 16:23

1 Answer 1

6

After doing some research I able to figured out how to achieve this, if someone has better way of doing please post it here.

1) I modified my VF email template and added attribute language="{!recipient.LanguageLocaleKey}"

2) After doing that, I created Custom Labels as shown below:

enter image description here

3) After creating the Custom Labels I just had to plug them in the VF email template as shown below.

<messaging:emailTemplate recipientType="User" language="{!recipient.LanguageLocaleKey}"
    relatedToType="custom_object"
    subject="Case report for Account: {!relatedTo.name}">

<messaging:htmlEmailBody>
    <html>
        <body>

        <p>{!$Label.Translation_Custom_Label_Line_1} {!recipient.name},</p>
        <p>{!$Label.Translation_Custom_Label_Line_2} {!relatedTo.name}.</p>
        <table border="0" >
            <tr>
                <th>{!$Label.Translation_Custom_Label_Line_3}</th> 
                <th>{!$Label.Translation_Custom_Label_Line_4}</th> 
            </tr>

        </table>
        <p/> 
        </body>
    </html>
</messaging:htmlEmailBody>

4) If you want to test it out, go back to the User account change the Language and Save the record, then go back to the Email Template and do a Send Test Email

It works fine without any issue, again if you have a better solution please let me know and hope this will help others.

You must log in to answer this question.

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