betty.locale module

Provide the Locale API.

class betty.locale.Date(year=None, month=None, day=None, fuzzy=False)[source]

Bases: LinkedDataDumpable

Parameters:
year=None

month=None

day=None

fuzzy=False

property comparable : bool
property complete : bool
async datey_dump_linked_data(dump, start_schema_org, end_schema_org)[source]
Parameters:
dump

start_schema_org

end_schema_org

Return type:

None

day : --is-rst--:py:class:`int` | :py:obj:`None`
async dump_linked_data(app, schemas_org=None)[source]

Dump this instance to JSON-LD.

Parameters:
app

schemas_org=None

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]]]]]

fuzzy : --is-rst--:py:class:`bool`
async classmethod linked_data_schema(app)[source]

Define the JSON Schema for self.dump_linked_data().

Parameters:
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]]]]]

month : --is-rst--:py:class:`int` | :py:obj:`None`
property parts : tuple[int | None, int | None, int | None]
to_range()[source]
Return type:

betty.locale.DateRange

year : --is-rst--:py:class:`int` | :py:obj:`None`
class betty.locale.DateRange(start=None, end=None, start_is_boundary=False, end_is_boundary=False)[source]

Bases: LinkedDataDumpable

Parameters:
start=None

end=None

start_is_boundary=False

end_is_boundary=False

property comparable : bool
async datey_dump_linked_data(dump, start_schema_org, end_schema_org)[source]
Parameters:
dump

start_schema_org

end_schema_org

Return type:

None

async dump_linked_data(app, start_schema_org=None, end_schema_org=None)[source]

Dump this instance to JSON-LD.

Parameters:
app

start_schema_org=None

end_schema_org=None

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 : --is-rst--:py:class:`betty.locale.Date` | :py:obj:`None`
end_is_boundary : --is-rst--:py:class:`bool`
async classmethod linked_data_schema(app)[source]

Define the JSON Schema for self.dump_linked_data().

Parameters:
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 : --is-rst--:py:class:`betty.locale.Date` | :py:obj:`None`
start_is_boundary : --is-rst--:py:class:`bool`
exception betty.locale.IncompleteDateError[source]

Bases: ValueError

exception betty.locale.LocaleNotFoundError(locale)[source]

Bases: RuntimeError

Parameters:
locale

class betty.locale.Localizable[source]

Bases: object

localize(localizer)[source]
Parameters:
localizer

Return type:

str

class betty.locale.Localized(*args, locale=None, **kwargs)[source]

Bases: LinkedDataDumpable

Parameters:
*args

locale=None

**kwargs

async dump_linked_data(app)[source]

Dump this instance to JSON-LD.

Parameters:
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)[source]

Define the JSON Schema for self.dump_linked_data().

Parameters:
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]]]]]

locale : --is-rst--:py:class:`str` | :py:obj:`None`
class betty.locale.Localizer(locale, translations)[source]

Bases: object

Parameters:
locale

translations

format_date(date)[source]
Parameters:
date

Return type:

str

format_date_range(date_range)[source]
Parameters:
date_range

Return type:

str

format_datey(date)[source]

Format a datey value into a human-readable string.

Parameters:
date

Return type:

str

gettext(message)[source]
Parameters:
message

Return type:

str

property locale : str
ngettext(message_singular, message_plural, n)[source]
Parameters:
message_singular

message_plural

n

Return type:

str

npgettext(context, message_singular, message_plural, n)[source]
Parameters:
context

message_singular

message_plural

n

Return type:

str

pgettext(context, message)[source]
Parameters:
context

message

Return type:

str

class betty.locale.LocalizerRepository(assets)[source]

Bases: object

Parameters:
assets

async coverage(locale)[source]
Parameters:
locale

Return type:

tuple[int, int]

async get(locale)[source]
Parameters:
locale

Return type:

betty.locale.Localizer

async get_negotiated(*preferred_locales)[source]
Parameters:
*preferred_locales

Return type:

betty.locale.Localizer

property locales : Iterator[str]
class betty.locale.Str[source]

Bases: Localizable

classmethod call(call)[source]
Parameters:
call

Return type:

betty.locale.Str

classmethod gettext(message, **format_kwargs)[source]
Parameters:
message

**format_kwargs

Return type:

betty.locale.Str

classmethod ngettext(message_singular, message_plural, n, **format_kwargs)[source]
Parameters:
message_singular

message_plural

n

**format_kwargs

Return type:

betty.locale.Str

classmethod npgettext(context, message_singular, message_plural, n, **format_kwargs)[source]
Parameters:
context

message_singular

message_plural

n

**format_kwargs

Return type:

betty.locale.Str

classmethod pgettext(context, message, **format_kwargs)[source]
Parameters:
context

message

**format_kwargs

Return type:

betty.locale.Str

classmethod plain(plain, **format_kwargs)[source]
Parameters:
plain

**format_kwargs

Return type:

betty.locale.Str

betty.locale.get_data(locale)[source]

Get locale metadata.

Parameters:
locale

Return type:

babel.core.Locale

betty.locale.get_display_name(locale, display_locale=None)[source]

Return a locale’s human-readable display name.

Parameters:
locale

display_locale=None

Return type:

str | None

async betty.locale.init_translation(locale)[source]

Initialize a new translation.

Parameters:
locale

Return type:

None

betty.locale.negotiate_locale(preferred_locales, available_locales)[source]

Negotiate the preferred locale from a sequence.

Parameters:
preferred_locales

available_locales

Return type:

babel.core.Locale | None

betty.locale.negotiate_localizeds(preferred_locales, localizeds)[source]

Negotiate the preferred localized value from a sequence.

Parameters:
preferred_locales

localizeds

Return type:

betty.locale.Localized | None

async betty.locale.ref_date(root_schema, app)[source]

Reference the Date schema.

Parameters:
root_schema

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, app)[source]

Reference the DateRange schema.

Parameters:
root_schema

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, app)[source]

Reference the Datey schema.

Parameters:
root_schema

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)[source]

Run a Babel Command Line Interface (CLI) command.

Parameters:
*args

Return type:

None

betty.locale.to_babel_identifier(locale)[source]

Convert a locale or locale metadata to a Babel locale identifier.

Parameters:
locale

Return type:

str

betty.locale.to_locale(locale)[source]

Ensure that a locale or locale metadata is a locale.

Parameters:
locale

Return type:

str

async betty.locale.update_translations(_output_assets_directory_path=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/betty/envs/0.3.4/lib/python3.12/site-packages/betty/assets'))[source]

Update all existing translations based on changes in translatable strings.

Parameters:
_output_assets_directory_path=PosixPath('/home/docs/checkouts/readthedocs.org/user_builds/betty/envs/0.3.4/lib/python3.12/site-packages/betty/assets')

Return type:

None