GanttEx.I18n (GanttEx v0.1.0)

Copy Markdown View Source

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

locale()

@type locale() :: String.t()

A locale name such as "es" or "pt_BR".

pattern()

@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

calendar_names(locale)

@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"

confirm_delete_tasks(count, locale)

@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?"

duration(count, unit, locale)

@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"

format(datetime, pattern, locale)

@spec format(NaiveDateTime.t() | Date.t() | nil, pattern(), locale()) :: String.t()

Formats a datetime with a pattern (see the module docs).

formatter(locale)

@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"

labels(locale)

@spec labels(locale()) :: %{required(atom()) => String.t()}

Returns every UI label of the chart, translated.

iex> GanttEx.I18n.labels("es").save
"Guardar"

iex> GanttEx.I18n.labels("en").task_name
"Task name"

locales()

@spec locales() :: [locale()]

Returns the bundled locales.

iex> GanttEx.I18n.locales()
["en", "es", "fr", "it", "de", "pt", "pt_BR", "ja"]

normalize_locale(locale)

@spec normalize_locale(term()) :: locale()

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"

pattern(name, locale)

@spec pattern(atom(), locale()) :: String.t()

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"

with_locale(locale, fun)

@spec with_locale(locale(), (-> result)) :: result when result: var

Runs fun with the GanttEx backend set to locale.