betty.locale.localizable package¶
Submodules¶
Module contents¶
The localizable API allows objects to be localized at the point of use.
- class betty.locale.localizable.Localizable[source]¶
Bases:
ABCA localizable object.
Objects of this type can convert themselves to localized strings at the point of use.
- abstract localize(localizer: Localizer) LocalizedStr[source]¶
Localize
selfto a human-readable string.
- betty.locale.localizable.ShorthandStaticTranslations: TypeAlias = collections.abc.Mapping[str, str] | str¶
StaticTranslationsor a string which is the translation for the undetermined locale.See
betty.locale.localizable.assertion.assert_static_translations().
- betty.locale.localizable.StaticTranslations¶
Keys are locales, values are translations.
See
betty.locale.localizable.assertion.assert_static_translations().
- class betty.locale.localizable.StaticTranslationsLocalizable[source]¶
Bases:
_FormattableLocalizable,LinkedDataDumpable[Object]Provide a
betty.locale.localizable.Localizablebacked by static translations.- __init__(translations: Mapping[str, str] | str | None = None, *args: Any, required: bool = True, **kwargs: Any)[source]¶
- Parameters:
translations – Keys are locales, values are translations.
- async classmethod linked_data_schema(project: Project) StaticTranslationsLocalizableSchema[source]¶
Define the JSON Schema for
betty.json.linked_data.LinkedDataDumpable.dump_linked_data().
- localize(localizer: Localizer) LocalizedStr[source]¶
Localize
selfto a human-readable string.
- final class betty.locale.localizable.StaticTranslationsLocalizableAttr[source]¶
Bases:
MutableAttr[object,StaticTranslationsLocalizable,Mapping[str,str] |str]An instance attribute that contains
betty.locale.localizable.StaticTranslationsLocalizable.- new_attr(instance: object) StaticTranslationsLocalizable[source]¶
Create a new attribute value.
- class betty.locale.localizable.StaticTranslationsLocalizableSchema[source]¶
Bases:
ObjectA JSON Schema for
betty.locale.localizable.StaticTranslationsLocalizable.
- betty.locale.localizable.call(call: Callable[[Localizer], str]) Localizable[source]¶
Create a new localizable that outputs the callable’s return value.
- betty.locale.localizable.format(localizable: Localizable, *format_args: str | Localizable, **format_kwargs: str | Localizable) Localizable[source]¶
Perform string formatting.
The arguments are identical to those of
str.format().
- betty.locale.localizable.gettext(message: str) _GettextLocalizable[source]¶
Like
gettext.gettext().Positional arguments are identical to those of
gettext.gettext(). Keyword arguments are identical to those of :py:met:`str.format`, except that anybetty.locale.localizable.Localizablewill be localized before string formatting.
- betty.locale.localizable.ngettext(message_singular: str, message_plural: str, n: int) _GettextLocalizable[source]¶
Like
gettext.ngettext().Positional arguments are identical to those of
gettext.ngettext(). Keyword arguments are identical to those of :py:met:`str.format`, except that anybetty.locale.localizable.Localizablewill be localized before string formatting.
- betty.locale.localizable.npgettext(context: str, message_singular: str, message_plural: str, n: int) _GettextLocalizable[source]¶
Like
gettext.npgettext().Positional arguments are identical to those of
gettext.npgettext(). Keyword arguments are identical to those of :py:met:`str.format`, except that anybetty.locale.localizable.Localizablewill be localized before string formatting.
- betty.locale.localizable.pgettext(context: str, message: str) _GettextLocalizable[source]¶
Like
gettext.pgettext().Positional arguments are identical to those of
gettext.pgettext(). Keyword arguments are identical to those of :py:met:`str.format`, except that anybetty.locale.localizable.Localizablewill be localized before string formatting.
- betty.locale.localizable.plain(string: str) Localizable[source]¶
Turns a plain string into a
betty.locale.localizable.Localizablewithout any actual translations.