This Flask app supports multiple Indian languages using Flask-Babel.
- English (en)
- Hindi (हिंदी)
- Marathi (मराठी)
- Tamil (தமிழ்)
- Telugu (తెలుగు)
- Bengali (বাংলা)
- Gujarati (ગુજરાતી)
-
Install dependencies:
pip install -r requirements.txt
-
Extract translatable strings:
pybabel extract -F babel.cfg -k _ -o messages.pot . -
Initialize translation files (first time only):
./init_translations.sh
Or manually:
pybabel init -i messages.pot -d translations -l hi pybabel init -i messages.pot -d translations -l mr # ... repeat for other languages -
Edit translation files: Edit
translations/{lang}/LC_MESSAGES/messages.poand add translations for eachmsgstr ""entry. -
Compile translations:
pybabel compile -d translations
-
Update translations (after adding new strings):
pybabel extract -F babel.cfg -k _ -o messages.pot . pybabel update -i messages.pot -d translations # Then edit and compile as above
Wrap translatable strings with {{ _('Your text here') }}:
<h1>{{ _('Welcome to Solaris') }}</h1>
<p>{{ _('Smart rooftop solar estimator') }}</p>from flask_babel import gettext as _
flash(_('Language changed successfully.'), 'success')Users can change language using the dropdown in the header. The selection is stored in the session and persists across pages.