Translatable Email Templates

DEVELOPER HOME

This document assumes that you are familiar with Translation Workbench available from Salesforce.com and that the required languages have been added to the list of supported languages.

The process of translating the templates is as follows:

  1. Add custom labels
  2. Add translation
  3. Edit email templates to use custom labels
  4. Specify the language to use to render the email message

1. Add custom labels

Custom labels are custom text values that can be accessed from email templates. The values can be translated into any language Salesforce.com supports.

  1. Go to Setup | Create | Custom Labels.
  2. Click New Custom Label to create a new label.
  3. In the Short Description text box, enter an easily recognizable term to identify this custom label. This description is used in merge fields.
  4. In the Name text box, enter the name the label uses. This value will be used in the email template to reference the custom label.
  5. In the Value text box, enter the text to be displayed. This value can be translated into any language that Salesforce.com supports.
  6. Click Save.
  7. Repeat the process for all the labels you want to translate.

2. Add translation

  1. Go to Setup | Create | Custom Labels.
  2. Select the custom label name to open the label.
  3. In the Translations related list, click New to enter a new translation.
  4. Select the Language you are translating into.
  5. Enter the Translation Text. This text overrides the value specified in the label's Value field when a user's default language is the translation language.
  6. Click Save.
  7. Repeat the process for all the labels you want to translate.

3. Edit email templates to use custom labels

  1. Go to Setup | Email | My Templates.
  2. Select the email template to be edited.
  3. Click Edit Template.
  4. Locate the text which needs to be translated and for which a label has already been entered.
  5. Replace the text with {!$Label.labelname} where labelname is the name of the label.

Example:

Billing Address needs to be translated and a label by the name 'labelBillingAddress' has been created for the same.

In the template, the Billing Address is written as follows:

<apex:variable var="lblBillingAddress" value="Billing Address" />

To use the label change this to:

<apex:variable var="lblBillingAddress" value="{!$Label.labelBillingAddress}"/>


As another example, you can change a literal value within the Visualforce markup like this:

<td>My Label</td>

To use a created label called MyLabel, instead of a literal, change this to:

<td>{!Label.MyLabel}</td>


4. Specify the language to use to render the email message

For this stage you must decide which object will contain the language to be used to render the email. Valid values for the Language field are Salesforce.com supported language keys, for example, "en" or “fr". For the purpose of this document we have assumed that you store this on the Account object.

To add the Language field to Account:

  1. Go to Setup | Customize | Accounts | Fields.
  2. Click New in the 'Account Custom Fields & Relationships' section.
  3. Select 'Text' on the screen and click Next.
  4. In the field label field type Language and in the Length type 10 and click Next
  5. Select the field level security and click Next
  6. Select the page layouts where this field needs to be displayed and click Save.
  7. Now edit the email template to add the language, as described in Section 3 above.
  8. Then add language="{!relatedTo.c2g__Account__r.Language__c}” to the tag at the top.

Example:

The following line:

<messaging:emailTemplate subject="Your Invoice from {!relatedTo.c2g__OwnerCompany__r.Name}" recipientType="User" relatedToType="c2g__codaInvoice__c" >

Should be modified to:

<messaging:emailTemplate subject="Your Invoice from {!relatedTo.c2g__OwnerCompany__r.Name}" language="{!relatedTo.c2g__Account__r.Language__c}" recipientType="User" relatedToType="c2g__codaInvoice__c" >