Localization of time.Time values

i have in config timeZone = “Europe/Zurich” and in frontmatter of page: vertretungfrom: 2023-04-17
but this code :

    {{ $vervon := dateFormat "Mon. 02. Jan. 2006" .Params.Vertretungfrom }}
    <div>{{ (time .Params.Vertretungfrom).Weekday }}</div>

gives : Monday

i expect the german version: Montag

is this a bug, planned behavior or am i doing something wrong?

edit:

languageCode = “de-CH”

I’m not sure what to call it, but the time function returns a time.Time value from Go’s std library and there’s no localization support there.

Curretnly, you need to use the time.Format func to get language support:

Note that the above will respect the timezone setting in your site (or language) config.

oke. tried this

5:{{ time.Format "Monday, Jan 2, 2006" "2015-01-21" }}

according to your advice , should give back “time.Format` returns a localized string for the current language.”

what i get is:

image

??? interpretation ???

markdown

---
title: About
vertretungfrom: 2023-04-17
---

site configuration

defaultContentLanguage = 'de-ch'
timeZone = 'Europe/Zurich'

template

{{ time.Format "Monday, Jan 2, 2006" .Params.vertretungfrom }}

rendered

Montag, Apr. 17, 2023

languageCode doesn’t do what you think it does.

1 Like

nice. thank you! :ok_hand:

    <!-- datumswerte fuer anzeige formatieren -->
    {{ $vervon := dateFormat "02. 01. 2006" .Params.Vertretungfrom }}

    {{/* versuch mit lokalisieren geht nur mit defaultContentLanguage = "de-ch" in cfg */}}
    <div>1:{{ (time .Params.Vertretungfrom).Weekday }}| {{(time .Params.Vertretungfrom).Month}} </div>
    <div>2:{{ $vervon }}</div>
    {{ $vervonloc := .Params.Vertretungfrom | time.Format ":date_full" }}
    <div>3:{{ $vervonloc }}</div>
    <div>4:{{ dateFormat "Mon 02. 01. 2006" .Params.Vertretungfrom }}</div>
    <div>5:{{ time.Format "Monday, Jan 2, 2006" "2015-01-21" }}</div>
    {{/* --- */}}

gives now

image

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.