I am trying to create different tokens (each language a separate token), that will display the date format in the specified language.
Examples:
English Token: March 31, 2018
French Token: 31 mars 2018
Spanish Token: 31 de marzo de 2018
Portuguese Token: 31 de março de 2018
So far, I have the English token formatted correctly but specifying a language for the other tokens is not working.
English Token:
#set( $inTimeZone = $date.getTimeZone().getTimeZone('America/New_York') )
#set( $outTimeZone = $date.getTimeZone().getTimeZone('America/New_York') )
#set( $locale = $date.getLocale() )
#set( $myDate = $convert.parseDate($lead.Member_Expire_Date,'yyyy-MM-dd',$locale,$inTimeZone) )
${date.format('d MMMM, yyyy',$myDate,$locale,$outTimeZone)}
Do we have to load a library of locales prior to defining it? Any other suggestions?
I would like to do this without web hooks.
Solved! Go to Solution.
Locales are already there. You need to instantiate Locale objects (specifically for ES and PT because there are no built-in constants for those in JRE6).
#set( $inTimeZone = $date.getTimeZone().getTimeZone('America/New_York') )
#set( $outTimeZone = $date.getTimeZone().getTimeZone('America/New_York') )
#set( $locale = $date.getLocale() )
#set( $String = $context.getClass().forName("java.lang.String") )
#set( $LocaleFrom2Part = $locale.getClass().getConstructor($String,$String))
#set( $locales = {
"en_US" : $LocaleFrom2Part.newInstance("en","US"),
"fr_FR" : $LocaleFrom2Part.newInstance("fr","FR"),
"es_ES" : $LocaleFrom2Part.newInstance("es","ES"),
"pt_PT" : $LocaleFrom2Part.newInstance("pt","PT")
})
#set( $myDate = $convert.parseDate($lead.Member_Expire_Date,'yyyy-MM-dd',$locale,$inTimeZone) )
${date.format("d MMMM, yyyy",$myDate,$locales.en_US,$outTimeZone)}
${date.format("d MMMM yyyy",$myDate,$locales.fr_FR,$outTimeZone)}
${date.format("d 'de' MMMM 'de' yyyy",$myDate,$locales.es_ES,$outTimeZone)}
${date.format("d 'de' MMMM 'de' yyyy",$myDate,$locales.pt_PT,$outTimeZone)}
I don't know why you'd use separate tokens, though. That's just way more to maintain. There should be one token, and output should be governed by some other field on the lead (i.e. their preferred locale).
Locales are already there. You need to instantiate Locale objects (specifically for ES and PT because there are no built-in constants for those in JRE6).
#set( $inTimeZone = $date.getTimeZone().getTimeZone('America/New_York') )
#set( $outTimeZone = $date.getTimeZone().getTimeZone('America/New_York') )
#set( $locale = $date.getLocale() )
#set( $String = $context.getClass().forName("java.lang.String") )
#set( $LocaleFrom2Part = $locale.getClass().getConstructor($String,$String))
#set( $locales = {
"en_US" : $LocaleFrom2Part.newInstance("en","US"),
"fr_FR" : $LocaleFrom2Part.newInstance("fr","FR"),
"es_ES" : $LocaleFrom2Part.newInstance("es","ES"),
"pt_PT" : $LocaleFrom2Part.newInstance("pt","PT")
})
#set( $myDate = $convert.parseDate($lead.Member_Expire_Date,'yyyy-MM-dd',$locale,$inTimeZone) )
${date.format("d MMMM, yyyy",$myDate,$locales.en_US,$outTimeZone)}
${date.format("d MMMM yyyy",$myDate,$locales.fr_FR,$outTimeZone)}
${date.format("d 'de' MMMM 'de' yyyy",$myDate,$locales.es_ES,$outTimeZone)}
${date.format("d 'de' MMMM 'de' yyyy",$myDate,$locales.pt_PT,$outTimeZone)}
I don't know why you'd use separate tokens, though. That's just way more to maintain. There should be one token, and output should be governed by some other field on the lead (i.e. their preferred locale).
L. Perez please check the above answer.
Thank you Sanford. This was just what I needed.
Cool, gotta do a blog post on this.