-
-
Notifications
You must be signed in to change notification settings - Fork 139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling localization for data? #614
Comments
Hi @HiImJulien , I would recommend your current solution too. Because template engine has no context about user's preference, it's not possible to format the date in helper unless you give user's preference as data to template. It will be identical to do it in backend. (Note that template rendering also happens in backend). |
My bad, it's less about the user preference than the "template preference". Would it be possible to access the underlying value using a helper e.g.:
or
or even
Or is the data serialized before the helper can access them? |
I see. Thank you for clarification. But before we send data into template's rendering process, it has to be converted to |
And I again, I failed to express my intent clearly 😅. I think I have an idea for an workaround: The basic idea is to use the serde's Then create a custom helper fn to_date_str(timestamp: i64, fmt: String) -> String {
let datetime = DateTime::from_timestamp(timestamp);
return datetime.format(fmt);
} This would allow me to do something like this {{ to_date_str email.date "DD.MM.YYYY" }}
What confuses me, however, is when you are taking a look at the example. On line 10, there is this line: handlebars_helper!(date: |dt: OffsetDateTime| dt.format(&parse("[year]-[month]-[day]").unwrap()).unwrap()); How can the helper access a value of type |
Hey there!
I have two email templates A and B. A is indented for an international audience whereas B is targeted at a German audience.
Both templates provide a placeholder to set the date of the generated email. The backend represents the timestamp using
chrono::DateTime<Utc>
. This results in strings such as2023-10-11T22:11:27.902255300Z
whereas strings such as11.10.2023
or10/11/2023
are desired. Strings such as11th March 23
would also be a possibility.My current workaround is to pass a localized string, which requires the backend to have knowledge of the preferred format.
Is it possible to control the serialization process (with
handlebars or the rhai extensions) to achieve a desired outcome?
Thanks in advance!
The text was updated successfully, but these errors were encountered: