zola icon indicating copy to clipboard operation
zola copied to clipboard

`date(format=)`-Filter is not localized

Open ibotty opened this issue 4 years ago • 8 comments

Zola version: zola-0.10.1-1.fc32.x86_64

Expected Behavior

in config.toml:

default_language = 'de'
{{ "2020-07-27"  | date(format="%B") }}

is not localized: It returns "July" and not "Juli".

I am certainly missing some setting to make it all work.

ibotty avatar Jul 27 '20 09:07 ibotty

You're not missing anything, chrono - the underlying date library - is not localized and only supports English :/

Keats avatar Jul 27 '20 10:07 Keats

@ibotty You can use the translation system to translate your dates.

Personally i only "translate" the order for date numbers:

{%- if page.date -%}<time class="dt-published" datetime="{{ page.date }}">📅&nbsp;{{ page.date | date(format=trans(key="dateFormat", lang=lang)) }}</time>{%- endif -%}

With dateFormat = "%d/%m/%Y" for french and dateFormat = "%m/%d/%Y" for english.

You could apply the same logic to translate month names. You can ask around on the forum if you're stuck and/or contribute documentation when you succeed.

Note: the translation system will undergo some major changes in a future release (#1040) so it's possible you may have to rework it slightly at some point

southerntofu avatar Jul 29 '20 16:07 southerntofu

@southerntofu, thank you for the workaround for date numbers. That's the approach I used. I certainly hope, that it's not decided to need month names before chronotope/chrono#453, the pull request to chrono to add locales, lands and is integrated in zola (if neccessary).

ibotty avatar Jul 30 '20 07:07 ibotty

I did use libc-strftime in the meanwhile. It's just strftime directly from the libc

cecton avatar Jul 30 '20 17:07 cecton

So can something be done in Tera after that PR? I haven't followed/want to read the whole thread.

Keats avatar Jul 19 '21 19:07 Keats

Ah yes it has been released for some time now. Just add the feature and don't forget to pass the Locale

cecton avatar Jul 19 '21 20:07 cecton

This issue can be closed now, unless it is about setting automatically the date locale to the website's default language? (which looks difficult and not really necessary)

ZettaScript avatar Sep 04 '22 21:09 ZettaScript

Let's close it when the version of Zola containing it is released.

Keats avatar Sep 05 '22 08:09 Keats

It seems that the expected locale parameters of Tera’s date filter takes a full locale specifier (e.g. fr_FR), so you cannot pass it lang directly. Would that make sense for Zola to directly provide a locale variable somehow?

sardemff7 avatar Jan 22 '23 14:01 sardemff7

It's kinda odd to have an automatic lang -> locale conversion but maybe it does not matter for dates? Anyone has some links on that?

Keats avatar Jan 22 '23 17:01 Keats