Skip to content

Forms

hypha.apply.translate.forms

TranslateSubmissionForm

Bases: Form

available_packages class-attribute instance-attribute

available_packages = get_available_translations()

from_lang class-attribute instance-attribute

to_lang class-attribute instance-attribute

clean

clean()
Source code in hypha/apply/translate/forms.py
def clean(self):
    form_data = self.cleaned_data
    try:
        from_code = form_data["from_lang"]
        to_code = form_data["to_lang"]

        to_packages = get_available_translations([from_code])

        if to_code not in [package.to_code for package in to_packages]:
            self.add_error(
                "to_lang",
                "The specified language is either invalid or not installed",
            )

        return form_data
    except KeyError as err:
        # If one of the fields could not be parsed, there is likely bad input being given
        raise forms.ValidationError("Invalid input selected") from err