Skip to content
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

Date locale #567

Closed
flaviotordini opened this issue Dec 11, 2022 · 7 comments
Closed

Date locale #567

flaviotordini opened this issue Dec 11, 2022 · 7 comments

Comments

@flaviotordini
Copy link

Is it possibile to format dates with the date filter in a specific language? If not, it sounds like a good feature for a templating engine.

@harttle
Copy link
Owner

harttle commented Dec 11, 2022

We have problem in JavaScript that Date doesn't support format string. We'll need localizations for this purpose, I'm thinking that we can create a separate project to port a strftime lib to Liquid date filter. like this one: https://github.com/samsonjs/strftime#locales

@pdehaan
Copy link
Contributor

pdehaan commented Dec 11, 2022

JavaScript does have an Intl.DateTimeFormat, which "enables language-sensitive date and time formatting."

@flaviotordini
Copy link
Author

In the meantime I used this:

    eleventyConfig.addFilter("localizedDate", (dateString, locale) => {
        const options = { year: 'numeric', month: 'long', day: 'numeric' };
        return new Date(dateString).toLocaleDateString(locale, options);
    });

The downside is that it does not support string patterns.

@harttle
Copy link
Owner

harttle commented Dec 12, 2022

Yes, you're right. We can customize locale date/time string in JavaScript, but not as flexible as in strftime.

Intl.DateTimeFormat and .toLocaleDateString() both support a format options parameter which contains something like dateStyle, timeStyle, year, month. While I can't find a way to implement strftime with it.

@prassie
Copy link
Contributor

prassie commented Feb 2, 2023

@harttle would an option for global/default date format help, similar to timezoneOffset?
In current code, the default format is hard coded.
With such an option, engine users will be free to set whatever format they need, however they got it (Intl, user configured, ...).

I use the similar timezoneOffset option, to get all dates in the templates converted to the required tz.

Of course, this is for the developers who setup/init the Liquid engine, and not for the template designers.

@harttle
Copy link
Owner

harttle commented Feb 4, 2023

Makes sense. Thank you @prassie for the clarification.

harttle added a commit that referenced this issue Jul 21, 2024
github-actions bot pushed a commit that referenced this issue Jul 21, 2024
# [10.16.0](v10.15.0...v10.16.0) (2024-07-21)

### Features

* locale support for date filter, [#567](#567) ([#723](#723)) ([e4aeb02](e4aeb02))
@harttle
Copy link
Owner

harttle commented Jul 21, 2024

weekday and months are now locale specific, details please check: https://liquidjs.com/filters/date.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants