0

I would like to use Flask-Babel to localise content in the app. Now I understand how Flask-Babel works and it's used to localise static content.

I have created a number of forms using Flask-wtf and they use QuerySelectField to fetch data from the database. Here is the registration form that has a QuerySelectField.

from flask_babel import _, lazy_gettext as _l

class RegistrationForm(FlaskForm):
    username = StringField(_l('Username'), validators=[DataRequired()])
    email = StringField(_l('Email'), validators=[DataRequired(), Email()])
    country = QuerySelectField(_l('Country'),
                           blank_text=u'-- please choose --',
                           query_factory=lambda: Country.query,
                           allow_blank=False)
    password = PasswordField(_l('Password'), validators=[DataRequired()])
    password2 = PasswordField(
        _l('Repeat Password'), validators=[DataRequired(),
                                           EqualTo('password')])
    submit = SubmitField(_l('Register'))

Is there anyway the country values can be localised here using babel instead of having to stored countries in different languages in the database?

avizzzy
  • 440
  • 9
  • 21

1 Answers1

1

As far as I know, the Flask-Babel was used to localize static content (strings in .py, .html etc.), you can't use it for dynamic content that output from the database. For this use case, you may need to use translation services such as Google Translation API or Microsoft translator.

Grey Li
  • 11,664
  • 4
  • 54
  • 64