betty.locale.localizer module - Betty 0.4.0a4 documentation

Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# betty.locale.localizer module

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

class betty.locale.localizer.Localizer

  Bases: `object`

  Provide localization functionality for a specific locale.

  __init__(locale: str, translations: NullTranslations)
  format_date(date: Date) → str

    Format a date to a human-readable string.

  format_date_range(date_range: DateRange) → str

    Format a date range to a human-readable string.

  format_datetime_datetime(datetime_datetime: datetime) → str

    Format a datetime date to a human-readable string.

  format_datey(date: Date | DateRange) → str

    Format a datey value into a human-readable string.

  gettext(message: str) → str

    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

    Like `gettext.ngettext()`.

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

  npgettext(context: str, message_singular: str, message_plural: str, n: int) → str

    Like `gettext.npgettext()`.

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

  pgettext(context: str, message: str) → str

    Like `gettext.pgettext()`.

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

final class betty.locale.localizer.LocalizerRepository

  Bases: `object`

  Exposes the available localizers.

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

    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

    Get the localizer for the given locale.

  async get_negotiated(*preferred_locales: str) → Localizer

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

  property locales: Iterator[str]

    The available locales.