PhoenixLiveCalendar.Utils.I18n (PhoenixLiveCalendar v0.1.0)

Copy Markdown View Source

Internationalization helpers for calendar labels, day names, month names, and date/time formatting.

Provides default English translations with full override support via a translations map. Consumers can either:

  1. Pass a translations map to override specific labels
  2. Use Gettext in their own app and pass translated strings directly

Day numbering

Uses ISO day numbering: 1 = Monday, 7 = Sunday.

Examples

# Default English
I18n.day_name(1)
#=> "Monday"

# With custom translations
translations = %{day_names: %{1 => "Lundi", 2 => "Mardi", ...}}
I18n.day_name(1, translations)
#=> "Lundi"

# Short names
I18n.day_name_short(1)
#=> "Mon"

Summary

Functions

Returns the full day name for an ISO day number (1-7).

Returns the narrow day name (1 letter).

Returns the abbreviated day name (3 letters).

Formats a date for display in list/agenda views.

Formats a time value for display.

Formats a title string for the calendar header based on view mode and date.

Returns a translated label string.

Returns the full month name.

Returns the abbreviated month name.

Returns ordered full day names for a week.

Returns ordered narrow day names for a week.

Returns ordered day names for a week, starting from the given week start day.

Types

translations()

@type translations() :: %{
  optional(:day_names) => %{required(1..7) => String.t()},
  optional(:day_names_short) => %{required(1..7) => String.t()},
  optional(:day_names_narrow) => %{required(1..7) => String.t()},
  optional(:month_names) => %{required(1..12) => String.t()},
  optional(:month_names_short) => %{required(1..12) => String.t()},
  optional(:labels) => %{required(atom()) => String.t()}
}

Functions

day_name(day, translations \\ %{})

@spec day_name(1..7, translations()) :: String.t()

Returns the full day name for an ISO day number (1-7).

day_name_narrow(day, translations \\ %{})

@spec day_name_narrow(1..7, translations()) :: String.t()

Returns the narrow day name (1 letter).

day_name_short(day, translations \\ %{})

@spec day_name_short(1..7, translations()) :: String.t()

Returns the abbreviated day name (3 letters).

format_date(date, translations \\ %{})

@spec format_date(Date.t(), translations()) :: String.t()

Formats a date for display in list/agenda views.

Examples

iex> I18n.format_date(~D[2026-04-15])
"Wed, Apr 15"

format_time(time, opts \\ [])

@spec format_time(
  Time.t(),
  keyword()
) :: String.t()

Formats a time value for display.

Options

  • format:h24 (default) or :h12

Examples

iex> I18n.format_time(~T[14:30:00])
"14:30"

iex> I18n.format_time(~T[14:30:00], format: :h12)
"2:30 PM"

format_title(view, date, opts \\ [])

@spec format_title(atom(), Date.t(), keyword()) :: String.t()

Formats a title string for the calendar header based on view mode and date.

Examples

iex> I18n.format_title(:month, ~D[2026-04-15])
"April 2026"

iex> I18n.format_title(:week, ~D[2026-04-15])
"Apr 13 – 19, 2026"

iex> I18n.format_title(:day, ~D[2026-04-15])
"Wednesday, April 15, 2026"

iex> I18n.format_title(:year, ~D[2026-04-15])
"2026"

label(key, translations \\ %{}, bindings \\ %{})

@spec label(atom(), translations(), map()) :: String.t()

Returns a translated label string.

Supports interpolation with a bindings map.

Examples

iex> I18n.label(:today)
"Today"

iex> I18n.label(:more, %{}, %{count: 5})
"+5 more"

month_name(month, translations \\ %{})

@spec month_name(1..12, translations()) :: String.t()

Returns the full month name.

month_name_short(month, translations \\ %{})

@spec month_name_short(1..12, translations()) :: String.t()

Returns the abbreviated month name.

ordered_day_names(week_start \\ 1, translations \\ %{})

@spec ordered_day_names(1..7, translations()) :: [String.t()]

Returns ordered full day names for a week.

ordered_day_names_narrow(week_start \\ 1, translations \\ %{})

@spec ordered_day_names_narrow(1..7, translations()) :: [String.t()]

Returns ordered narrow day names for a week.

ordered_day_names_short(week_start \\ 1, translations \\ %{})

@spec ordered_day_names_short(1..7, translations()) :: [String.t()]

Returns ordered day names for a week, starting from the given week start day.

Examples

iex> I18n.ordered_day_names_short(1)
["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"]

iex> I18n.ordered_day_names_short(7)
["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"]