Can I display the long form of a month in datetime display in a language other than english?

The documentation shows how to display a datetime.

I can display the full name of a month using display("[month repr:long]") which gives me e.g. October.

This is also the case when the document language is set to another language with a #set text(lang: "de").
The desired result is that this does not returns October but instead Oktober which is the German spelling ot the month.

Is there a way to get the display method to display the month in another language?

Looking at the documentation for text.lang, it says it should affect “all other things which are language-aware”.

However, there seems to be an open issue for formatting dates (or at least months) locally, #2840, but it looks like it’s blocked because of the Rust time crate.

The icu-datetime package seems to add this functionality though, but it displays the full date, as opposed to just a month:

#import "@preview/icu-datetime:0.1.2": fmt-datetime, fmt-date

#fmt-date(datetime.today(), locale: "de")

// Sonntag, 13. Oktober 2
2 Likes

Also check out #1537

1 Like

You can extract the individual parts of a datetime, providing good enough results:

#let months = ("janeiro", "fevereiro", "março", "abril", "maio", "junho", "julho", "agosto", "setembro", "outubro", "novembro", "dezembro")

#let translated-month(dt) = months.at(dt.month() - 1)

#let today = datetime.today()

#today.day() de #translated-month(today) de #today.year()

output: "14 de outubro de 2024"

For more information, see the methods at the datetime docs: Datetime Type – Typst Documentation

1 Like

Thank you! Both are great solutions for different usecases :)