Translations and localized date formatting.
All user-facing strings of the chart (column titles, lightbox labels,
toolbar tooltips, month and day names...) live in the GanttEx.Gettext
backend. Date patterns are translatable too, so each language can choose
its own order and separators.
Supported locales
en, es, fr, it, de, pt, pt_BR, ja
Locale names are normalized, so "pt-BR", "es-CL" or :fr work too.
Date patterns
Patterns use Calendar.strftime/3 directives with localized month and day
names, plus %V for the ISO week number. Named patterns (atoms) resolve to
the translated pattern of the locale:
iex> GanttEx.I18n.format(~N[2025-03-07 00:00:00], :month_year, "es")
"marzo 2025"
iex> GanttEx.I18n.format(~N[2025-03-07 00:00:00], :date, "de")
"07.03.2025"
iex> GanttEx.I18n.format(~N[2025-03-07 00:00:00], "%a %-d · W%V", "fr")
"ven. 7 · W10"
iex> GanttEx.I18n.format(~N[2025-03-07 00:00:00], :month_year, "ja")
"2025年3月"
Summary
Types
A locale name such as "es" or "pt_BR".
A date pattern: a named pattern, a strftime string or a function.
Functions
Returns localized month and weekday names as tuples.
Returns the confirmation message to delete several tasks.
Returns a translated duration such as "3 days".
Formats a datetime with a pattern (see the module docs).
Returns a 2-arity formatting function bound to locale.
Returns every UI label of the chart, translated.
Returns the bundled locales.
Normalizes a locale name, falling back to the language and then to "en".
Returns the translated pattern for a named date format.
Runs fun with the GanttEx backend set to locale.
Types
@type locale() :: String.t()
A locale name such as "es" or "pt_BR".
@type pattern() :: atom() | String.t() | (NaiveDateTime.t() -> String.t()) | (NaiveDateTime.t(), locale() -> String.t())
A date pattern: a named pattern, a strftime string or a function.
Functions
@spec calendar_names(locale()) :: %{ months: tuple(), months_short: tuple(), weekdays: tuple(), weekdays_short: tuple() }
Returns localized month and weekday names as tuples.
iex> GanttEx.I18n.calendar_names("it").months |> elem(0)
"gennaio"
iex> GanttEx.I18n.calendar_names("de").weekdays_short |> elem(6)
"So"
@spec confirm_delete_tasks(pos_integer(), locale()) :: String.t()
Returns the confirmation message to delete several tasks.
iex> GanttEx.I18n.confirm_delete_tasks(3, "en")
"Are you sure you want to delete these 3 tasks?"
@spec duration(integer(), GanttEx.Dates.unit(), locale()) :: String.t()
Returns a translated duration such as "3 days".
iex> GanttEx.I18n.duration(3, :day, "es")
"3 días"
iex> GanttEx.I18n.duration(1, :hour, "en")
"1 hour"
@spec format(NaiveDateTime.t() | Date.t() | nil, pattern(), locale()) :: String.t()
Formats a datetime with a pattern (see the module docs).
@spec formatter(locale()) :: (NaiveDateTime.t() | Date.t() | nil, pattern() -> String.t())
Returns a 2-arity formatting function bound to locale.
Translations are looked up once, which makes it the efficient choice to format many dates (for example all the cells of a time scale).
iex> format = GanttEx.I18n.formatter("pt_BR")
iex> format.(~N[2025-12-01 00:00:00], :month_year)
"dezembro 2025"
Returns every UI label of the chart, translated.
iex> GanttEx.I18n.labels("es").save
"Guardar"
iex> GanttEx.I18n.labels("en").task_name
"Task name"
@spec locales() :: [locale()]
Returns the bundled locales.
iex> GanttEx.I18n.locales()
["en", "es", "fr", "it", "de", "pt", "pt_BR", "ja"]
Normalizes a locale name, falling back to the language and then to "en".
iex> GanttEx.I18n.normalize_locale("pt-br")
"pt_BR"
iex> GanttEx.I18n.normalize_locale("es-CL")
"es"
iex> GanttEx.I18n.normalize_locale(:ja)
"ja"
iex> GanttEx.I18n.normalize_locale("xx")
"en"
Returns the translated pattern for a named date format.
Available names: :date, :datetime, :time, :day, :weekday_day,
:day_month, :weekday_date, :month_year, :month, :year and
:quarter.
iex> GanttEx.I18n.pattern(:date, "en")
"%m/%d/%Y"
iex> GanttEx.I18n.pattern(:quarter, "es")
"T%q"
@spec with_locale(locale(), (-> result)) :: result when result: var
Runs fun with the GanttEx backend set to locale.