[SOLVED] The Day of Week translation

Hi! Is there a possibility to translate not only Month into another language such as in the example “Customize Dates” https://gohugo.io/content-management/multilingual/#customize-dates but also translate the Day of the Week, for example, Monday?

The correct answer:
In the folder < data> create document days.yaml with this content:
0: Sonntag
1: Montag
2: Dienstag
3: Mittwoch
4: Donnerstag
5: Freitag
6: Samstag

and use this code {{ index $.Site.Data.days (printf "%d" .Date.Weekday) }}

1 Like

It shouldn’t be hard to adapt the example from the docs. Create a new data file that contains all weekdays in a language of your choice, e.g. wochentage.toml, which means weekdays in German:

1: "Montag"
2: "Dienstag"
3: "Mittwoch"
4: "Donnerstag"
5: "Freitag"
6: "Samstag"
7: "Sonntag"

Inside you template you get the nth weekday that can be used as index to get the corresponding weekday in German:

{{ index $.Site.Data.days (printf "%d" .Date.Day) }}
1 Like

1 September - Montag, 2 October - Dienstag, 3 November - Mittwoch? 8 December = Null? :roll_eyes:
Dear Digitalcraftsman, let us clearly: how to name it, in which folder to place all of it and is this code correctly work with .Date.Day?

I should double-check the documentation of the time package. .Date.Day refers to the nth day of the month, whereas .Date.Weekday corresponds to the nth weekday.

December = Null happened because weekdays have a zero-based index, whereas months are counted (intuitively) from one upwards.

Overall, the snippet is nearly the same as the one for the translations of month names that has been linked in the introductory post. It was mentioned that wochentage.toml is a data file. Maybe it wasn’t as obvious that it belongs in the data/ folder but the next time I’ll try to be more precise in the details


A post was split to a new topic: Get the day of the week extracted from an arbitrary frontmatter date