betty.locale module¶
Provide the Locale API.
- class betty.locale.Date[source]¶
Bases:
LinkedDataDumpableA (Gregorian) date.
- __init__(year: int | None = None, month: int | None = None, day: int | None = None, fuzzy: bool = False)[source]¶
- async datey_dump_linked_data(dump: dict[str, bool | int | float | str | None | Sequence[bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | Mapping[str, bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]]], start_schema_org: str, end_schema_org: str) None[source]¶
Dump this instance to JSON-LD for a ‘datey’ field.
- Parameters:
dump (
dict[str,typing.Union[bool,int,float,str,None,typing.Sequence[typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]],typing.Mapping[str,typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]]]])start_schema_org (
str)end_schema_org (
str)
- Return type:
- async dump_linked_data(app: betty.app.App, schemas_org: list[str] | None = None) dict[str, bool | int | float | str | None | Sequence[bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | Mapping[str, bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]]][source]¶
Dump this instance to JSON-LD.
- Parameters:
app (
betty.app.App)
- Return type:
dict[str,typing.Union[bool,int,float,str,None,typing.Sequence[typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]],typing.Mapping[str,typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]]]]
- async classmethod linked_data_schema(app: betty.app.App) dict[str, bool | int | float | str | None | Sequence[bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | Mapping[str, bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]]][source]¶
Define the JSON Schema for
betty.json.linked_data.LinkedDataDumpable.dump_linked_data().- Parameters:
app (
betty.app.App)- Return type:
dict[str,typing.Union[bool,int,float,str,None,typing.Sequence[typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]],typing.Mapping[str,typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]]]]
- property parts: tuple[int | None, int | None, int | None]¶
The date parts: a 3-tuple of the year, month, and day.
- to_range() betty.locale.DateRange[source]¶
Convert this date to a date range.
- Return type:
- class betty.locale.DateRange[source]¶
Bases:
LinkedDataDumpableA date range can describe a period of time between, before, after, or around start and/or end dates.
- Parameters:
start (
betty.locale.Date|None)end (
betty.locale.Date|None)start_is_boundary (
bool)end_is_boundary (
bool)
- __init__(start: betty.locale.Date | None = None, end: betty.locale.Date | None = None, start_is_boundary: bool = False, end_is_boundary: bool = False)[source]¶
- Parameters:
start (
betty.locale.Date|None)end (
betty.locale.Date|None)start_is_boundary (
bool)end_is_boundary (
bool)
- async datey_dump_linked_data(dump: dict[str, bool | int | float | str | None | Sequence[bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | Mapping[str, bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]]], start_schema_org: str, end_schema_org: str) None[source]¶
Dump this instance to JSON-LD for a ‘datey’ field.
- Parameters:
dump (
dict[str,typing.Union[bool,int,float,str,None,typing.Sequence[typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]],typing.Mapping[str,typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]]]])start_schema_org (
str)end_schema_org (
str)
- Return type:
- async dump_linked_data(app: betty.app.App, start_schema_org: str | None = None, end_schema_org: str | None = None) dict[str, bool | int | float | str | None | Sequence[bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | Mapping[str, bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]]][source]¶
Dump this instance to JSON-LD.
- Parameters:
app (
betty.app.App)
- Return type:
dict[str,typing.Union[bool,int,float,str,None,typing.Sequence[typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]],typing.Mapping[str,typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]]]]
-
end:
betty.locale.Date|None¶
- async classmethod linked_data_schema(app: betty.app.App) dict[str, bool | int | float | str | None | Sequence[bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | Mapping[str, bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]]][source]¶
Define the JSON Schema for
betty.json.linked_data.LinkedDataDumpable.dump_linked_data().- Parameters:
app (
betty.app.App)- Return type:
dict[str,typing.Union[bool,int,float,str,None,typing.Sequence[typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]],typing.Mapping[str,typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]]]]
-
start:
betty.locale.Date|None¶
- exception betty.locale.IncompleteDateError[source]¶
Bases:
ValueErrorRaised when a datey was unexpectedly incomplete.
- exception betty.locale.LocaleNotFoundError[source]¶
Bases:
RuntimeErrorRaise when a locale could not be found.
- Parameters:
locale (
str)
- class betty.locale.Localizable[source]¶
Bases:
objectA localizable object.
Objects of this type can convert themselves to localized strings at the point of use.
- localize(localizer: betty.locale.Localizer) str[source]¶
Localize
selfto a human-readable string.- Parameters:
localizer (
betty.locale.Localizer)- Return type:
- class betty.locale.Localized[source]¶
Bases:
LinkedDataDumpableA resource that is localized, e.g. contains information in a specific locale.
- Parameters:
args (
typing.Any)kwargs (
typing.Any)
- __init__(*args: Any, locale: str | None = None, **kwargs: Any)[source]¶
- Parameters:
args (
typing.Any)kwargs (
typing.Any)
- async dump_linked_data(app: betty.app.App) dict[str, bool | int | float | str | None | Sequence[bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | Mapping[str, bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]]][source]¶
Dump this instance to JSON-LD.
- Parameters:
app (
betty.app.App)- Return type:
dict[str,typing.Union[bool,int,float,str,None,typing.Sequence[typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]],typing.Mapping[str,typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]]]]
- async classmethod linked_data_schema(app: betty.app.App) dict[str, bool | int | float | str | None | Sequence[bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | Mapping[str, bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]]][source]¶
Define the JSON Schema for
betty.json.linked_data.LinkedDataDumpable.dump_linked_data().- Parameters:
app (
betty.app.App)- Return type:
dict[str,typing.Union[bool,int,float,str,None,typing.Sequence[typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]],typing.Mapping[str,typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]]]]
- class betty.locale.Localizer[source]¶
Bases:
objectProvide localization functionality for a specific locale.
- Parameters:
locale (
str)translations (
gettext.NullTranslations)
- __init__(locale: str, translations: gettext.NullTranslations)[source]¶
- Parameters:
locale (
str)translations (
gettext.NullTranslations)
- format_date(date: betty.locale.Date) str[source]¶
Format a date to a human-readable string.
- Parameters:
date (
betty.locale.Date)- Return type:
- format_date_range(date_range: betty.locale.DateRange) str[source]¶
Format a date range to a human-readable string.
- Parameters:
date_range (
betty.locale.DateRange)- Return type:
- format_datetime_datetime(datetime_datetime: datetime.datetime) str[source]¶
Format a datetime date to a human-readable string.
- Parameters:
datetime_datetime (
datetime.datetime)- Return type:
- format_datey(date: betty.locale.Date | betty.locale.DateRange) str[source]¶
Format a datey value into a human-readable string.
- Parameters:
date (
betty.locale.Date|betty.locale.DateRange)- Return type:
- gettext(message: str) str[source]¶
Like
gettext.gettext().Arguments are identical to those of
gettext.gettext().
- ngettext(message_singular: str, message_plural: str, n: int) str[source]¶
Like
gettext.ngettext().Arguments are identical to those of
gettext.ngettext().
- class betty.locale.LocalizerRepository[source]¶
Bases:
objectExposes the available localizers.
- Parameters:
assets (
betty.fs.FileSystem)
- __init__(assets: betty.fs.FileSystem)[source]¶
- Parameters:
assets (
betty.fs.FileSystem)
- async coverage(locale: str | babel.core.Locale) tuple[int, int][source]¶
Get the translation coverage for the given locale.
- Return type:
- Returns:
A 2-tuple of the number of available translations and the number of translatable source strings.
- Parameters:
locale (
str|babel.core.Locale)
- async get(locale: str | babel.core.Locale) betty.locale.Localizer[source]¶
Get the localizer for the given locale.
- Parameters:
locale (
str|babel.core.Locale)- Return type:
- async get_negotiated(*preferred_locales: str) betty.locale.Localizer[source]¶
Get the best matching available locale for the given preferred locales.
- Parameters:
preferred_locales (
str)- Return type:
- class betty.locale.Str[source]¶
Bases:
LocalizableCreate new localizable strings.
- classmethod call(call: Callable[[betty.locale.Localizer], str]) betty.locale.Str[source]¶
Create a new localizable that outputs the callable’s return value.
- Parameters:
call (
typing.Callable[[betty.locale.Localizer],str])- Return type:
- classmethod gettext(message: str, **format_kwargs: str | betty.locale.Localizable) betty.locale.Str[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.Localizablewill be localized before string formatting.- Parameters:
message (
str)format_kwargs (
str|betty.locale.Localizable)
- Return type:
- classmethod ngettext(message_singular: str, message_plural: str, n: int, **format_kwargs: str | betty.locale.Localizable) betty.locale.Str[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.Localizablewill be localized before string formatting.- Parameters:
message_singular (
str)message_plural (
str)n (
int)format_kwargs (
str|betty.locale.Localizable)
- Return type:
- classmethod npgettext(context: str, message_singular: str, message_plural: str, n: int, **format_kwargs: str | betty.locale.Localizable) betty.locale.Str[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.Localizablewill be localized before string formatting.- Parameters:
- Return type:
- classmethod pgettext(context: str, message: str, **format_kwargs: str | betty.locale.Localizable) betty.locale.Str[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.Localizablewill be localized before string formatting.- Parameters:
context (
str)message (
str)format_kwargs (
str|betty.locale.Localizable)
- Return type:
- classmethod plain(plain: Any, **format_kwargs: str | betty.locale.Localizable) betty.locale.Str[source]¶
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.Localizablewill be localized before string formatting.- Parameters:
plain (
typing.Any)format_kwargs (
str|betty.locale.Localizable)
- Return type:
- betty.locale.get_data(locale: str | babel.core.Locale) babel.core.Locale[source]¶
Get locale metadata.
- Parameters:
locale (
str|babel.core.Locale)- Return type:
- betty.locale.get_display_name(locale: str | babel.core.Locale, display_locale: str | babel.core.Locale | None = None) str | None[source]¶
Return a locale’s human-readable display name.
- Parameters:
locale (
str|babel.core.Locale)display_locale (
str|babel.core.Locale|None)
- Return type:
- betty.locale.negotiate_locale(preferred_locales: str | babel.core.Locale | Sequence[str | babel.core.Locale], available_locales: Sequence[str | babel.core.Locale]) babel.core.Locale | None[source]¶
Negotiate the preferred locale from a sequence.
- Parameters:
preferred_locales (
typing.Union[str,babel.core.Locale,typing.Sequence[str|babel.core.Locale]])available_locales (
typing.Sequence[str|babel.core.Locale])
- Return type:
- betty.locale.negotiate_localizeds(preferred_locales: str | babel.core.Locale | Sequence[str | babel.core.Locale], localizeds: Sequence[betty.locale.Localized]) betty.locale.Localized | None[source]¶
Negotiate the preferred localized value from a sequence.
- Parameters:
preferred_locales (
typing.Union[str,babel.core.Locale,typing.Sequence[str|babel.core.Locale]])localizeds (
typing.Sequence[betty.locale.Localized])
- Return type:
- async betty.locale.ref_date(root_schema: dict[str, bool | int | float | str | None | Sequence[bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | Mapping[str, bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]]], app: betty.app.App) dict[str, bool | int | float | str | None | Sequence[bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | Mapping[str, bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]]][source]¶
Reference the Date schema.
- Parameters:
root_schema (
dict[str,typing.Union[bool,int,float,str,None,typing.Sequence[typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]],typing.Mapping[str,typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]]]])app (
betty.app.App)
- Return type:
dict[str,typing.Union[bool,int,float,str,None,typing.Sequence[typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]],typing.Mapping[str,typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]]]]
- async betty.locale.ref_date_range(root_schema: dict[str, bool | int | float | str | None | Sequence[bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | Mapping[str, bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]]], app: betty.app.App) dict[str, bool | int | float | str | None | Sequence[bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | Mapping[str, bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]]][source]¶
Reference the DateRange schema.
- Parameters:
root_schema (
dict[str,typing.Union[bool,int,float,str,None,typing.Sequence[typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]],typing.Mapping[str,typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]]]])app (
betty.app.App)
- Return type:
dict[str,typing.Union[bool,int,float,str,None,typing.Sequence[typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]],typing.Mapping[str,typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]]]]
- async betty.locale.ref_datey(root_schema: dict[str, bool | int | float | str | None | Sequence[bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | Mapping[str, bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]]], app: betty.app.App) dict[str, bool | int | float | str | None | Sequence[bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]] | Mapping[str, bool | int | float | str | None | Sequence[Dump] | Mapping[str, Dump]]][source]¶
Reference the Datey schema.
- Parameters:
root_schema (
dict[str,typing.Union[bool,int,float,str,None,typing.Sequence[typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]],typing.Mapping[str,typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]]]])app (
betty.app.App)
- Return type:
dict[str,typing.Union[bool,int,float,str,None,typing.Sequence[typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]],typing.Mapping[str,typing.Union[bool,int,float,str,None,typing.Sequence[Dump],typing.Mapping[str, Dump]]]]]
- async betty.locale.run_babel(*args: str) None[source]¶
Run a Babel Command Line Interface (CLI) command.
- betty.locale.to_babel_identifier(locale: str | babel.core.Locale) str[source]¶
Convert a locale or locale metadata to a Babel locale identifier.
- Parameters:
locale (
str|babel.core.Locale)- Return type:
- betty.locale.to_locale(locale: str | babel.core.Locale) str[source]¶
Ensure that a locale or locale metadata is a locale.
- Parameters:
locale (
str|babel.core.Locale)- Return type:
- async betty.locale.update_translations(_output_assets_directory_path: pathlib.Path = PosixPath('/home/runner/work/betty/betty/betty/assets')) None[source]¶
Update all existing translations based on changes in translatable strings.
- Parameters:
_output_assets_directory_path (
pathlib.Path)- Return type: