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.
- localizator :Optional[Callable[[Any, str], Optional[object]]][source]#
Getter for localized values of the field. Called in
LocalizedAPIModel.as_dict.
- class apimodel.localization.LocalizedAPIModelMeta[source]#
Localized API model metaclass.
- class apimodel.localization.LocalizedAPIModel[source]#
Localized API model.
- 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.