Flask Application with Multi-Language Support (TR-EN-DE-FR)
git clone https://github.com/nuriozbey/flask-babel-example.git
python -m venv venv
venv\Scripts\activate
cd flask-babel-example
pip install flask
pip install flask-babel
pip install pybabel
pip install -r requirements.txt
python .\main.py
# config.py
BABEL_DEFAULT_LOCALE = 'tr'
BABEL_DEFAULT_TIMEZONE = 'Europe/Istanbul'
BABEL_TRANSLATION_DIRECTORIES = 'translations'
# main.py
from flask_babel import _
@app.route('/')
def index():
return render_template('index.html', title=_('Home'))
# translations/tr/LC_MESSAGES/messages.po
msgid "Home"
msgstr "Ana Sayfa"
# babel.cfg
[python: **.py]
[jinja2: **/templates/**.html]
[extractors]
jinja2 = jinja2.ext.babel_extract
pybabel extract -F babel.cfg -o messages.pot .
pybabel init -i messages.pot -d translations -l tr
pybabel init -i messages.pot -d translations -l de
pybabel init -i messages.pot -d translations -l fr
pybabel init -i messages.pot -d translations -l es
pybabel compile -d translations
python .\main.py
pybabel extract -F babel.cfg -o messages.pot . --no-wrap
pybabel update -i messages.pot -d translations --no-wrap
pybabel compile -d translations
python .\main.py
GNU General Public License v3.0
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.