elixir-cldr / cldr_calendars

Calendar functions for CLDR
Other
15 stars 6 forks source link

Cldr.Calendar.Duration.to_string not respecting the locale option #16

Closed petrus-jvrensburg closed 9 months ago

petrus-jvrensburg commented 1 year ago

I'm able to localise relative DateTimes, but not Calendar Durations. This is my code in a livebook cell:

now = DateTime.now!("Etc/UTC")
earlier = DateTime.add(now, -300)
Cldr.DateTime.Relative.to_string!(earlier, relative_to: now, locale: "de-DE")
|> IO.inspect()

{:ok, duration} = Cldr.Calendar.Duration.new(~D[2025-01-01], ~D[2025-12-31])
Cldr.Calendar.Duration.to_string!(duration, locale: "de-DE")
|> IO.inspect()

The output is

"vor 5 Minuten"
"11 months, 30 days"
kipcole9 commented 9 months ago

@petrus-jvrensburg, this appears fixed (although I don't recall doing the work for this) on the current version:

iex> {:ok, duration} = Cldr.Calendar.Duration.new(~D[2025-01-01], ~D[2025-12-31])
iex> Cldr.Calendar.Duration.to_string!(duration, locale: "de-DE")
"11 Monate und 30 Tage"

I will close as fixed, but please reopen if it appears unresolved for you.