Open
Description
I needed translated (NL/Dutch) FormValidation
errors in a frontend and tried to get that working. There is a package pydantic-translations
I am not sure about the best internationalisation project for pydantic; there's also pydantic-i18n
With pydantic-translations
: I managed to get Dutch / NL form validations errors in the frontend, by changing some code in post_form()
:
# Loop through user inputs and for each input validate and update current state and validation results
while user_inputs:
user_input = user_inputs.pop(0)
# Validate
try:
form_validated_data = generated_form(**user_input)
except ValidationError as e:
from pydantic_translations import Translator
tr = Translator('nl')
errors = [tr.translate_error(error) for error in e.errors()]
raise FormValidationError(e.model.__name__, errors) from e # type: ignore
This works as a POC: it might be cool to add this as a feature, by adding an optional language parameter in start_form() and post_form().
Investigate:
- is this a nice feature for this project?
- which translation package is the best
- what's a good format for the language parameter: "nl", "NL-nl"?
- how can can users add custom translations for their own form fields