betty.locale.localizable module - Betty 0.4.0a3 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 module

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.

  abstract localize(localizer: betty.locale.Localizer) → str

    Localize `self` to a human-readable string.

    Parameters:

      localizer (`betty.locale.Localizer`)

    Return type:

      `str`

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

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

  Parameters:

    call (`collections.abc.Callable`[[`betty.locale.Localizer`], `str`])

  Return type:

    `betty.locale.localizable.Localizable`

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

  Perform string formatting.

  The arguments are identical to those of :py:meth:`str.format`.

  Parameters:

    - localizable (`betty.locale.localizable.Localizable`)

    - format_args (`str` | `betty.locale.localizable.Localizable`)

    - format_kwargs (`str` | `betty.locale.localizable.Localizable`)

  Return type:

    `betty.locale.localizable.Localizable`

betty.locale.localizable.gettext(message: str) → betty.locale.localizable._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` will be localized before string formatting.

  Parameters:

    message (`str`)

  Return type:

    `betty.locale.localizable._GettextLocalizable`

betty.locale.localizable.ngettext(message_singular: str, message_plural: str, n: int) → betty.locale.localizable._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` will be localized before string formatting.

  Parameters:

    - message_singular (`str`)

    - message_plural (`str`)

    - n (`int`)

  Return type:

    `betty.locale.localizable._GettextLocalizable`

betty.locale.localizable.npgettext(context: str, message_singular: str, message_plural: str, n: int) → betty.locale.localizable._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` will be localized before string formatting.

  Parameters:

    - context (`str`)

    - message_singular (`str`)

    - message_plural (`str`)

    - n (`int`)

  Return type:

    `betty.locale.localizable._GettextLocalizable`

betty.locale.localizable.pgettext(context: str, message: str) → betty.locale.localizable._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` will be localized before string formatting.

  Parameters:

    - context (`str`)

    - message (`str`)

  Return type:

    `betty.locale.localizable._GettextLocalizable`

betty.locale.localizable.plain(plain: Any) → betty.locale.localizable.Localizable

  Create a new localizable that outputs the given plain text string.

  Keyword arguments are identical to those of :py:met:`str.format`, except that any `betty.locale.Localizable` will be localized before string formatting.

  Parameters:

    plain (`typing.Any`)

  Return type:

    `betty.locale.localizable.Localizable`