Expand my Community achievements bar.

Converting English Months to French in ACC

Avatar

Level 3

hey!

First run at ACC here, and trying to convert the current date into French months:

 

<%= formatDate(new Date(), "%D %Bi %Y") %>,

 

So instead of 20 July 2020, i would it to say 20 juillet 2020

11 Replies

Avatar

Community Advisor

Hello @connorSlack24 ,

 

You can use moment.js in your workflow to achieve this.

 

Just download the moment.js library (from here). Then upload it in Administration > Configuration > JavaScript Codes

 

Then in your workflow you can use this code.

loadLibrary('NAMESPACE:moment.js');
var myDate=formatDate(new Date(), "%D %Bi %Y");
var frenchDate=moment(myDate, 'DDD MMMM YYYY', 'fr');

More Information on date formatting is available here: https://momentjs.com/docs/#:~:text=moment(%2212%2D25%2D,valid%20dates%20over%20invalid%20ones.

Let me know if that works.


     Manoj
     Find me on LinkedIn

Avatar

Level 3
Thank you! As i dont have access to admin panel yet, I cannot try this but i have asked my admin to load it.

Avatar

Level 3
Hey Manoj, so i got the lib installed, and im not getting an error, but im not sure how to display the date now?, I have added that script inside the email.

Avatar

Level 3

Hey Jonathon, Thanks!
Hey! My problem is the correct syntax, as i am new to eJS (coming from Freemarker) i cant seem to get it right:

 

<%= formatDate(toLocaleDateString('fr-CA), "%D %Bl, %Y") %>

 

Doesnt seem to work, but chances are im not coding it correctly.

Avatar

Level 3
Hey! My problem is the correct syntax, as i am new to eJS (coming from Freemarker) i cant seem to get it right:

Avatar

Community Advisor

Use the below, remove any js libs installed for this:

<%=
new Date().toLocaleDateString('fr-CA', {
  year: 'numeric',
  month: 'long',
  day: 'numeric'
});
%>

Thanks,

-Jon 

Avatar

Level 3

Hey Jon,

 

I added that script to my personalization block, and called that into my delivery, and i am getting this error:

Error while evaluating document

JST-310000 Error while compiling script 'content htmlContent' line 20: missing ) after argument list (line=' }); ' token='; ').
SCR-160032 Javascript&colon; error while compiling script 'content htmlContent'.
JST-310007 Unable to compile script (content htmlContent).

Avatar

Administrator

@_Manoj_Kumar_ @Jonathon_wodnicki Can any of you further help with @connorSlack24 's query?
Thanks!



Sukrity Wadhwa