betty.locale.translation module

Manage translations of built-in translatable strings.

final class betty.locale.translation.AssetTranslationRepository

Bases: TranslationRepository, Bootstrappable

Provide translations from assets.

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

__init__(assets: AssetRepository, cache: BinaryFileCache)
async bootstrap() None

Bootstrap the object.

async coverage(locale: ResolvableLocale) 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.

get(locale: ResolvableLocale) NullTranslations

Get the translations for the given locale.

property locales: Iterable[Locale]

The available locales.

final class betty.locale.translation.StaticTranslationRepository

Bases: TranslationRepository

Provide static translations.

__init__(translations: Mapping[Locale, gettext.NullTranslations])
get(locale: ResolvableLocale) NullTranslations

Get the translations for the given locale.

property locales: Iterable[Locale]

The available locales.

class betty.locale.translation.TranslationRepository

Bases: ABC

Provide translations.

abstractmethod get(locale: ResolvableLocale) NullTranslations

Get the translations for the given locale.

abstract property locales: Iterable[Locale]

The available locales.

final exception betty.locale.translation.UntranslatedLocale

Bases: LocaleError

Raised when no translations exist for a locale.

__init__(locale: Locale, /)
betty.locale.translation.default_translation_repository: Final[TranslationRepository] = <betty.locale.translation.StaticTranslationRepository object>

The translation repository for the default locale.

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

Create a new translation.

async betty.locale.translation.update_app_translations(override_output: Path | None = None, /) None

Update the translations for Betty itself.

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

Update translations.