Expand my Community achievements bar.

Announcing the launch of new sub-community for Campaign Web UI to cater specifically to the needs of Campaign Web UI users!
SOLVED

How to translate small piece of content within email template body

Avatar

Level 2

Hi everyone,

 

I'm rendering dynamic content using JavaScript and it is in English for one email delivery. I want to use same JavaScript for content that should be in another language.

 

For example, I'm displaying month name dynamically in email subject as well as email body in English. I want to display the same in French. I'm newbie with ACM. Can anyone help me how I can do that?

 

I'm using following snippet for email subject for EN -

<%= formatDate(new Date(), "%Bl") %>

 

And following snippet for email body for EN -

 

<%
function daysInMonth(today) {
return new Date(today.getFullYear(), today.getMonth()+1, 0).getDate();
}
var today = new Date();
%>

<%= daysInMonth(today) %> <%= formatDate (today, "%Bl") %>, <%= formatDate (today, "%4Y") %>

 

I want to display the month's name in French in subject as well as email body.

 

English and French email deliveries are independent so no condition is required.

 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

try this 

Last day of the month is:   
      <%
function daysInMonth(today) {
     return new Date(today.getFullYear(), today.getMonth(), 0).getDate();
}


function month_fr(today){
   var monthFr = ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aout", "Septembre", "Octobre","Novembre","Décembre"];
   var thisMonthFr = monthFr[today.getMonth()];
   return thisMonthFr.toString();
}

var today = new Date();

%>

<%= daysInMonth(today) %> <%= month_fr(today) %>, <%= formatDate (today, "%4Y") %>  

 



David Kangni

View solution in original post

9 Replies

Avatar

Community Advisor

Hi , 

 

One way is to use personalization block. You need to predefined text over there with different language you want to use based on some conditions and then you can use your defined personalization block in email delivery. 

 

For more information on how to use personalization block please refer below link : 

https://experienceleague.adobe.com/docs/campaign-classic-learn/tutorials/sending-messages/email-chan...

 

Also, another way is - within email delivery you can create conditional content , where you'd specify a rule according to the recipient's preferred language, or country

 

I hope this helps. 

 

Thanks,
Kapil

Avatar

Level 2

Hi Kapil,

 

Thank you for your reply.

 

I have seen this video and this helped me understand how to use blocks.

 

I'm having 2 different deliveries as per language preference so there isn't use of conditional statement. But I'm trying to figure out how to use JS specific code so that I could have month's name in French in email body as well as subject. 

 

JS Code I pasted above worked in a simple HTML but it doesn't work in ACM as it doesn't support toLocale. Can you please help with that?

 

 

Avatar

Community Advisor

Hi,

You will need to import a javascript library such as moment js and call this js in your deliveries.

 

 you can find an example here 

 

Thanks,

David



David Kangni

Avatar

Level 2

Hi David,

 

Thank you for the reply. Isn't it possible to do this without using any external libraries?

 

I tried to use the following code, but it didn't work out:

 

Last day of the month is:   
      <%
function daysInMonth(today) {
     return new Date(today.getFullYear(), today.getMonth(), 0).getDate();
}


function month_fr(today){
   var monthFr:["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aout", "Septembre", "Octobre","Novembre","Décembre"];
   var thisMonthFr = monthFr[today.getMonth()];
   return thisMonthFr.toString();
} var today = new Date(); %> <%= daysInMonth(today) %> <%= month_fr(today) %>, <%= formatDate (today, "%4Y") %>  

Can you please tell me what might be the issue ? 

Avatar

Correct answer by
Community Advisor

try this 

Last day of the month is:   
      <%
function daysInMonth(today) {
     return new Date(today.getFullYear(), today.getMonth(), 0).getDate();
}


function month_fr(today){
   var monthFr = ["Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Aout", "Septembre", "Octobre","Novembre","Décembre"];
   var thisMonthFr = monthFr[today.getMonth()];
   return thisMonthFr.toString();
}

var today = new Date();

%>

<%= daysInMonth(today) %> <%= month_fr(today) %>, <%= formatDate (today, "%4Y") %>  

 



David Kangni

Avatar

Level 2

This worked. I noticed the difference and what was the issue. Thank you

Avatar

Administrator

Hi @vinay049,

Was the given solution helpful to resolve your query or do you still need more help here? Do let us know.

Thanks!



Sukrity Wadhwa

Avatar

Administrator

Great! Thanks for letting us know.

 



Sukrity Wadhwa