betty.locale package

Subpackages

Submodules

Module contents

Provide the Locale API.

class betty.locale.Localized

Bases: ABC

A resource that has a locale, e.g. contains information in a specific locale.

abstract property locale: Locale | None

The locale the data in this instance is in.

final class betty.locale.LocalizedStr

Bases: Localized, str

A string that has a locale.

__init__(string: str, *, locale: Locale | None = None)
static __new__(cls, string: str, *, locale: Locale | None = None)
property locale: Locale | None

The locale the data in this instance is in.

betty.locale.default_locale: Final[Locale] = Locale('en', territory='US')

Betty’s default locale (US English).

betty.locale.default_locale_tag: Final[str] = 'en-US'

The IETF BCP 47 language tag for Betty’s default locale (US English).

betty.locale.from_language_tag(language_tag: str, /) Locale

Get a locale from its IETF BCP 47 language tag.

Raises:
  • betty.locale.InvalidLocale – Raised if the given identifier is not a valid locale.

  • betty.locale.LocaleNotFoundError – Raised if the given locale cannot be found.

betty.locale.negotiate_has_locales(preferred_locales: Locale | Sequence[Locale], has_locales: Sequence[Localized]) Localized | None

Negotiate the preferred value from a sequence.

betty.locale.negotiate_locale(preferred_locales: Locale | Sequence[Locale], available_locales: Sequence[Locale], /) Locale | None

Negotiate the preferred locale from a sequence.

betty.locale.plural_tags(locale: Locale) Sequence[str]

Get a locale’s plural tags.

betty.locale.resolve_locale(locale: ResolvableLocale, /) Locale

Ensure that the given value is a locale.

Raises:
  • betty.locale.InvalidLocale – Raised if the given identifier is not a valid locale.

  • betty.locale.LocaleNotFoundError – Raised if the given locale cannot be found.

betty.locale.to_language_tag(locale: Locale | None, /) str

Formats a locale as an IETF BCP 47 language tag.