Colloidal localization of WTF with Babel

I used Flask Babel and localized my project, but I have a problem with WTF forms, I cannot translate the fields shown when the field is empty. Any help?

It works:

return jsonify({'error': gettext('Incorrect Data')}), 406

      

but when working with Form class Babel does not retrieve field. eg:

class LoginForm(Form):
    username = TextField(gettext(u'Username'), validators=[validators.Required()])
    password = PasswordField('Password', validators=[validators.Required()])

      

I've tried both with the 'u' option / no option

+3


source to share


2 answers


Messages for the validator Required

are installed via Required(message=error_message)

, translated using babel. See the WTForms documentation for details .



class LoginForm(Form):
    username = TextField(gettext(u'Username'), validators=[validators.Required(message='Validation failed for username')])
    password = PasswordField('Password', validators=[validators.Required(message='Validation failed for password')])

      

0


source


try with lazy_gettext('')

.

class LoginForm(Form):
    username = TextField(lazy_gettext(u'Username'), validators=[validators.Required()])

      



in HTML :

{{form.username.label (class="form-control-label") }}

      

0


source







All Articles