apimodel.localization#

Localization support for the API.

Module Contents#

class apimodel.localization.LocalizedFieldInfo(default: object = ..., *, alias: Optional[str] = None, private: Optional[bool] = False, validators: apimodel.tutils.MaybeSequence[apimodel.tutils.AnyCallable] = ..., i18n: Optional[Union[str, Mapping[str, str]]] = None, localizator: Optional[Callable[[Any, str], Optional[object]]] = None, **extra: Any)[source]#

Complete information about a localized field.

i18n :Optional[Union[str, Mapping[str, str]]][source]#

Localized field names.

localizator :Optional[Callable[[Any, str], Optional[object]]][source]#

Getter for localized values of the field. Called in LocalizedAPIModel.as_dict.

get_localized_name(self, provider: Mapping[str, Mapping[str, str]], locale: str, name: Optional[str] = None) str[source]#

Get the localized name of the field.

get_localized_value(self, value: object, provider: Mapping[str, Mapping[str, str]], locale: str) object[source]#

Get the localized value of the field..

class apimodel.localization.LocalizedAPIModelMeta[source]#

Localized API model metaclass.

__fields__ :Mapping[str, LocalizedFieldInfo][source]#
i18n :ClassVar[Dict[str, Dict[str, str]]][source]#

Internationalization mapping of {locale: {key: "localized string"}}.

set_i18n(self, locale: str, key: str, value: str) None[source]#

Set a new i18n entry.

class apimodel.localization.LocalizedAPIModel[source]#

Localized API model.

locale :Optional[str][source]#
as_dict(self, *, private: bool = False, properties: bool = True, alias: Optional[bool] = None, locale: Optional[str] = None, **options: object) Mapping[str, object][source]#

Create a mapping from the model instance.

Parameters
  • private – Include private attributes (prefixed with an underscore _).

  • properties – Include methods decorated with @property.

  • alias – Rename fields to their declared name if they cannot be localized. If False, do not rename any field even if it can be localized.

  • locale – Locale to use for localization. By default the locale of the model instance is used.