N
Novu•5mo ago
Shaun

Localize Date Strings with {{dateformat}}

Hi again 🙂 As a part of my teams localization effort, we were hoping to be able to use the {{dateformat}} handlebar and pass in the subscriber locale to it in order to get the proper date format (ex MM/dd/yyyy vs dd/MM/yyyy in some countries). The docs help bot seemed to imply this was supported but looking at the handlerbar implementation, it seems locale information is not currently passed to date-fns. Is this accurate? Is there a way to accomplish what I am hoping? Thank you in advance!
19 Replies
Novu_Bot
Novu_Bot•5mo ago
@Shaun, you just advanced to level 1!
Tomer Barnea
Tomer Barnea•5mo ago
Hey @Shaun 👋 adding here some team members that can help us here 🙂 @Emil @Pawan Jain @Gali Baum , can you assist?
empe
empe•5mo ago
While I'm investigating the matter, As a workaround, you might consider adding the locale as a property to your subscriber model and then using conditional statements to render different date formats based on the locale. For example:
{{#equals subscriber.locale '2'}}
..formatted date for locale '2'..
{{else}}
..default formatted date..
{{/equals}}
{{#equals subscriber.locale '2'}}
..formatted date for locale '2'..
{{else}}
..default formatted date..
{{/equals}}
However, this approach requires you to handle the logic for each locale manually within your templates.
Gali Baum
Gali Baum•5mo ago
Hi @Shaun, we don' t have that currently within the translations feature. We do have an handlebar function, but not one that takes into account the locale. This should be part of the upcoming release, that includes the formatting by locale
empe
empe•5mo ago
@Shaun Please update us here if we were able to help, if you were expecting something else / more, let us know 🙂
Gali Baum
Gali Baum•5mo ago
As of the next release - this is how you would use a date formatting. In the translation file, for example:
{
"date": "Current date: {{date, dd/MM/yyyy}}",
"try_date": "Current date: {{date, MM/dd/yyyy}}",
"intlDateTime": "On the {{date, HH:yyyy}}"
}
{
"date": "Current date: {{date, dd/MM/yyyy}}",
"try_date": "Current date: {{date, MM/dd/yyyy}}",
"intlDateTime": "On the {{date, HH:yyyy}}"
}
In the editor:
Gali Baum
Gali Baum•5mo ago
where the date can be a string or a variable you send in the payload as {date: new Date() }
No description
Gali Baum
Gali Baum•5mo ago
The result from this example
No description
Gali Baum
Gali Baum•5mo ago
@Shaun is that the direction of what you were looking for?
Shaun
Shaun•5mo ago
Yes, that seems to give me a way to handle this 🙂 I will give that a shot, thank you!
Gali Baum
Gali Baum•5mo ago
It will be part of the next release:) it’s not there yet 😉
Shaun
Shaun•5mo ago
Oh I see, thank you! What is the best way to keep up to date when this functionality will be available?
Gali Baum
Gali Baum•5mo ago
@Dima Grossman @Paweł T. do we have an estimate on when the translations alpha version will be released ?
Paweł T.
Paweł T.•5mo ago
somewhere at the end of this week or next week
Gali Baum
Gali Baum•4mo ago
@Shaun it has been released in v.0.23.0 🙂
jvinga
jvinga•3mo ago
@Gali Baum is this also supposed to work for emails? I am trying to set it up and it displays an error in the preview...
No description
No description
Tomer Barnea
Tomer Barnea•3mo ago
Ping @Gali Baum @Pawan Jain ?
Gali Baum
Gali Baum•3mo ago
Hi @jvinga , it should work, what is the error you are getting?
Gali Baum
Gali Baum•3mo ago
Also, try setting a value for the date in the payload of the preview
No description
No description