quart-i18n


Namequart-i18n JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/1bali1/quart-i18n
SummaryInternationalization (i18n) extension for Quart applications.
upload_time2025-09-01 17:16:42
maintainerNone
docs_urlNone
author1bali1
requires_python>=3.10
licenseMIT
keywords quart i18n internationalization localization translation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# Quart i18n

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

`quart-i18n` is a simple and easy-to-use **internationalization (i18n) extension** for [Quart](https://pgjones.gitlab.io/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

```bash
pip install quart-i18n
```

---

## Quick Start

1. **Create a Quart application**

```python
from quart import Quart
from quart_i18n import I18n

app = Quart(__name__)
```

2. **Create localization configuration files**

Create a `locales/` folder and add JSON files:

```
locales/
├── index.json
├── about.json
```

Example `index.json`:

```json
{
  "en": {
    "title": "Welcome, {username}!",
    "description": "This is the English version."
  },
  "hu": {
    "title": "Üdv, {username}!",
    "description": "This is the Hungarian version."
  }
}
```

3. **Initialize I18n**

```python
i18n = I18n(
    appInstance=app,
    languages=["en", "hu"],
    configPath="locales",
    defaultLanguage="en"
)
```

4. **Use in templates**

The `render_template` wrapper automatically injects localization:

```python
@app.route("/")
async def index():
    return await i18n.render_template("index.html", username="Bali")
```

Example `index.html`:

```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

```python
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](mailto:info@1bali1.hu)

---

## Related Links

* [GitHub repository](https://github.com/1bali1/quart-i18n)
* [PyPI](https://pypi.org/project/quart-i18n)
* [Quart documentation](https://pgjones.gitlab.io/quart/)

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/1bali1/quart-i18n",
    "name": "quart-i18n",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "quart, i18n, internationalization, localization, translation",
    "author": "1bali1",
    "author_email": "Bali <info@1bali1.hu>",
    "download_url": "https://files.pythonhosted.org/packages/ec/47/8d1e9392637406b9752729b3465ae4fd8e62e56dec73fd3416e898ea6f41/quart_i18n-0.1.0.tar.gz",
    "platform": null,
    "description": "\r\n# Quart i18n\r\n\r\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\r\n\r\n`quart-i18n` is a simple and easy-to-use **internationalization (i18n) extension** for [Quart](https://pgjones.gitlab.io/quart/) web applications. It allows you to manage multilingual content and inject localized strings directly into templates.\r\n\r\n---\r\n\r\n## Key Features\r\n\r\n- Dynamic language handling\r\n- JSON-based localization files\r\n- Safe string formatting (missing keys do not raise errors)\r\n- Async-compatible `render_template` wrapper\r\n- Easy integration with Quart applications\r\n- Multiple language support via a simple list configuration\r\n\r\n---\r\n\r\n## Installation\r\n\r\n```bash\r\npip install quart-i18n\r\n```\r\n\r\n---\r\n\r\n## Quick Start\r\n\r\n1. **Create a Quart application**\r\n\r\n```python\r\nfrom quart import Quart\r\nfrom quart_i18n import I18n\r\n\r\napp = Quart(__name__)\r\n```\r\n\r\n2. **Create localization configuration files**\r\n\r\nCreate a `locales/` folder and add JSON files:\r\n\r\n```\r\nlocales/\r\n\u251c\u2500\u2500 index.json\r\n\u251c\u2500\u2500 about.json\r\n```\r\n\r\nExample `index.json`:\r\n\r\n```json\r\n{\r\n  \"en\": {\r\n    \"title\": \"Welcome, {username}!\",\r\n    \"description\": \"This is the English version.\"\r\n  },\r\n  \"hu\": {\r\n    \"title\": \"\u00dcdv, {username}!\",\r\n    \"description\": \"This is the Hungarian version.\"\r\n  }\r\n}\r\n```\r\n\r\n3. **Initialize I18n**\r\n\r\n```python\r\ni18n = I18n(\r\n    appInstance=app,\r\n    languages=[\"en\", \"hu\"],\r\n    configPath=\"locales\",\r\n    defaultLanguage=\"en\"\r\n)\r\n```\r\n\r\n4. **Use in templates**\r\n\r\nThe `render_template` wrapper automatically injects localization:\r\n\r\n```python\r\n@app.route(\"/\")\r\nasync def index():\r\n    return await i18n.render_template(\"index.html\", username=\"Bali\")\r\n```\r\n\r\nExample `index.html`:\r\n\r\n```html\r\n<h1>{{ t.title }}</h1>\r\n<p>{{ t.description }}</p>\r\n```\r\n\r\n---\r\n\r\n## Cookie-based Language Selection\r\n\r\n`I18n` selects the language in the following order:\r\n\r\n1. `language` cookie value\r\n2. If the cookie value is unsupported \u2192 `defaultLanguage`\r\n\r\n---\r\n\r\n## Error Handling\r\n\r\nThe package includes several custom exceptions:\r\n\r\n* `ConfigNotFoundError` \u2013 configuration directory or file is missing\r\n* `MissingPageError` \u2013 JSON file for the requested page does not exist\r\n* `InvalidConfigError` \u2013 JSON parsing error\r\n* `LanguageNotSupportedError` \u2013 requested language is not in the supported list\r\n\r\n---\r\n\r\n## Examples\r\n\r\n### Dynamic String Formatting\r\n\r\n```python\r\nawait i18n.render_template(\"index.html\", displayname=\"Alice\")\r\n```\r\n\r\nIf `displayname` is not present in the JSON, SafeDict ensures no error is raised; the placeholder `{displayname}` remains in the template.\r\n\r\n---\r\n\r\n## License\r\n\r\nMIT License \u00a9 2025 [Bali](mailto:info@1bali1.hu)\r\n\r\n---\r\n\r\n## Related Links\r\n\r\n* [GitHub repository](https://github.com/1bali1/quart-i18n)\r\n* [PyPI](https://pypi.org/project/quart-i18n)\r\n* [Quart documentation](https://pgjones.gitlab.io/quart/)\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Internationalization (i18n) extension for Quart applications.",
    "version": "0.1.0",
    "project_urls": {
        "Documentation": "https://github.com/1bali1/quart-i18n#readme",
        "Homepage": "https://github.com/1bali1/quart-i18n",
        "Issues": "https://github.com/1bali1/quart-i18n/issues",
        "Repository": "https://github.com/1bali1/quart-i18n"
    },
    "split_keywords": [
        "quart",
        " i18n",
        " internationalization",
        " localization",
        " translation"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "8ffbe04443fc5a275290ec582f2a88b992357055cdce62a037889b47aec152b2",
                "md5": "7534387d877658da6597f7bb5765b16c",
                "sha256": "4c3b81612707f2208bf1b4886d08da3cd13e466ed1aa79d069534c8a08548267"
            },
            "downloads": -1,
            "filename": "quart_i18n-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "7534387d877658da6597f7bb5765b16c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 6847,
            "upload_time": "2025-09-01T17:16:40",
            "upload_time_iso_8601": "2025-09-01T17:16:40.727965Z",
            "url": "https://files.pythonhosted.org/packages/8f/fb/e04443fc5a275290ec582f2a88b992357055cdce62a037889b47aec152b2/quart_i18n-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "ec478d1e9392637406b9752729b3465ae4fd8e62e56dec73fd3416e898ea6f41",
                "md5": "3cd2b3746eccc1bbb6cc2d596df405b2",
                "sha256": "32d81db25c51d67630642a4154f554190469f5a714c1241bfc28c8d6634c6a26"
            },
            "downloads": -1,
            "filename": "quart_i18n-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3cd2b3746eccc1bbb6cc2d596df405b2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 7467,
            "upload_time": "2025-09-01T17:16:42",
            "upload_time_iso_8601": "2025-09-01T17:16:42.118206Z",
            "url": "https://files.pythonhosted.org/packages/ec/47/8d1e9392637406b9752729b3465ae4fd8e62e56dec73fd3416e898ea6f41/quart_i18n-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-01 17:16:42",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "1bali1",
    "github_project": "quart-i18n",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "quart-i18n"
}
        
Elapsed time: 1.04741s