6

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?

Machavity
  • 30,841
  • 27
  • 92
  • 100
kechap
  • 2,077
  • 6
  • 28
  • 50

1 Answers1

1

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.

tbicr
  • 24,790
  • 12
  • 81
  • 106
  • 1
    Helpful but I still can't make it work. I have compiled to both messages.mo and wtforms.mo and it doesn't work. – kechap Sep 15 '13 at 13:02
  • I use next command `PATH_TO_PYTHON_ENV/bin/pybabel compile -f -d PATH_TO_FLASK_PROJECT/translations/` and it fork fine for me. What `babel` and `flask babel` versions and what WTForm classes you use? – tbicr Sep 16 '13 at 09:14
  • I am using virtualenv, so I have the latest versions provided by pip. – kechap Sep 16 '13 at 10:26
  • copy the content of wtforms.po into your messages.po, then translate them – dpgaspar Dec 05 '14 at 18:19