{"library":"flask-babel","title":"Flask-Babel","description":"Flask-Babel is an extension for the Flask micro-framework that adds internationalization (i18n) and localization (l10n) support to Flask applications. It provides built-in features for date and time formatting with timezone support, as well as a friendly interface for gettext translations. The library is actively maintained, with the current version being 4.0.0, and has a consistent release cadence.","status":"active","version":"4.0.0","language":"en","source_language":"en","source_url":"https://github.com/python-babel/flask-babel","tags":["flask","i18n","l10n","internationalization","localization","babel"],"install":[{"cmd":"pip install Flask-Babel","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Requires Python 3.8 or newer for version 4.0.0.","package":"python","optional":false},{"reason":"Core library for i18n/l10n; Flask-Babel v3.1.0+ requires Babel 12.2 or greater.","package":"babel","optional":false},{"reason":"The web framework it extends.","package":"flask","optional":false},{"reason":"For template integration; Flask-Babel v3.0.0+ requires Jinja 3 or greater.","package":"jinja2","optional":false},{"reason":"For timezone handling; became an explicit dependency in v1.0.0.","package":"pytz","optional":false},{"reason":"Flask's WSGI utility library, had a deprecated import fix in v1.0.0.","package":"werkzeug","optional":false}],"imports":[{"note":"The `flask.ext` prefix was deprecated in Flask for extensions; direct import from `flask_babel` is correct since Flask 0.8.","wrong":"from flask.ext.babel import Babel","symbol":"Babel","correct":"from flask_babel import Babel"},{"note":"Both `gettext` and `_` are commonly used aliases for marking translatable strings.","symbol":"gettext","correct":"from flask_babel import gettext\nfrom flask_babel import _"}],"quickstart":{"code":"from flask import Flask, render_template, request\nfrom flask_babel import Babel, gettext\n\napp = Flask(__name__)\napp.config['BABEL_DEFAULT_LOCALE'] = 'en'\napp.config['LANGUAGES'] = {'en': 'English', 'de': 'Deutsch'}\n\nbabel = Babel(app)\n\n@babel.localeselector\ndef get_locale():\n    # Try to guess the language from the user's browser accept header\n    # or use a default/configured locale.\n    return request.accept_languages.best_match(list(app.config['LANGUAGES'].keys()))\n\n@app.route('/')\ndef index():\n    return f\"<h1>{gettext('Hello, World!')}</h1>\"\n\n# To run this example, you would also need a `messages.po` file and compile it.\n# 1. Create a `babel.cfg` file:\n#    [python: **.py]\n#    [jinja2: **/templates/**.html]\n# 2. Extract messages:\n#    pybabel extract -F babel.cfg -o messages.pot .\n# 3. Initialize translation for a language (e.g., German):\n#    pybabel init -i messages.pot -d translations -l de\n# 4. Translate strings in `translations/de/LC_MESSAGES/messages.po`\n# 5. Compile translations:\n#    pybabel compile -d translations\n\nif __name__ == '__main__':\n    app.run(debug=True)","lang":"python","description":"This quickstart demonstrates how to initialize Flask-Babel with a Flask application, set up default locales and available languages, and define a `localeselector` function to determine the user's preferred language. It also includes basic usage of `gettext` for string internationalization and outlines the necessary `pybabel` commands for translation file management."},"warnings":[{"fix":"Upgrade Python to 3.8 or newer. Alternatively, pin `Flask-Babel<4.0.0`.","message":"Version 4.0.0 dropped support for Python 3.7. Applications running on Python 3.7 or older must upgrade their Python environment or use an older Flask-Babel version.","severity":"breaking","affected_versions":"4.0.0+"},{"fix":"Update `Babel` to version 12.2 or higher (`pip install -U Babel`).","message":"Version 3.1.0 requires Babel 12.2 or greater. Ensure your `babel` package is updated to avoid compatibility issues, particularly with localized time formatting.","severity":"breaking","affected_versions":"3.1.0+"},{"fix":"Upgrade Python to 3.7+ (preferably 3.8+ for v4.0.0) and Jinja2 to version 3 or greater (`pip install -U Jinja2`).","message":"Version 3.0.0 made several significant breaking changes, including dropping support for Python 3.5 and 3.6, and requiring Jinja version 3 or greater.","severity":"breaking","affected_versions":"3.0.0+"},{"fix":"Replace any usage of `Babel._date_formats` with `Babel.date_formats`.","message":"In version 3.0.0, the internal attribute `Babel._date_formats` was removed. Users should now use the public `Babel.date_formats` attribute instead.","severity":"breaking","affected_versions":"3.0.0+"},{"fix":"Update import statements from `from flask.ext.babel import ...` to `from flask_babel import ...`.","message":"Older Flask extensions used the `flask.ext` namespace (e.g., `flask.ext.babel`). This pattern is deprecated. Always import directly from `flask_babel`.","severity":"gotcha","affected_versions":"<1.0.0 (old codebases)"},{"fix":"Ensure all date and time storage and manipulation within your application consistently uses UTC. Convert to local timezones only at the presentation layer using Flask-Babel's formatting functions.","message":"Flask-Babel defaults the `BABEL_DEFAULT_TIMEZONE` to 'UTC'. It is crucial that your application internally uses 'UTC' for date and time storage to prevent unexpected behavior with user-facing localized dates.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-06T00:00:00.000Z","next_check":"2026-07-05T00:00:00.000Z"}