madrilene / eleventy-excellent

Eleventy starter based on the workflow suggested by Andy Bell's buildexcellentwebsit.es.
https://eleventy-excellent.netlify.app/
Other
382 stars 69 forks source link

Date language #15

Closed phillocoder closed 1 year ago

phillocoder commented 1 year ago

Is there any way to change the language of the blog post dates from english to something else? I tried things for some time now but I can't seem to figure out any solution. Thanks

madrilene commented 1 year ago

Hey, yeah, that's not a problem. You can see on my website (which is structured very similar) how to solve this. dayjs comes with locales, you can call them in the filter configs.

https://github.com/madrilene/lenesaile.com/blob/main/config/filters/index.js#L3 https://github.com/madrilene/lenesaile.com/blob/main/config/filters/index.js#L103

You then import the new filter into your config file

https://github.com/madrilene/lenesaile.com/blob/main/.eleventy.js#L28 https://github.com/madrilene/lenesaile.com/blob/main/.eleventy.js#L114

You can then apply the filter directly here (if you only have one language): https://github.com/madrilene/eleventy-excellent/blob/main/src/_includes/partials/date.njk

<time datetime="{{ definedDate | toIsoString }}">
  {{
    definedDate | formatDateDE('D. MMMM YYYY')
  }}
</time>

My site is multilingual, but for this to work you have to set some more things.

https://github.com/madrilene/lenesaile.com/blob/a8201804290ec1d7955dbadd79cfd4ab5aa1ac61/src/_includes/partials/date.njk#L4-L7

https://www.lenesaile.com/en/blog/internationalization-with-eleventy-20-and-netlify/

phillocoder commented 1 year ago

Hey, yeah, that's not a problem. You can see on my website (which is structured very similar) how to solve this. dayjs comes with locales, you can call them in the filter configs.

https://github.com/madrilene/lenesaile.com/blob/main/config/filters/index.js#L3 https://github.com/madrilene/lenesaile.com/blob/main/config/filters/index.js#L103

You then import the new filter into your config file

https://github.com/madrilene/lenesaile.com/blob/main/.eleventy.js#L28 https://github.com/madrilene/lenesaile.com/blob/main/.eleventy.js#L114

You can then apply the filter directly here (if you only have one language): https://github.com/madrilene/eleventy-excellent/blob/main/src/_includes/partials/date.njk

<time datetime="{{ definedDate | toIsoString }}">
  {{
    definedDate | formatDateDE('D. MMMM YYYY')
  }}
</time>

My site is multilingual, but for this to work you have to set some more things.

https://github.com/madrilene/lenesaile.com/blob/a8201804290ec1d7955dbadd79cfd4ab5aa1ac61/src/_includes/partials/date.njk#L4-L7

https://www.lenesaile.com/en/blog/internationalization-with-eleventy-20-and-netlify/

Hello, thanks for your help. The first two steps are working, but when I change the date.njk the build fails with a template render error: (./src/_includes/partial/date.njk)

madrilene commented 1 year ago

I'd need to see your code!

madrilene commented 1 year ago

(did you export the filter?) https://github.com/madrilene/lenesaile.com/blob/main/config/filters/index.js#L218

phillocoder commented 1 year ago

(did you export the filter?) https://github.com/madrilene/lenesaile.com/blob/main/config/filters/index.js#L218

That's it, I think. Thank you very much