betty.localizer module

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

final class betty.localizer.Localizer

Bases: object

Localize a variety of data into a specific locale.

__init__(locale: ResolvableLocale, translations: NullTranslations, /)
gettext(message: str, /) LocalizedStr

Like gettext.gettext().

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

locale: Final[Locale]

The locale.

localize(localizable: ResolvableLocalizable, /) LocalizedStr

Ensure that a localizable-like value is or is made to be localized.

ngettext(message_singular: str, message_plural: str, n: int, /) LocalizedStr

Like gettext.ngettext().

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

npgettext(context: str, message_singular: str, message_plural: str, n: int, /) LocalizedStr

Like gettext.npgettext().

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

pgettext(context: str, message: str, /) LocalizedStr

Like gettext.pgettext().

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

final class betty.localizer.LocalizerRepository

Bases: object

Exposes the available localizers.

This is thread-safe, which means you can safely use this between different threads.

__init__(translations: TranslationRepository, /)
get(locale: ResolvableLocale, /) Localizer

Get the localizer for the given locale.