{"id":28127,"library":"quart-babel","title":"Quart-Babel","description":"Implements i18n and l10n support for Quart, the async Python web microframework. Current version 1.0.7. Release cadence is irregular, with several breaking changes in recent versions.","status":"active","version":"1.0.7","language":"python","source_language":"en","source_url":"https://github.com/Quart-Addons/quart-babel","tags":["quart","babel","i18n","l10n","internationalization","localization"],"install":[{"cmd":"pip install quart-babel","lang":"bash","label":"pip install"}],"dependencies":[{"reason":"Required web framework","package":"Quart","optional":false},{"reason":"Core localization library","package":"Babel","optional":false},{"reason":"Often used for locale config","package":"python-dotenv","optional":true}],"imports":[{"note":"Babel is exported directly from quart_babel, not a submodule","wrong":"from quart_babel.babel import Babel","symbol":"Babel","correct":"from quart_babel import Babel"},{"note":"gettext functions are top-level in quart_babel","wrong":"from quart_babel.utils import gettext","symbol":"gettext functions","correct":"from quart_babel import gettext, ngettext, lazy_gettext"},{"note":"Format functions are exported directly from quart_babel","wrong":"from quart_babel.dates import format_date","symbol":"format_date","correct":"from quart_babel import format_date, format_datetime, format_number"}],"quickstart":{"code":"import os\nfrom quart import Quart\nfrom quart_babel import Babel, gettext, set_locale\n\napp = Quart(__name__)\napp.config['BABEL_DEFAULT_LOCALE'] = os.environ.get('BABEL_DEFAULT_LOCALE', 'en')\nbabel = Babel(app)\n\n@app.route('/')\nasync def index():\n    return gettext('Hello World')\n\nif __name__ == '__main__':\n    app.run()","lang":"python","description":"Basic Quart-Babel setup with a simple route using gettext."},"warnings":[{"fix":"Remove 'await' calls from gettext, format_date, etc. Import directly from quart_babel.","message":"In version 1.0.6, the extension was rewritten as a copy of Flask-Babel, removing the ASGI middleware. All functions (gettext, format_date, etc.) are now synchronous, not async. Update your routes and templates accordingly.","severity":"breaking","affected_versions":">=1.0.6"},{"fix":"Upgrade to >=1.0.6, which reverts to Flask-Babel style without middleware.","message":"Version 1.0.0 introduced ASGI middleware for locale/timezone detection, which broke compatibility with Quart-WTF and other extensions. Version 1.0.6 removed that middleware again.","severity":"breaking","affected_versions":"1.0.0 - 1.0.5"},{"fix":"Pass a locale_selector function when initializing Babel: Babel(app, locale_selector=lambda: request.headers.get('Accept-Language', 'en')[0:2])","message":"Quart-Babel does not automatically detect the browser's language. You must implement your own locale selector (e.g., from request headers).","severity":"gotcha","affected_versions":"All"},{"fix":"Store lazy_gettext in a lambda or function, or use it only inside templates and forms.","message":"Lazy gettext (lazy_gettext) cannot be used directly in route decorators because it's evaluated at template rendering time. Use it in form definitions or with callables.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Remove 'await' from gettext, format_date, etc. They are synchronous functions.","cause":"Using 'await' with gettext/format_date, which are synchronous in versions >=1.0.6.","error":"TypeError: can't use async function in non-async context"},{"fix":"Use 'from quart_babel import Babel'.","cause":"Importing from wrong module (e.g., 'from quart_babel.babel import Babel').","error":"AttributeError: module 'quart_babel' has no attribute 'Babel'"},{"fix":"Ensure gettext is called within a route or template, or use lazy_gettext outside context.","cause":"Calling gettext outside of a Quart request context (e.g., at module level).","error":"RuntimeError: No current application context"},{"fix":"Use 'from quart_babel import format_date' directly.","cause":"Trying to import from a submodule like 'quart_babel.dates' in old versions.","error":"ImportError: cannot import name 'format_date' from 'quart_babel'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}