PhoenixKitProjects.L10n (PhoenixKitProjects v0.2.1)

Copy Markdown View Source

Tiny locale-aware date/time formatting helpers used by the projects UI.

Unlike Calendar.strftime(d, "%b %d, %Y"), the output of these helpers is safe to translate: the three-letter month labels and the surrounding string template all go through Gettext.

The 12 month labels are intentionally listed as separate gettext/1 calls so the string-extraction task picks them up into the .pot file. Don't collapse them into a map-based lookup.

Summary

Functions

The current content-display language code.

Formats a Date/DateTime as Mon DD, YYYY. Returns nil for nil.

Formats as Mon DD, YYYY at HH:MM. For DateTimes.

Formats as Mon DD HH:MM — month, day, and time only.

24-hour time string as HH:MM (locale-neutral).

Short 3-letter month name, translated (Jan, Feb, ...).

True when translations matches the documented JSONB shape

Functions

current_content_lang()

@spec current_content_lang() :: String.t() | nil

The current content-display language code.

Reads Gettext.get_locale/1 against the parent app's gettext backend — that's the locale Phoenix's pipeline set on the URL prefix (/bs/..."bs"). Used by the localized-read helpers on schemas to pick the right entry from the translations JSONB; the helpers themselves fall back to the primary-language column when the locale has no override or is nil, so this never needs to validate the result against enabled_languages/0.

format_date(dt)

Formats a Date/DateTime as Mon DD, YYYY. Returns nil for nil.

format_datetime(dt)

Formats as Mon DD, YYYY at HH:MM. For DateTimes.

format_month_day_time(dt)

Formats as Mon DD HH:MM — month, day, and time only.

format_time(date_time)

24-hour time string as HH:MM (locale-neutral).

short_month(int)

Short 3-letter month name, translated (Jan, Feb, ...).

valid_translations_shape?(map)

@spec valid_translations_shape?(any()) :: boolean()

True when translations matches the documented JSONB shape:

%{optional(String.t()) => %{optional(String.t()) => String.t()}}

i.e. an outer map keyed by language code ("es-ES") whose values are maps keyed by translatable field name ("name") with string values. %{} and nil are valid (empty / unset). Used by every schema with a translations column to add a changeset-level guard so a programmatic caller can't persist garbage that the read helpers would silently fall back through.