API documentation

ParlerAdminWagtailMixin (internal use)

⚠️ This mixin is documented for dev only: you SHOULD NOT use it directly ⚠️

class wagtail_parler.handlers.ParlerAdminWagtailMixin

Bases: object

Mixin to manage translations via Parler inside a ModelAdmin or SnippetViewSet

You SHOULD NOT use this Mixin directly but ParlerModelAdminMixin or ParlerSnippetAdminMixin

_set_translations_handlers(handlers: List, base_handler: TranslationsList | None = None) Set[str]

Build handler for each locale and add it to handlers list base_handler can be used as a template : all it’s children which are FieldPanel will have their field_name renamed with translations_%(language_code)s_%(field_name)s if they exists in the translation Model.

get_edit_handler() TabbedInterface

Prepare real handlers to be used with this Model Admin.

ParlerSnippetAdminMixin

class wagtail_parler.handlers.ParlerSnippetAdminMixin(**kwargs)

Bases: ParlerAdminWagtailMixin, SnippetViewSet

Mixin to use with SnippetViewSet to manage parler translations.

If no edit_handler are defined, the default behaviour will create an unstranlated data tab then a tab for each language You can specify your edit_handler to have more control over how form is built. TranslationsList will be duplicated for each language and populated with translations fields if no children are given. Of course, you can also configure fields manually ex:

class SomeModelAdminSnippet(ParlerSnippetAdminMixin, SnippetViewSet):
    model = SomeModel


class FoodAdminSnippet(ParlerSnippetAdminMixin, SnippetViewSet):
    model = Food
    edit_handler = ObjectList(
        children=[
            FieldPanel("yum_rating"),
            TranslationsList(
                heading="%(code)s: %(locale)s %(status)s",
                # let children empty, it will be auto populated
            ),
            ObjectList(
                heading=_("RΓ©gime"),
                children=[FieldPanel("vegetarian"), FieldPanel("vegan")]
            ),
        ],
    )
get_edit_handler() TabbedInterface

Prepare real handlers to be used with this Model Admin.

ParlerModelAdminMixin

class wagtail_parler.handlers.ParlerModelAdminMixin

Bases: ParlerAdminWagtailMixin

Mixin to use with ModelAdmin to manage parler translations. ex:

class SomeModelAdmin(ParlerModelAdminMixin, ModelAdmin):
    model = SomeModel


class FoodModelAdmin(ParlerModelAdminMixin, ModelAdmin):
    model = Food
    edit_handler = ObjectList(
        children=[
            FieldPanel("yum_rating"),
            TranslationsList(
                heading="%(code)s: %(locale)s %(status)s",  # type: ignore
                # let children empty, it will be auto populated
            ),
            ObjectList(
                heading=_("RΓ©gime"),
                children=[FieldPanel("vegetarian"), FieldPanel("vegan")]
            ),
        ],
    )

AutoParlerModelForm

⚠️ This class is documented for dev only: you SHOULD NOT use it directly ⚠️

class wagtail_parler.forms.AutoParlerModelForm(*args: Tuple, **kwargs: Dict)

Bases: Form

Manage update/create/delete of translations

auto_parler_fields: Set[str] = {}
cleaned_data_for_locales: Dict[str, Any] = {}
_init_i18n_initials(instance: Model, initials: Dict) Dict | None

If instance already has translations, populates the initial content of translated fields

get_localized_fieldnames(locale: str) Generator

Generator of (field_name: str, i18n_field_name:str) to get real field_name for the translated model and the current form associated field name.

param: locale: str: locale code of translation to save/create/delete

_set_locale(locale: str) List

Depending sent data, will save/create/delete translation for the given language code

Args:

locale (str): locale code of translation to save/create/delete

Returns:
(None|True|False, int|instance|[instances]: for deletion, will return None and the

number of translations deleted for creation, will return True and the created of translation for update, will return False and the updated of translation

_save_locale(locale: str) Tuple

Depending sent data, will save/create/delete translation for the given language code

Args:

locale (str): locale code of translation to save/create/delete

Returns:
(None|True|False, int|instance|[instances]: for deletion, will return None and the

number of translations deleted for creation, will return True and the created of translation for update, will return False and the updated of translation

clean() Dict

Prepare cleaned_data_for_locales of translated fields

save(*args: Tuple, **kwargs: Dict) Model

Save the instance and it’s translations

base_fields = {}
declared_fields = {}
property media

Return all media required to render the widgets on this form.