Internationalization (i18n) extension for Quart applications.
Project description
Quart i18n
quart-i18n is a simple and easy-to-use internationalization (i18n) extension for Quart web applications. It allows you to manage multilingual content and inject localized strings directly into templates.
Key Features
- Dynamic language handling
- JSON-based localization files
- Safe string formatting (missing keys do not raise errors)
- Async-compatible
render_templatewrapper - Easy integration with Quart applications
- Multiple language support via a simple list configuration
Installation
pip install quart-i18n
Quick Start
- Create a Quart application
from quart import Quart
from quart_i18n import I18n
app = Quart(__name__)
- Create localization configuration files
Create a locales/ folder and add JSON files:
locales/
├── index.json
├── about.json
Example index.json:
{
"en": {
"title": "Welcome, {username}!",
"description": "This is the English version."
},
"hu": {
"title": "Üdv, {username}!",
"description": "This is the Hungarian version."
}
}
- Initialize I18n
i18n = I18n(
appInstance=app,
languages=["en", "hu"],
configPath="locales",
defaultLanguage="en"
)
- Use in templates
The render_template wrapper automatically injects localization:
@app.route("/")
async def index():
return await i18n.render_template("index.html", username="Bali")
Example index.html:
<h1>{{ t.title }}</h1>
<p>{{ t.description }}</p>
Cookie-based Language Selection
I18n selects the language in the following order:
languagecookie value- If the cookie value is unsupported →
defaultLanguage
Error Handling
The package includes several custom exceptions:
ConfigNotFoundError– configuration directory or file is missingMissingPageError– JSON file for the requested page does not existInvalidConfigError– JSON parsing errorLanguageNotSupportedError– requested language is not in the supported list
Examples
Dynamic String Formatting
await i18n.render_template("index.html", displayname="Alice")
If displayname is not present in the JSON, SafeDict ensures no error is raised; the placeholder {displayname} remains in the template.
License
MIT License © 2025 Bali
Related Links
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 quart_i18n-0.1.0.tar.gz.
File metadata
- Download URL: quart_i18n-0.1.0.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
32d81db25c51d67630642a4154f554190469f5a714c1241bfc28c8d6634c6a26
|
|
| MD5 |
3cd2b3746eccc1bbb6cc2d596df405b2
|
|
| BLAKE2b-256 |
ec478d1e9392637406b9752729b3465ae4fd8e62e56dec73fd3416e898ea6f41
|
File details
Details for the file quart_i18n-0.1.0-py3-none-any.whl.
File metadata
- Download URL: quart_i18n-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4c3b81612707f2208bf1b4886d08da3cd13e466ed1aa79d069534c8a08548267
|
|
| MD5 |
7534387d877658da6597f7bb5765b16c
|
|
| BLAKE2b-256 |
8ffbe04443fc5a275290ec582f2a88b992357055cdce62a037889b47aec152b2
|