betty.locale.localizable package - Betty documentation

Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# betty.locale.localizable package

## Submodules

- betty.locale.localizable.assertion module
  - `assert_static_translations()`
- betty.locale.localizable.config module
  - `OptionalStaticTranslationsLocalizableConfigurationAttr`
  - `RequiredStaticTranslationsLocalizableConfigurationAttr`
  - `StaticTranslationsLocalizableConfiguration`
    - `StaticTranslationsLocalizableConfiguration.dump()`
    - `StaticTranslationsLocalizableConfiguration.load()`

## Module contents

The localizable API allows objects to be localized at the point of use.

class betty.locale.localizable.Localizable

  Bases: `ABC`

  A localizable object.

  Objects of this type can convert themselves to localized strings at the point of use.

  abstractmethod localize(localizer: Localizer) → LocalizedStr

    Localize `self` to a human-readable string.

final class betty.locale.localizable.OptionalStaticTranslationsLocalizableAttr

  Bases: `StaticTranslationsLocalizableAttr`

  An instance attribute that contains `betty.locale.localizable.StaticTranslationsLocalizable`.

final class betty.locale.localizable.RequiredStaticTranslationsLocalizableAttr

  Bases: `StaticTranslationsLocalizableAttr`

  An instance attribute that contains `betty.locale.localizable.StaticTranslationsLocalizable`.

betty.locale.localizable.ShorthandStaticTranslations: TypeAlias = collections.abc.Mapping[str, str] | str

  `StaticTranslations` or 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()`.

  alias of `Mapping`[`str`, `str`]

class betty.locale.localizable.StaticTranslationsLocalizable

  Bases: `_FormattableLocalizable`, `LinkedDataDumpable`[`Object`, `MutableMapping`[`str`, `bool` | `int` | `float` | `str` | `None` | `MutableSequence`[Dump] | `MutableMapping`[`str`, Dump]]]

  Provide a `betty.locale.localizable.Localizable` backed by static translations.

  __init__(translations: Mapping[str, str] | str | None = None, *args: Any, required: bool = True, **kwargs: Any)
    Parameters:

      translations – Keys are locales, values are translations.

  async dump_linked_data(project: Project) → DumpMapping[Dump]

    Dump this instance to JSON-LD.

  async classmethod linked_data_schema(project: Project) → Object

    Define the JSON Schema for `betty.json.linked_data.LinkedDataDumpable.dump_linked_data()`.

  localize(localizer: Localizer) → LocalizedStr

    Localize `self` to a human-readable string.

  replace(translations: Self | Mapping[str, str] | str) → None

    Replace the translations.

  property translations: Mapping[str, str]

    The translations.

class betty.locale.localizable.StaticTranslationsLocalizableAttr

  Bases: `LinkedDataDumpableProvider`[`object`, `Schema`, `bool` | `int` | `float` | `str` | `None` | `MutableSequence`[Dump] | `MutableMapping`[`str`, Dump]]

  An instance attribute that contains `betty.locale.localizable.StaticTranslationsLocalizable`.

  This is internal. It MAY be used anywhere in Betty’s source code, but MUST NOT be used by third-party code.

  __init__(attr_name: str, title: str | None = None, description: str | None = None)
  async dump_linked_data_for(project: Project, target: object) → Dump

    Dump the given target to JSON-LD.

  async linked_data_schema_for(project: Project) → Schema

    Define the JSON Schema for `betty.json.linked_data.LinkedDataDumpableProvider.dump_linked_data_for()`.

class betty.locale.localizable.StaticTranslationsLocalizableSchema

  Bases: `Object`

  A JSON Schema for `betty.locale.localizable.StaticTranslationsLocalizable`.

  __init__(*, title: str = 'Static translations', description: str | None = None)

betty.locale.localizable.call(call: Callable[[Localizer], str]) → Localizable

  Create a new localizable that outputs the callable’s return value.

betty.locale.localizable.do_you_mean(*available_options: str) → Localizable

  Produce a message listing available options.

betty.locale.localizable.format(localizable: Localizable, *format_args: str | Localizable, **format_kwargs: str | Localizable) → Localizable

  Perform string formatting.

  The arguments are identical to those of `str.format()`.

betty.locale.localizable.gettext(message: str) → _GettextLocalizable

  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 any `betty.locale.localizable.Localizable` will be localized before string formatting.

betty.locale.localizable.join(*localizables: Localizable, separator: str = ' ') → Localizable

  Join multiple localizables.

betty.locale.localizable.ngettext(message_singular: str, message_plural: str, n: int) → _GettextLocalizable

  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 any `betty.locale.localizable.Localizable` will be localized before string formatting.

betty.locale.localizable.npgettext(context: str, message_singular: str, message_plural: str, n: int) → _GettextLocalizable

  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 any `betty.locale.localizable.Localizable` will be localized before string formatting.

betty.locale.localizable.pgettext(context: str, message: str) → _GettextLocalizable

  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 any `betty.locale.localizable.Localizable` will be localized before string formatting.

betty.locale.localizable.plain(string: str) → Localizable

  Turns a plain string into a `betty.locale.localizable.Localizable` without any actual translations.

betty.locale.localizable.static(translations: Mapping[str, str] | str) → Localizable

  Create a new localizable that outputs the given static translations.