How To Translate Field Label Automatically When Using Flask-admin?
I would like to know how to use Flask-BabelEx(which is recommended by Flask-Admin) to translate field labels automatically when it's been generated by flask-admin. For example, If
Solution 1:
We need to use lazy_gettext rather than gettext to make it work, examples as below:
adminViews.add_view(SalesOrderAdmin(SalesOrder, db_session, name=lazy_gettext("Sales Order")))
And
classPurchaseOrderAdmin(ModelView):
column_labels =dict(logistic_amount=lazy_gettext("logistic_amount"),)
Solution 2:
My guess is that in your case gettext("logistic_amount")
does not actually return the translated string.
As a rather crude 'quick fix' you could try using a custom admin/model/list.html
for your model and: replace all occurrences of {{ name }}
by {{ _(name) }}
, then Jinja should take care of that. (Worked for me.)
I haven't looked into that but I believe thats some Babel / BabelEx configuration issue.
Regards
Post a Comment for "How To Translate Field Label Automatically When Using Flask-admin?"