inveniosoftware / flask-breadcrumbs

Flask-Breadcrumbs is a Flask extension that adds support for generating site breadcrumb navigation.
https://flask-breadcrumbs.readthedocs.io
Other
30 stars 23 forks source link

Support internationalization #54

Closed TheKruspe closed 2 years ago

TheKruspe commented 2 years ago

If you want to translate your breadcrumbs, you might face the following issue:

@register_breadcrumb(app, ".", _("Translate This"))

will throw Out Of Application Context error.

@register_breadcrumb(app, ".", lambda: _("Translate This"))

will leave you with a string like this: [<function <lambda> at 0x7d8fe8ad0630>]

The only possible way I found wass using dynamic_list_constructor like this:

@register_breadcrumb(app, ".", "", dynamic_list_constructor=lambda: [{"text": _("Translate This"), "url": ""}])

but this way the url needs to be entered manually.

lnielsen commented 2 years ago

Flask-Breadcrumbs already supports I18N. See example in https://github.com/inveniosoftware/invenio-accounts/blob/master/invenio_accounts/views/security.py

However, you probably need to use the lazy gettext: from flask_babel import lazy_gettext as _