Reference: Forms

This module contains the form utilities for the Translations app.

translations.forms.generate_translation_form(translatable)[source]

Return the Translation form based on a Translatable model and the translation languages.

Generates the Translation form based on the translatable fields of the Translatable model and the translation languages and returns it.

Parameters

translatable (type(Translatable)) – The Translatable model to generate the Translation form based on.

Returns

The Translation form generated based on the Translatable model and the translation languages.

Return type

type(ModelForm(Translation))

Raises

ValueError – If the default language code is not supported.

To get the Translation form based on a Translatable model and the translation languages:

from translations.forms import generate_translation_form
from sample.models import Continent

# get the translation form
form = generate_translation_form(Continent)

print(form.declared_fields['field'].choices)
print(form.declared_fields['language'].choices)
[
    (None, '---------'),
    ('name', 'Name'),
    ('denonym', 'Denonym'),
]
[
    (None, '---------'),
    ('en-gb', 'English (Great Britain)'),
    ('de', 'German'),
    ('tr', 'Turkish'),
]