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

FR: Language argument support for the date filter #3006

watarutmnh opened this issue Jun 19, 2018 · 3 comments


None yet
3 participants
Copy link

commented Jun 19, 2018

In some case I want to have the date in specific language format at site not same locale.
For example:
In Japanese site, if I write

entry.postDate|date('M j, Y')

it output in Japanese format like "6月 19, 2018".
but I want it to display "Jun 19, 2018" as in English format.

So tried...

{% set M = {'1月':'Jan', '2月':'Feb', '3月':'Mar', '4月':'Apr', '5月':'May', '6月':'Jun', '7月':'Jul', '8月':'Aug', '9月':'Sep', '10月':'Oct', '11月':'Nov', '12月':'Dec' } %}
{{ entry.postDate|date('M j, Y')|replace(M) }}

also suggested better solution by carlcs in #craft3-hlp at Slack.

{% set formatter ='de').getFormatter %}
{{ formatter.asDatetime(date, 'php:M j, Y') }}

those work OK but It would be nice to have the date filter support for a language argument.


This comment has been minimized.

Copy link

commented Jun 19, 2018

Not quite the same issue, but we have a site where we need the dates to come out in Thai, which has it's own set of numerals ( ๑๒๓๔๕๖๗๘๙๐ ). And I'm sure there are other languages with their own locale-specific sets of numerals. Not sure if that can also be covered in this request.

To be honest, though, although dates are the most common need here, we did have another site where we needed to make sure that all numbers, even in body fields, ended up in Thai, so in the end we had to run most of our Twig output fields through a macro, which achieved what we were after with dates (and everything else).


This comment has been minimized.

Copy link

commented Jun 19, 2018

There's a little precidence for this, I guess, in that the |t filter allows you to specify the target language (which will default to the current application language).


This comment has been minimized.

Copy link

commented Jun 20, 2018

…and done, for the |date, |time, and |datetime filters, for the next release.

{{ now|date(locale='en-US') }}
<!-- outputs "Jun 19, 2018" -->

{{ now|date(locale='en-GB') }}
<!-- outputs "19 Jun 2018" -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.