Name | yet-another-i18n JSON |
Version |
0.2.0
JSON |
| download |
home_page | None |
Summary | A lightweight and developer-friendly Python translation library designed for simplicity and flexibility. |
upload_time | 2025-02-03 18:41:09 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | MIT |
keywords |
i18n
json
localization
translation
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# yet another i18n
A lightweight and developer-friendly Python translation library designed for simplicity and flexibility.
## Features
- 🌐 json-based translation: easy-to-use translations powered by simple JSON files.
- 🔄 fallback language support: automatically provides translations in a fallback language when a specific translation is unavailable.
- 🧩 nested values and placeholders: fully supports nested structures and dynamic placeholders within translations.
- 🎛️ flexible translation styles: offers both preconfigured translations and on-the-fly translation generation.
- 🛠️ developer experience focused api: designed with developers in mind, drawing inspiration from other projects.
- ⚡ lightweight and simple: under 150 lines of code with no dependencies beyond Python's standard library.
## Usage
### 0. Installation
Install the package via pip:
```bash
pip install yet-another-i18n
```
### 1. Initialization
Create a `Translator` instance by specifying at least the fallback locale.
```python
from yai18n import Translator
translator = Translator(
fallback_locale="en",
)
```
- **fallback_locale** (required): The locale to use if the requested key is not found in any other locale.
- **default_locale** (optional): The primary locale used when none is explicitly provided.
- **locale_folder_path** (optional): Directory containing your JSON locale files. (default: `"locales"`)
- **debug** (optional): If `True`, locale files are reloaded before each translation (useful for development).
### 2. Locale Files
Each locale file should be a JSON file named `<locale>.json` within the specified `locale_folder_path`. Example:
`en.json`:
```json
{
"greeting": {
"hello": "Hello, {name}!"
}
}
```
### 3. Translation
To translate a key, simply call the `Translator` instance:
```python
message = translator("greeting.hello", locale="en", args={"name": "Alice"})
print(message) # Outputs: "Hello, Alice!"
```
- **key**: A string path (e.g., `"section.subsection.key"`) to the translated text.
- **locale** (optional): Override the default locale for this translation.
- **args** (optional): A dictionary to format dynamic placeholders in the translated text.
### 4. Fallback Behavior
If a key does not exist in the requested locale, the translator automatically uses the `fallback_locale`.
If the key is not found there either, a `KeyError` is raised.
### 5. Error Handling
- **ValueError**: Raised if a requested locale or default locale is not found.
- **TypeError**: Raised if arguments to methods are of incorrect types.
- **KeyError**: Raised if a translation key cannot be found in both the given and fallback locales.
## Contributors ✨
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
<!-- prettier-ignore-start -->
<!-- markdownlint-disable -->
<table>
<tbody>
<tr>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/2mal3"><img src="https://avatars.githubusercontent.com/u/56305732?v=4?s=100" width="100px;" alt="2mal3"/><br /><sub><b>2mal3</b></sub></a><br /><a href="https://github.com/2mal3/yet-another-i18n/commits?author=2mal3" title="Code">💻</a> <a href="https://github.com/2mal3/yet-another-i18n/commits?author=2mal3" title="Documentation">📖</a> <a href="#platform-2mal3" title="Packaging/porting to new platform">📦</a></td>
<td align="center" valign="top" width="14.28%"><a href="https://github.com/LuisSchuimer"><img src="https://avatars.githubusercontent.com/u/85784931?v=4?s=100" width="100px;" alt="Luis Schuimer"/><br /><sub><b>Luis Schuimer</b></sub></a><br /><a href="https://github.com/2mal3/yet-another-i18n/issues?q=author%3ALuisSchuimer" title="Bug reports">🐛</a> <a href="#userTesting-LuisSchuimer" title="User Testing">📓</a></td>
</tr>
</tbody>
</table>
<!-- markdownlint-restore -->
<!-- prettier-ignore-end -->
<!-- ALL-CONTRIBUTORS-LIST:END -->
This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!
Raw data
{
"_id": null,
"home_page": null,
"name": "yet-another-i18n",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "i18n, json, localization, translation",
"author": null,
"author_email": "2mal3 <56305732+2mal3@users.noreply.github.com>",
"download_url": "https://files.pythonhosted.org/packages/89/87/f9337ceaf98f5181425f7e3a2bc4d3465a143deb63416152128dd6a72c6d/yet_another_i18n-0.2.0.tar.gz",
"platform": null,
"description": "# yet another i18n\n\nA lightweight and developer-friendly Python translation library designed for simplicity and flexibility.\n\n## Features\n\n- \ud83c\udf10 json-based translation: easy-to-use translations powered by simple JSON files.\n- \ud83d\udd04 fallback language support: automatically provides translations in a fallback language when a specific translation is unavailable.\n- \ud83e\udde9 nested values and placeholders: fully supports nested structures and dynamic placeholders within translations.\n- \ud83c\udf9b\ufe0f flexible translation styles: offers both preconfigured translations and on-the-fly translation generation.\n- \ud83d\udee0\ufe0f developer experience focused api: designed with developers in mind, drawing inspiration from other projects.\n- \u26a1 lightweight and simple: under 150 lines of code with no dependencies beyond Python's standard library.\n\n## Usage\n\n### 0. Installation\n\nInstall the package via pip:\n\n```bash\npip install yet-another-i18n\n```\n\n### 1. Initialization\n\nCreate a `Translator` instance by specifying at least the fallback locale.\n\n```python\nfrom yai18n import Translator\n\ntranslator = Translator(\n fallback_locale=\"en\",\n)\n```\n\n- **fallback_locale** (required): The locale to use if the requested key is not found in any other locale.\n- **default_locale** (optional): The primary locale used when none is explicitly provided.\n- **locale_folder_path** (optional): Directory containing your JSON locale files. (default: `\"locales\"`)\n- **debug** (optional): If `True`, locale files are reloaded before each translation (useful for development).\n\n### 2. Locale Files\n\nEach locale file should be a JSON file named `<locale>.json` within the specified `locale_folder_path`. Example:\n\n`en.json`:\n\n```json\n{\n \"greeting\": {\n \"hello\": \"Hello, {name}!\"\n }\n}\n```\n\n### 3. Translation\n\nTo translate a key, simply call the `Translator` instance:\n\n```python\nmessage = translator(\"greeting.hello\", locale=\"en\", args={\"name\": \"Alice\"})\nprint(message) # Outputs: \"Hello, Alice!\"\n```\n\n- **key**: A string path (e.g., `\"section.subsection.key\"`) to the translated text.\n- **locale** (optional): Override the default locale for this translation.\n- **args** (optional): A dictionary to format dynamic placeholders in the translated text.\n\n### 4. Fallback Behavior\n\nIf a key does not exist in the requested locale, the translator automatically uses the `fallback_locale`.\nIf the key is not found there either, a `KeyError` is raised.\n\n### 5. Error Handling\n\n- **ValueError**: Raised if a requested locale or default locale is not found.\n- **TypeError**: Raised if arguments to methods are of incorrect types.\n- **KeyError**: Raised if a translation key cannot be found in both the given and fallback locales.\n\n## Contributors \u2728\n\nThanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):\n\n<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->\n<!-- prettier-ignore-start -->\n<!-- markdownlint-disable -->\n<table>\n <tbody>\n <tr>\n <td align=\"center\" valign=\"top\" width=\"14.28%\"><a href=\"https://github.com/2mal3\"><img src=\"https://avatars.githubusercontent.com/u/56305732?v=4?s=100\" width=\"100px;\" alt=\"2mal3\"/><br /><sub><b>2mal3</b></sub></a><br /><a href=\"https://github.com/2mal3/yet-another-i18n/commits?author=2mal3\" title=\"Code\">\ud83d\udcbb</a> <a href=\"https://github.com/2mal3/yet-another-i18n/commits?author=2mal3\" title=\"Documentation\">\ud83d\udcd6</a> <a href=\"#platform-2mal3\" title=\"Packaging/porting to new platform\">\ud83d\udce6</a></td>\n <td align=\"center\" valign=\"top\" width=\"14.28%\"><a href=\"https://github.com/LuisSchuimer\"><img src=\"https://avatars.githubusercontent.com/u/85784931?v=4?s=100\" width=\"100px;\" alt=\"Luis Schuimer\"/><br /><sub><b>Luis Schuimer</b></sub></a><br /><a href=\"https://github.com/2mal3/yet-another-i18n/issues?q=author%3ALuisSchuimer\" title=\"Bug reports\">\ud83d\udc1b</a> <a href=\"#userTesting-LuisSchuimer\" title=\"User Testing\">\ud83d\udcd3</a></td>\n </tr>\n </tbody>\n</table>\n\n<!-- markdownlint-restore -->\n<!-- prettier-ignore-end -->\n\n<!-- ALL-CONTRIBUTORS-LIST:END -->\n\nThis project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A lightweight and developer-friendly Python translation library designed for simplicity and flexibility.",
"version": "0.2.0",
"project_urls": {
"Homepage": "https://github.com/2mal3/yet-another-i18n",
"Issues": "https://github.com/2mal3/yet-another-i18n/issues",
"Repository": "https://github.com/2mal3/yet-another-i18n"
},
"split_keywords": [
"i18n",
" json",
" localization",
" translation"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "57e18cf7864c17236e27a409b920b1c4123031e330cb2a4f6d61e93ca2538f0a",
"md5": "31e09acddf5ae0f7198f50239bea8926",
"sha256": "b3e86d66ffcb4084cf429ab3a6a560e9210d292765d68de20fdba1e991cb939b"
},
"downloads": -1,
"filename": "yet_another_i18n-0.2.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "31e09acddf5ae0f7198f50239bea8926",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 5842,
"upload_time": "2025-02-03T18:41:07",
"upload_time_iso_8601": "2025-02-03T18:41:07.597536Z",
"url": "https://files.pythonhosted.org/packages/57/e1/8cf7864c17236e27a409b920b1c4123031e330cb2a4f6d61e93ca2538f0a/yet_another_i18n-0.2.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "8987f9337ceaf98f5181425f7e3a2bc4d3465a143deb63416152128dd6a72c6d",
"md5": "49f52afe595a20369bb33b4a758198e8",
"sha256": "3f36fe5665c8e219de7825bf5662b65ed74ec5bfc8bc0799bcc00af7e8f12fbb"
},
"downloads": -1,
"filename": "yet_another_i18n-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "49f52afe595a20369bb33b4a758198e8",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 6105,
"upload_time": "2025-02-03T18:41:09",
"upload_time_iso_8601": "2025-02-03T18:41:09.992508Z",
"url": "https://files.pythonhosted.org/packages/89/87/f9337ceaf98f5181425f7e3a2bc4d3465a143deb63416152128dd6a72c6d/yet_another_i18n-0.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-03 18:41:09",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "2mal3",
"github_project": "yet-another-i18n",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "yet-another-i18n"
}