aiohttp_babel
aiohttp_babel adds i18n and l10n support to aiohttp.
Usage:
import aiohttp_jinja2
from aiohttp.web import Application
from aiohttp_babel.locale import (load_gettext_translations,
set_default_locale,
set_locale_detector)
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 request.url.host == 'es.example.com':
return 'es'
elif request.url.host == 'zh.example.com':
return 'zh'
else:
return 'en'
set_locale_detector(detector)
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['_'] = _
How to extract & compile locales:
Code from:
tornado-babel: https://github.com/openlabs/tornado-babel
django-babel: https://github.com/python-babel/django-babel
Metadata
Release files for aiohttpbabel 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aiohttpbabel-0.0.7.tar.gz | 5.5 kB | Without provenance | Details for aiohttpbabel-0.0.7.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| aiohttpbabel-0.0.7-py3-none-any.whl | Python 3 | none | any | Details for aiohttpbabel-0.0.7-py3-none-any.whl |
Total release size: 11.0 kB
Release files / aiohttpbabel-0.0.7.tar.gz
| Download URL | aiohttpbabel-0.0.7.tar.gz |
|---|---|
| Size | 5.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e4907ebaeb572cf100e2dc14aa58a754dd205ab791f796561ac67de14cf4dfa8
|
|
BLAKE2b-256 checksum How to use checksums |
49c159cf84ef5d81176f9616234fe9999d0128a63426ee947669a32027e8686a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
|
Release files / aiohttpbabel-0.0.7-py3-none-any.whl
| Download URL | aiohttpbabel-0.0.7-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0762b5db57956049e80d576a65483ab8deccdd316109c4490b4aa99b09a9efdf
|
|
BLAKE2b-256 checksum How to use checksums |
4b94e4297d9c974ce4841702779043c1364ae00299e2a226f72c57b495894f1c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
|
Security for aiohttpbabel 0.0.7
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.