Solved

How can I localize the liquid date filter?

Fredydb
Shopify Partner
29 1 2

Hi!
Does someone have an idea on how to localize the liquid date filter?

I was hoping that inputing

{{ "Tuesday" | date: "%A" }}

 

Would output the correct translation of tuesday for the language the user is browsing the site in.

Thanks for your suggestions!

 

Accepted Solution (1)

Stephen2020
Shopify Partner
19 2 6

This is an accepted solution.

Hi,

Liquid will do that for you, if you use the locale files. E.g.:

In en.default.json you define:

  "date_formats": {
    "month_day_year": "%b %d, %Y",
    "weekday": "%A"
  }

And in de.json:

  "date_formats": {
    "month_day_year": "%d. %b %Y",
    "weekday": "%A"
  }

You can then do the following:

{{ "2022-05-31" | date: format: 'weekday' }}

If you browse your site in English, you will get:

Tuesday

And in German you will get:

Dienstag

View solution in original post

Replies 2 (2)

Stephen2020
Shopify Partner
19 2 6

This is an accepted solution.

Hi,

Liquid will do that for you, if you use the locale files. E.g.:

In en.default.json you define:

  "date_formats": {
    "month_day_year": "%b %d, %Y",
    "weekday": "%A"
  }

And in de.json:

  "date_formats": {
    "month_day_year": "%d. %b %Y",
    "weekday": "%A"
  }

You can then do the following:

{{ "2022-05-31" | date: format: 'weekday' }}

If you browse your site in English, you will get:

Tuesday

And in German you will get:

Dienstag

Fredydb
Shopify Partner
29 1 2

Thank you Stephen! found a way around it, but will keep this one up my sleeve.