zola
zola copied to clipboard
`date(format=)`-Filter is not localized
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.
You're not missing anything, chrono
- the underlying date library - is not localized and only supports English :/
@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 }}">📅 {{ 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, 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).
I did use libc-strftime in the meanwhile. It's just strftime directly from the libc
So can something be done in Tera after that PR? I haven't followed/want to read the whole thread.
Ah yes it has been released for some time now. Just add the feature and don't forget to pass the Locale
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)
Let's close it when the version of Zola containing it is released.
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?
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?