Skip to content

Babel

These are configurable class-based filters implementing internationalization and localization features.

liquid2.builtin.filters.translate.BaseTranslateFilter

Base class for the default translation filters.

PARAMETER DESCRIPTION
translations_var

The name of a render context variable that resolves to a gettext Translations class. Defaults to "translations".

TYPE: str DEFAULT: 'translations'

default_translations

A fallback translations class to use if translations_var can not be resolves. Defaults to NullTranslations.

TYPE: Translations | None DEFAULT: None

message_interpolation

If True (default), perform printf-style string interpolation on the translated message, using keyword arguments passed to the filter function.

TYPE: bool DEFAULT: True

auto_escape_message

If True and the current environment has auto_escape set to True, the filter's left value will be escaped before translation. Defaults to False.

TYPE: bool DEFAULT: False

format_message

format_message(
    context: RenderContext,
    message_text: str,
    message_vars: dict[str, Any],
) -> str

Return the message string formatted with the given message variables.

liquid2.builtin.DateTime

A Liquid filter for formatting datetime objects.

PARAMETER DESCRIPTION
timezone_var

The name of a render context variable that resolves to a timezone. Defaults to "timezone".

TYPE: str DEFAULT: 'timezone'

default_timezone

A fallback timezone to use if timezone_var can not be resolved. Defaults to "UTC".

TYPE: str DEFAULT: 'UTC'

locale_var

The name of a render context variable that resolves to the current locale. Defaults to "locale".

TYPE: str DEFAULT: 'locale'

default_locale

A fallback locale to use if locale_var can not be resolved. Defaults to "en_US".

TYPE: str DEFAULT: 'en_US'

format_var

The name of a render context variable that resolves to the current datetime format string. Defaults to "datetime_format".

TYPE: str DEFAULT: 'datetime_format'

default_format

A fallback datetime format that is used if format_var can not be resolved. Defaults to "medium".

TYPE: str DEFAULT: 'medium'

input_timezone_var

The name of a render context variable that resolves to a timezone for parsing datetimes entered as strings. Defaults to "input_timezone".

TYPE: str DEFAULT: 'input_timezone'

default_input_timezone

A fallback timezone to use if input_timezone_var can not be resolved. Defaults to "UTC".

TYPE: str DEFAULT: 'UTC'

__call__

__call__(
    left: object,
    *,
    context: RenderContext,
    format: str | None = None
) -> str

Apply the filter and return the result.

liquid2.builtin.GetText

Bases: BaseTranslateFilter, TranslatableFilter

A Liquid filter equivalent of gettext.gettext.

liquid2.builtin.NGetText

Bases: BaseTranslateFilter, TranslatableFilter

A Liquid filter equivalent of gettext.ngettext.

__call__

__call__(
    __left: object,
    __plural: str,
    __count: object,
    *,
    context: RenderContext,
    **kwargs: Any
) -> str

Apply the filter and return the result.

liquid2.builtin.NPGetText

Bases: BaseTranslateFilter, TranslatableFilter

A Liquid filter equivalent of gettext.npgettext.

liquid2.builtin.Number

A Liquid filter for formatting decimal values.

PARAMETER DESCRIPTION
decimal_quantization_var

The name of a render context variable that resolves to the decimal quantization to be used. Defaults to "decimal_quantization".

TYPE: str DEFAULT: 'decimal_quantization'

default_decimal_quantization

A fallback decimal quantization if decimal_quantization_var can not be resolved. Defaults to False.

TYPE: bool DEFAULT: False

locale_var

The name of a render context variable that resolves to the current locale. Defaults to "locale".

TYPE: str DEFAULT: 'locale'

default_locale

A fallback locale to use if locale_var can not be resolved. Defaults to "en_US".

TYPE: str DEFAULT: 'en_US'

format_var

The name of a render context variable that resolves to the current decimal format string. Defaults to "decimal_format".

TYPE: str DEFAULT: 'decimal_format'

default_format

A fallback decimal format that is used if format_var can not be resolved. Defaults to None, which means the standard format for the current locale will be used.

TYPE: str | None DEFAULT: None

input_locale_var

The name of a render context variable that resolves to a locale suitable for parsing input strings to decimals. Defaults to "input_locale".

TYPE: str DEFAULT: 'input_locale'

default_input_locale

A fallback locale to use if input_locale_var can not be resolved. Defaults to "en_US".

TYPE: str DEFAULT: 'en_US'

__call__

__call__(
    left: object,
    *,
    context: RenderContext,
    group_separator: bool = True
) -> str

Apply the filter and return the result.

liquid2.builtin.Translate

Bases: BaseTranslateFilter, TranslatableFilter

A Liquid filter for translating strings to other languages.

Depending on the keyword arguments provided when the resulting filter is called, it could behave like gettext, ngettext, pgettext or npgettext.

__call__

__call__(
    __left: object,
    __message_context: object = None,
    *,
    context: RenderContext,
    **kwargs: Any
) -> str

Apply the filter and return the result.

liquid2.builtin.Unit

A Liquid filter for formatting units of measurement.

PARAMETER DESCRIPTION
locale_var

The name of a render context variable that resolves to the current locale. Defaults to "locale".

TYPE: str DEFAULT: 'locale'

default_locale

A fallback locale to use if locale_var can not be resolved. Defaults to "en_US".

TYPE: str DEFAULT: 'en_US'

length_var

The name of a render context variable that resolves to a unit format length. Should be one of "short", "long" or "narrow". Defaults to "long".

TYPE: str DEFAULT: 'unit_length'

default_length

A fallback format length to use if length_var can not be resolved.

TYPE: str DEFAULT: 'long'

format_var

The name of a render context variable that resolves to a decimal format string. Defaults to "unit_format".

TYPE: str DEFAULT: 'unit_format'

default_format

A fallback decimal format to use if format_var can not be resolved. Defaults to None, meaning the locale's standard decimal format is used.

TYPE: str | None DEFAULT: None

input_locale_var

The name of a render context variable that resolves to a locale suitable for parsing input strings to decimals. Defaults to "input_locale".

TYPE: str DEFAULT: 'input_locale'

default_input_locale

A fallback locale to use if input_locale_var can not be resolved. Defaults to "en_US".

TYPE: str DEFAULT: 'en_US'