Skip to main content

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:

  1. ?lang=ru URL parameter → saves to session
  2. session['lang'] if previously set
  3. Accept-Language header from browser
  4. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flask_i18n_pro-1.0.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

flask_i18n_pro-1.0.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

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

Hashes for flask_i18n_pro-1.0.0.tar.gz
Algorithm Hash digest
SHA256 b1cb2d5f240b0c28083c676799bbc3cb6316440a0d07591b85880c8c2d18d34a
MD5 0e10fcc1e8337d418f669df0404386d4
BLAKE2b-256 a5e03868ed81b1f540d75d60e9b5ea5cf6c772ee452549edd7663337bededc00

See more details on using hashes here.

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

Hashes for flask_i18n_pro-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 26114b7a5c18f3b84630e7eaccc5e104c56f8fdc7275a0d466890845f666ce5e
MD5 13916871e20aff941970c70c7d256012
BLAKE2b-256 e37653694bf578def0264440aa4456bf300dc8cf70db38adcbbb3bd033bf5987

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page