1

is there a way how to have the same Custom Label on the email template in two different languages? What we want to achieve is to have a Visualforce email with two parts, one in the language of the contact and one in English. I would like to avoid creating duplicate Custom Labels. Following code is the way how we are using the language attribute in the email template. How can I define another language for the second custom label to show it in English? Or somehow block the language preference for the second label so it shows in default language?

<messaging:emailTemplate subject="{!$Label.Email_Subject}" recipientType="Contact" language="{!recipient.Preferred_Language_Code__c}">
    <messaging:htmlEmailBody>
        {!$Label.Text} <! -- in Contact language-->
        {!$Label.Text} <! -- in English -->
    </messaging:htmlEmailBody>
</messaging:emailTemplate>
1

There is a one way to do that using custom visualforce components.

It is possible to use language property for visualforce component, like referenced in documentation here.

As a result, it is possible to create visualforce component, called MyLabel that is similar to next:

<apex:component access="global" language="{!lang}" >
    <apex:attribute name="lang" type="String" description="Language string"/>
    {!$Label.Text}
</apex:component>

So, it can be used in visualforce email template as following:

<messaging:emailTemplate subject="{!$Label.Email_Subject}" recipientType="Contact" language="{!recipient.Preferred_Language_Code__c}">
    <messaging:htmlEmailBody>
        <c:MyLabel language="en_US">
        <c:MyLabel language="{!recipient.Preferred_Language_Code__c}">
        <c:MyLabel language="nl_NL">
    </messaging:htmlEmailBody>
</messaging:emailTemplate>

In that case, first label will be always in English, last one always in Dutch, and middle one will be dependent on Preferred_Language_Code__c.

0

I had a similar requirement in past. But there is no default way to do this. This is still in an idea stage.

If you read the Idea page there is an interesting workaround given by KK Ramamoorthy in the comments. You can use this custom API class (few lines of code) to get this feature.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.