function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Translating Dates in Visualforce Emails to the language of the recipient



I've got a requirement for Visualforce emails to display Close dates in the email that the end user will understand based on his language.


A close date of 03.05.2014 in an email to a German user should show the month component for MAY as "MAI".




So I tried this in a Visualforce page for fun, putting year then month then day:


<apex:page standardController="Opportunity" language="de" >
<apex:outputtext value="{0,date,yyyy-MMMM-dd}"> <apex:param value="{!opportunity.CloseDate}" /> </apex:outputtext>


This prints the month in English even though the language = "de".  Disappointing but definitely not surprising.


To get a close date with the month in words in English, we've accomplished this in the past with a formula field.  



So I tried replacing this in the same formula with Custom Labels.   


1, $Label.JAN, 
2, $Label.FEB, 
3, $Label.MAR, 
4, $Label.APR, 
5, $Label.MAY, 
6, $Label.JUN, 
7, $Label.JUL, 
8, $Label.AUG, 
9, $Label.SEP, 
10, $Label.OCT, 
11, $Label.NOV, 
12, $Label.DEC, 
"None") + " " + 
TEXT(DAY(CloseDate)) +" " + 

If the page has language="de" it still comes up as English because my user settings are English.  So if this was a VF page to use while logged in, that would have taken care of it.


But this is a Visualforce email sent out by Batch Apex so the language of the user sending the batch will be different in most cases to the language of the recipient of the email.  We choose this from a language field on Contact.


So any good suggestions for having to do this without getting too clunky in a controller?  Up til now, we have been able to do all of our requirements for this without creating a controller for the Visualforce email. 



MJ Kahn / OpFocusMJ Kahn / OpFocus
Sorry, but all of the Apex system classes that do formatting use the current User's locale. You might try looking for a web service that will format a date into a given locale and language, and see about calling that from the controller.