Translate default errors in Flask-WTF

1.3k views Asked by At

I am trying to translate the default messages from WTForms using the Flask-WTF plugin. According to this(https://github.com/ajford/flask-wtf/pull/65) it should be working. You can also see that wtforms use gettext for their default error messages(https://bitbucket.org/simplecodes/wtforms/src/113994790508/wtforms/validators.py).

I added WTF_I18n_ENABLED to my config file and I created my .po file using the following commands

pybabel extract -F babel.cfg -k lazy_gettext -o messages.pot myapp
pybabel init -i messages.pot -d myapp/translations -l en
pybabel compile -d myapp/translations

I expected the default messages to appear there but they don't. Am I expecting too much or doing something wrong?

1

There are 1 answers

4
tbicr On

Flask can search translations only on one folder (translations by default and not on eggs). So you need copypaste wtforms.mo/wtforms.po files to your application LS_MESSAGES.