betty.localizables.static module#

Static translations.

final class betty.localizables.static.CountableStaticTranslations#

Bases: CountableLocalizable

A countable localizable backed by static translations.

__init__(translations: ShorthandCountableStaticTranslations, /)#
count(count: LocalizableCount, /) Localizable#

Create a localizable for the given count (number of things).

Implementations MUST automatically format the returned localizable with a {count} argument set to count.

translations: Final[CountableStaticTranslationsMapping]#

The translations.

final exception betty.localizables.static.InvalidPluralTag#

Bases: LocaleError

Raised when a countable localizable defines an invalid plural tag.

final exception betty.localizables.static.MissingPluralPlaceholder#

Bases: LocaleError

Raised when a plural translation is missing a placeholder.

final exception betty.localizables.static.MissingPluralTag#

Bases: LocaleError

Raised when a countable localizable is missing a plural tag.

final class betty.localizables.static.StaticTranslations#

Bases: Localizable

A localizable backed by static translations.

All configuration options#

This configuration is either a single translation as a string, or multiple translations as a key-value mapping.

A single translation#

Type

string

A single translation can be set that is to be used for all languages.

Example configuration:

"I am a single translation, used for all languages"
"I am a single translation, used for all languages"

Multiple translations#

Type

mapping

Keys (string) are IETF BCP 47 language tags, and values (string) are human-readable translations.

Example configuration:

en-US: "I'm the English translation"
nl-NL: "Ik ben de Nederlandse vertaling"
{
  "en-US": "I'm the English translation",
  "nl-NL": "Ik ben de Nederlandse vertaling",
}
__init__(translations: ShorthandStaticTranslations, /)#
Parameters:

translations – Keys are locales, values are translations.

localize(localizer: Localizer, /) LocalizedStr#

Localize self to a human-readable string.

classmethod resolve(other: Localizable, localizers: Iterable[Localizer], /) Self#

Create a new instance from another :py:class`betty.localizable.Localizable`.

translations: Final[StaticTranslationsMapping]#

The translations.