betty.locale.localizer module

Localizers provide a wide range of localization utilities through a single entry point.

class betty.locale.localizer.Localizer[source]

Bases: object

Provide localization functionality for a specific locale.

__init__(locale: str, translations: NullTranslations)[source]
format_date(date: Date) str[source]

Format a date to a human-readable string.

format_date_range(date_range: DateRange) str[source]

Format a date range to a human-readable string.

format_datetime_datetime(datetime_datetime: datetime) str[source]

Format a datetime date to a human-readable string.

format_datey(date: Date | DateRange) str[source]

Format a datey value into a human-readable string.

gettext(message: str) str[source]

Like gettext.gettext().

Arguments are identical to those of gettext.gettext().

property locale: str

The locale.

ngettext(message_singular: str, message_plural: str, n: int) str[source]

Like gettext.ngettext().

Arguments are identical to those of gettext.ngettext().

npgettext(context: str, message_singular: str, message_plural: str, n: int) str[source]

Like gettext.npgettext().

Arguments are identical to those of gettext.npgettext().

pgettext(context: str, message: str) str[source]

Like gettext.pgettext().

Arguments are identical to those of gettext.pgettext().

final class betty.locale.localizer.LocalizerRepository[source]

Bases: object

Exposes the available localizers.

__init__(assets: AssetRepository)[source]
async coverage(locale: str | Locale) tuple[int, int][source]

Get the translation coverage for the given locale.

Returns:

A 2-tuple of the number of available translations and the number of translatable source strings.

async get(locale: str | Locale) Localizer[source]

Get the localizer for the given locale.

async get_negotiated(*preferred_locales: str) Localizer[source]

Get the best matching available locale for the given preferred locales.

property locales: Iterator[str]

The available locales.