betty.gettext module#

Manage translations of built-in translatable strings.

final class betty.gettext.MoTranslations#

Bases: Translations

Translations from *.mo file data.

__init__(locale: Locale, mo: bytes, /)#
gettext(message: str, /) LocalizedStr | None#

Like gettext.gettext().

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

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

Like gettext.ngettext().

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

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

Like gettext.npgettext().

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

pgettext(context: str, message: str, /) LocalizedStr | None#

Like gettext.pgettext().

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

class betty.gettext.Translations#

Bases: ABC

A set of translations.

abstractmethod gettext(message: str, /) LocalizedStr | None#

Like gettext.gettext().

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

abstractmethod ngettext(message_singular: str, message_plural: str, n: int, /) LocalizedStr | None#

Like gettext.ngettext().

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

abstractmethod npgettext(context: str, message_singular: str, message_plural: str, n: int, /) LocalizedStr | None#

Like gettext.npgettext().

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

abstractmethod pgettext(context: str, message: str, /) LocalizedStr | None#

Like gettext.pgettext().

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

final class betty.gettext.TranslationsRepository#

Bases: object

Expose translations.

__init__(*, assets: AssetRepository, cache: TransientBinaryFileStore)#
async get(locale: ResolvableLocale, /) Iterable[Translations]#

Get the translations for the given locale.

final class betty.gettext.Translator#

Bases: Translations

Translate strings.

The translator always reliably returns strings. If no translations can be found, the original source strings are returned with the correct locale information.

__init__(*translations: Translations)#
gettext(message: str, /) LocalizedStr#

Like gettext.gettext().

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

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().

async betty.gettext.new_translation(output: AssetDirectoryDefinition, locale: Locale, *, user: User) None#

Create a new translation.

async betty.gettext.update_builtin_translations(override_output: Path | None = None, /) None#

Update the translations for Betty itself.

async betty.gettext.update_translations(output: StrPath, inputs: Iterable[StrPath], excludes: Iterable[StrPath], user: User) None#

Update translations.