Production-grade i18n for Flask with Cyrillic and Asian language support
Project description
Flask-I18N-Pro
Internationalization for Flask with Cyrillic and Asian language support.
What it does
- 4-tier locale selection: URL parameter → Session → Accept-Language header → Default
- Cyrillic-aware formatting: Russian number formatting (1 234,56 instead of 1,234.56)
- Proper pluralization: Handles complex rules (Russian: 1/2-4/5+ forms)
- Context-aware translations: Disambiguate homonyms
- Time-ago utilities: "2 hours ago" with correct plurals
Built while working on wallmarkets. Tested with English, Russian, Mongolian, Chinese.
Installation
pip install flask-i18n-pro
Usage
Basic setup
from flask import Flask
from flask_i18n_pro import setup_i18n
app = Flask(__name__)
app.config['LANGUAGES'] = ['en', 'ru', 'mn', 'zh']
setup_i18n(app)
# Locale now auto-selected per request
Formatting in templates
{# Date/time #}
{{ order.created_at|format_order_datetime }}
{# en: "Dec 25, 2023, 2:30 PM" #}
{# ru: "25 дек. 2023 г., 14:30" #}
{# Price - Cyrillic formatting #}
{{ product.price|format_price('RUB') }}
{# en: "RUB 15,000.00" #}
{# ru: "15 000,00 ₽" (space separator!) #}
{# Time ago #}
{{ comment.created_at|time_ago }}
{# en: "2 minutes ago" #}
{# ru: "2 минуты назад" #}
Cyrillic number formatting
This is the main difference from Flask-Babel:
from flask_i18n_pro import format_weight
# With Russian locale
format_weight(1234.5) # → "1 234,5"
# Not "1,234.5" like Flask-Babel does
Locale selection
Automatic 4-tier fallback:
?lang=ruURL parameter → saves to sessionsession['lang']if previously setAccept-Languageheader from browser- Default configured language
Configuration
app.config['LANGUAGES'] = ['en', 'ru', 'mn', 'zh']
app.config['BABEL_DEFAULT_LOCALE'] = 'en'
app.config['BABEL_TRANSLATION_DIRECTORIES'] = 'translations'
License
MIT
Contributing
Pull requests welcome. Please add tests.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flask_i18n_pro-1.0.0.tar.gz.
File metadata
- Download URL: flask_i18n_pro-1.0.0.tar.gz
- Upload date:
- Size: 11.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1cb2d5f240b0c28083c676799bbc3cb6316440a0d07591b85880c8c2d18d34a
|
|
| MD5 |
0e10fcc1e8337d418f669df0404386d4
|
|
| BLAKE2b-256 |
a5e03868ed81b1f540d75d60e9b5ea5cf6c772ee452549edd7663337bededc00
|
File details
Details for the file flask_i18n_pro-1.0.0-py3-none-any.whl.
File metadata
- Download URL: flask_i18n_pro-1.0.0-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26114b7a5c18f3b84630e7eaccc5e104c56f8fdc7275a0d466890845f666ce5e
|
|
| MD5 |
13916871e20aff941970c70c7d256012
|
|
| BLAKE2b-256 |
e37653694bf578def0264440aa4456bf300dc8cf70db38adcbbb3bd033bf5987
|