Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Consider Flask-Babel integration #18

Closed
mattupstate opened this Issue Jun 18, 2012 · 9 comments

Comments

Projects
None yet
6 participants
Owner

mattupstate commented Jun 18, 2012

i10n and i18n could be necessary for things such as Flash messages.

Owner

mattupstate commented Sep 13, 2012

If anyone has some experience with doing this, I've started a branch named messages. I've having a bit of a hard time getting this feature started. The implementation is based on the Flask-Admin implementation.

Contributor

abulte commented Apr 17, 2013

This could be a great feature indeed! 👍

Owner

mattupstate commented Apr 17, 2013

Tell me about it. I haven't had much success getting it to work in the way that Flask-Admin has.

Contributor

abulte commented Apr 18, 2013

Maybe I can take a shot at it next week - if I can find the time. Not very experienced with Babel, but I would definitively use this feature. Anything I should know beforehand?

Owner

mattupstate commented Apr 18, 2013

Not that I can think of. Flask-Admin seems to have it figured out, thats about all I have to contribute as of now.

+1
Currently I encapsulate the strings from _default_messages and _default_email_subjects into the Flask-Babel lazy_gettext() and then set them into the app.config.

Unfortunately that doesn't work for _default_field_labels in forms.py. It might work if the definition of the _default_field_labels would be in another file, so it could be modified from the outside before the forms.py is imported. This is hacky and definitely not the best solution.

P.S. I use lazy_gettext() so the strings get translated on each access and not just once on initialization (or at least so I think, haven't tested it yet). This way the locale can change and the strings are then translated to the correct language.

macic commented Dec 5, 2013

I guess there was no progress on this recently. I will try and work on this in upcoming days.

Contributor

yoursdearboy commented Apr 26, 2017

In addition to Chris solution - to localize login message SECURITY_MSG_LOGIN it's also necessary to provide localize callback for login manager.

security = Security(app, user_datastore)
security.login_manager.localize_callback = lazy_gettext
Collaborator

jirikuncar commented Apr 27, 2017

@yoursdearboy the Flask-BabelEx has been integrated in #617 (originally from inveniosoftware#33). Please check if it works for you and in case you have a problem open new issue. Thank you!

@jirikuncar jirikuncar closed this Apr 27, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment