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

Localize date decorator #209

Open
jariz opened this issue Jan 18, 2019 · 6 comments
Open

Localize date decorator #209

jariz opened this issue Jan 18, 2019 · 6 comments

Comments

@jariz
Copy link

jariz commented Jan 18, 2019

Currently dates are always returned in English (or perhaps whatever the server default is?)
It'd be really great if dates returned would be returned in either the same language as the site where the entry comes from, or if you could at least manually specify a language through an extra argument.

@markhuot
Copy link
Owner

That makes sense. Could you please provide a GraphQL snippet showing how you are currently using the @date directive where it doesn't work?

@jariz
Copy link
Author

jariz commented Jan 18, 2019

My site language:

Query:

query {
  entry (type:News, site:"nl") {
    ... on News {
      date @date(as: "j F Y")
    }
  }
}
{
  "data": {
    "entry": {
      "date": "1 January 2019"
    }
  }
}

Expected output: (date format should match site's locale)

{
  "data": {
    "entry": {
      "date": "1 januari 2019"
    }
  }
}

@markhuot
Copy link
Owner

Yup, makes sense. Do you know if Craft does this natively in Twig templates? e.g., does this give you what you would expect in Twig for an entry on your nl site?

{{ entry.postDate|date('j F Y') }}

@jariz
Copy link
Author

jariz commented Jan 18, 2019

Seems to work as expected:

{{ 1547830750|date('j F Y') }}

@markhuot
Copy link
Owner

This is available on the dev-master branch and will go out with the next release. Note there are two updates here,

  1. All @date(as: formatting should now use the locale of the entry that is being formatted
  2. If you want to override this you can pass in a locale such as @date(as: "j F Y", locale: "nl")

@jariz
Copy link
Author

jariz commented Jan 23, 2019

Great, thanks @markhuot !

seamofreality pushed a commit to djfarly/craftql that referenced this issue Jul 3, 2019
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

2 participants