Skip to main content
Join the official 2020 Python Developers SurveyStart the survey!

Babel localisation support for aiohttp

Project description

aiohttp_babel adds i18n and l10n support to aiohttp.


import aiohttp_jinja2
from aiohttp.web import Application
from aiohttp_babel.locale import (load_gettext_translations,
from aiohttp_babel.middlewares import babel_middleware, _

set_default_locale('en_GB')  # set default locale, if necessary
# load compiled locales
load_gettext_translations('/path/to/locales', 'domain')

# you can use your own locale detection method, if necessary.
# aiohttp_babel checks cookie parameter `locale` or `Accept-Language`
# header by default.
def detector(request):
    if == '':
        return 'es'
    elif == '':
        return 'zh'
        return 'en'

jinja_loader = jinja2.FileSystemLoader('./templates')
app = Application(middlewares=[babel_middleware])

aiohttp_jinja2.setup(app, loader=jinja_loader)
jinja_env = aiohttp_jinja2.get_env(app)
jinja_env.globals['_'] = _

Project details

Download files

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

Files for aiohttpbabel, version 0.0.7
Filename, size File type Python version Upload date Hashes
Filename, size aiohttpbabel-0.0.7-py3-none-any.whl (5.5 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size aiohttpbabel-0.0.7.tar.gz (5.5 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page