py_research.intl module#
Simple & semi-automatic intl. + localization of data analysis functions.
- class DtUnit(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
StrEnum
Common datetime units with their LDML pattern strings.
- year = 'yyyy'#
- quarter = 'QQQ'#
- month = 'MM'#
- week = 'ww'#
- week_of_month = 'W'#
- day = 'dd'#
- day_of_year = 'DD'#
- hour = 'HH'#
- minute = 'mm'#
- second = 'ss'#
- millisecond = 'SSS'#
- class Format(decimal_notation=None, decimal_digits=None, decimal_min_digits=None, decimal_max_digits=None, decimal_group_separator=None, datetime_auto_format=None, datetime_format=None, timedelta_auto_format=None, timedelta_resolution=None, country_format=None, fallback_to_translation=True, na_representation='')[source]#
Bases:
object
Custom options for localized formatting.
- Parameters:
decimal_notation (Literal['plain', 'scientific', 'percent'] | None) –
decimal_digits (int | None) –
decimal_min_digits (int | None) –
decimal_max_digits (int | None) –
decimal_group_separator (bool | None) –
datetime_auto_format (Literal['short', 'medium', 'long'] | None) –
timedelta_auto_format (Literal['narrow', 'short', 'medium', 'long', 'raw'] | None) –
timedelta_resolution (Literal['year', 'month', 'week', 'day', 'hour', 'minute', 'second'] | None) –
country_format (Literal[GeoScheme.country_name, GeoScheme.cc_iso2, GeoScheme.cc_iso3] | None) –
fallback_to_translation (bool) –
na_representation (str) –
- datetime_auto_format: Literal['short', 'medium', 'long'] | None = None#
How to auto-format datetimes.
- datetime_format: DtUnit | str | None = None#
`ldml pattern`_ for formatting datetime objects. .. _ldml pattern: https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table
- timedelta_auto_format: Literal['narrow', 'short', 'medium', 'long', 'raw'] | None = None#
How to auto-format timedeltas.
- timedelta_resolution: Literal['year', 'month', 'week', 'day', 'hour', 'minute', 'second'] | None = None#
Unit to use for formatting timedeltas. Has no effect for auto-format ‘raw’.
- country_format: Literal[GeoScheme.country_name, GeoScheme.cc_iso2, GeoScheme.cc_iso3] | None = None#
How to format countries.
- fallback_to_translation: bool = True#
Whether to fallback to text translation if no other formatting method matches.
- class Template(replace=None, wrap=None, args=None)[source]#
Bases:
object
Override for a text template.
- class Overrides(templates=<factory>, vocabulary=<factory>, format=<factory>)[source]#
Bases:
object
Custom, language-dependent text overrides.
- Parameters:
- class Localization(loc=None, overrides=None, show_raw=False)[source]#
Bases:
object
Locale config, which can be used as a context manager to activate the locale.
- Parameters:
- loc: Locale | str | None = None#
Locale to use for this localization. If None, use parent context’s locale.
- overrides: Overrides | dict[Locale, Overrides] | dict[str, Overrides] | None = None#
Optional translation overrides for the current or other locales.
- show_raw: bool = False#
Whether to show raw function calls instead of localized text, for debugging.
- property locale: Locale#
Return first locale found up the parent tree or default locale.
- property override_dict: dict[Locale, Overrides]#
Return dict of all overrides, keyed by locale string.
- get_overrides(locale)[source]#
Return merger of all the parents’ and self’s overrides for given locale.
- Parameters:
locale (Locale) –
- Return type:
- text(context, content, *args, locale=None)[source]#
Localize given text.
- Parameters:
- Returns:
Localized text.
- Return type:
- value(v, options=Format(decimal_notation=None, decimal_digits=None, decimal_min_digits=None, decimal_max_digits=None, decimal_group_separator=None, datetime_auto_format=None, datetime_format=None, timedelta_auto_format=None, timedelta_resolution=None, country_format=None, fallback_to_translation=True, na_representation=''), locale=None)[source]#
Return localized string represention of given value.
- formatter(options=Format(decimal_notation=None, decimal_digits=None, decimal_min_digits=None, decimal_max_digits=None, decimal_group_separator=None, datetime_auto_format=None, datetime_format=None, timedelta_auto_format=None, timedelta_resolution=None, country_format=None, fallback_to_translation=True, na_representation=''), locale=None)[source]#
Return a formatting function bound to this locale.
- format_spec(typ, options=Format(decimal_notation=None, decimal_digits=None, decimal_min_digits=None, decimal_max_digits=None, decimal_group_separator=None, datetime_auto_format=None, datetime_format=None, timedelta_auto_format=None, timedelta_resolution=None, country_format=None, fallback_to_translation=True, na_representation=''), locale=None)[source]#
Return locale-aware format-string for given type, if applicable.
- iter_locales(locales=None, overrides=None)[source]#
Iterate over localizations for given locales w/ optional overrides.
- Parameters:
- Returns:
Generator of localizations.
- Return type:
Generator[Localization, None, None]
- default_file_path = PosixPath('/home/runner/work/py-research/py-research/texts.yaml')#
Default path to text overrides file.