Skip to main content

Internationalization (i18n) extension for Quart applications.

Project description

Quart i18n

License: MIT

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_template wrapper
  • Easy integration with Quart applications
  • Multiple language support via a simple list configuration

Installation

pip install quart-i18n

Quick Start

  1. Create a Quart application
from quart import Quart
from quart_i18n import I18n

app = Quart(__name__)
  1. 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."
  }
}
  1. Initialize I18n
i18n = I18n(
    appInstance=app,
    languages=["en", "hu"],
    configPath="locales",
    defaultLanguage="en"
)
  1. 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:

  1. language cookie value
  2. If the cookie value is unsupported → defaultLanguage

Error Handling

The package includes several custom exceptions:

  • ConfigNotFoundError – configuration directory or file is missing
  • MissingPageError – JSON file for the requested page does not exist
  • InvalidConfigError – JSON parsing error
  • LanguageNotSupportedError – 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


Download files

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

Source Distribution

quart_i18n-0.1.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

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

quart_i18n-0.1.0-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

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

Hashes for quart_i18n-0.1.0.tar.gz
Algorithm Hash digest
SHA256 32d81db25c51d67630642a4154f554190469f5a714c1241bfc28c8d6634c6a26
MD5 3cd2b3746eccc1bbb6cc2d596df405b2
BLAKE2b-256 ec478d1e9392637406b9752729b3465ae4fd8e62e56dec73fd3416e898ea6f41

See more details on using hashes here.

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

Hashes for quart_i18n-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4c3b81612707f2208bf1b4886d08da3cd13e466ed1aa79d069534c8a08548267
MD5 7534387d877658da6597f7bb5765b16c
BLAKE2b-256 8ffbe04443fc5a275290ec582f2a88b992357055cdce62a037889b47aec152b2

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