locotoml


Namelocotoml JSON
Version 0.2.0 PyPI version JSON
download
home_pagehttps://github.com/drago-suzuki58/LocoTOML
SummaryLocoTOML is a lightweight Python library for multi-language support, using hierarchical TOML-based translations with fallback and detailed logging for missing keys.
upload_time2024-11-17 19:28:33
maintainerNone
docs_urlNone
authordrago-suzuki58
requires_python<4.0,>=3.11
licenseMIT
keywords toml localization translation localisation multi-language
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # LocoTOML

LocoTOML is a brand new library for multilingual support in Python programs, designed to be the lightest possible. It uses only the standard library and has no external dependencies.

However, LocoTOML depends on a core library called [LocoCore](https://github.com/drago-suzuki58/LocoCore). LocoCore provides common multilingual support features, and LocoTOML adds TOML-based translation functionality on top of it.

Other Language LEADME (GitHub)
[Japanese](https://github.com/drago-suzuki58/LocoTOML/blob/main/README.ja.md)

## Features

- **Easy Calls**:

  You can easily call translations by writing `loc.key1.key2.key3()`, improving code readability. For more details, please refer to the documentation.

- **Flexible Calls**:

  If you want to output in English just this time, you can temporarily change the language by writing `loc.key1("en")`.

- **Easy-to-understand TOML Translations**:

  Translations are in TOML format, making it easy to load files corresponding to each language.

- **Hierarchical Translation Structure**:

  You can handle multiple keys hierarchically, such as `key1.key2.key3`, making it comfortable to use even when the data grows.

- **Detailed Log Output**:

  When translation keys are incomplete or errors occur, detailed logs including the file name and line number of the relevant part are output, making troubleshooting easy.

- **Fallback**:

  If a translation corresponding to the language is not found, it automatically falls back to the default language set. If there is no translation at all, the translation ID is output as is, clearly notifying the developer.

## Installation

Install from PyPI

```sh
pip install locotoml
```

Alternatively, you can install it from the GitHub repository:

```sh
python -m pip install git+https://github.com/drago-suzuki58/LocoTOML
```

## Sample Code

Basic Usage

`main.py`
```python
from locotoml import LocoTOML

# Set the default language to Japanese and the fallback language to English
loc = LocoTOML(locale="ja", fallback_locale="en", locale_dir="loc")

# こんにちは
print(loc.greeting.hello())

# こんにちは!太郎さん
print(loc.greeting.hello_to_user(user="太郎"))
```

Temporarily Specify Language for Translation

`main.py`
```python
# Hello
print(loc.greeting.hello("en"))

# Hello! John
print(loc.greeting.hello_to_user("en", user="John"))
```

Fallback Example
t notifies the relevant line and file name where it was called, supporting development.

`main.py`
```python
# Log: 2024-11-17 20:23:03 | WARNING    | main.py:18 - Missing translation: greeting.hello in: fr, return key name
# Hello
print(loc.greeting.hello("fr")) # Non-existent translation language

# Log: 2024-11-17 20:23:03 | WARNING    | main.py:23 - Missing translation: greeting.goodbye in: ja, falling back to en
# Log: 2024-11-17 20:23:03 | WARNING    | main.py:25 - Missing translation: greeting.goodbye in: en, return key name
# greeting.goodbye
print(loc.greeting.goodbye())
```

Unused Arguments Example
It notifies the relevant line and file name in the log, similar to fallback.

`main.py`
```python
# Log: 2024-11-17 20:23:03 | WARNING    | main.py:29 - Unused keys: {'message': 'hogehoge'}
# こんにちは
print(loc.greeting.hello(message="hogehoge"))
```

Translation Files Used in `main.py`

`loc/ja.toml`
```toml
sample = "サンプル"

[greeting]
hello = "こんにちは"
hello_to_user = "こんにちは!{user}さん"
```

`loc/en.toml`
```toml
sample = "Sample"

[greeting]
hello = "Hello"
hello_to_user = "Hello! {user}"
```

In addition to the above sample code, practical examples are available in the [example](https://github.com/drago-suzuki58/LocoTOML/tree/main/examples) folder. Please take a look.

## Q&A

### What language codes should I use for translations?

Basically, you are free to use any language code as long as it matches the TOML file name. (Even `UwU.toml` will be recognized correctly!) However, for readability, we recommend using standard formats such as ISO 639-1 (`en`, etc.) or ISO-3166 (`US`).

### Are default and fallback languages required?

The default language is required, but the fallback language is not. If not set, `en` will be automatically set as the fallback language.

### Can I use formats other than TOML (e.g., YAML)?

No, currently only TOML is supported. If there is high demand, we may develop a separate library like LocoYAML.

## Contribution

LocoTOML is an open-source project! Bug reports and feature suggestions are welcome.

## Update Info

<details>
<summary>Click to show update information</summary>

### v0.2.0

- Initial release

</details>

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/drago-suzuki58/LocoTOML",
    "name": "locotoml",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.11",
    "maintainer_email": null,
    "keywords": "toml, localization, translation, localisation, multi-language",
    "author": "drago-suzuki58",
    "author_email": "dorasuzu58@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c2/92/37404798016e48b676102d7317d2ae7b97c2c8f38657e99c5df54630c959/locotoml-0.2.0.tar.gz",
    "platform": null,
    "description": "# LocoTOML\n\nLocoTOML is a brand new library for multilingual support in Python programs, designed to be the lightest possible. It uses only the standard library and has no external dependencies.\n\nHowever, LocoTOML depends on a core library called [LocoCore](https://github.com/drago-suzuki58/LocoCore). LocoCore provides common multilingual support features, and LocoTOML adds TOML-based translation functionality on top of it.\n\nOther Language LEADME (GitHub)\n[Japanese](https://github.com/drago-suzuki58/LocoTOML/blob/main/README.ja.md)\n\n## Features\n\n- **Easy Calls**:\n\n  You can easily call translations by writing `loc.key1.key2.key3()`, improving code readability. For more details, please refer to the documentation.\n\n- **Flexible Calls**:\n\n  If you want to output in English just this time, you can temporarily change the language by writing `loc.key1(\"en\")`.\n\n- **Easy-to-understand TOML Translations**:\n\n  Translations are in TOML format, making it easy to load files corresponding to each language.\n\n- **Hierarchical Translation Structure**:\n\n  You can handle multiple keys hierarchically, such as `key1.key2.key3`, making it comfortable to use even when the data grows.\n\n- **Detailed Log Output**:\n\n  When translation keys are incomplete or errors occur, detailed logs including the file name and line number of the relevant part are output, making troubleshooting easy.\n\n- **Fallback**:\n\n  If a translation corresponding to the language is not found, it automatically falls back to the default language set. If there is no translation at all, the translation ID is output as is, clearly notifying the developer.\n\n## Installation\n\nInstall from PyPI\n\n```sh\npip install locotoml\n```\n\nAlternatively, you can install it from the GitHub repository:\n\n```sh\npython -m pip install git+https://github.com/drago-suzuki58/LocoTOML\n```\n\n## Sample Code\n\nBasic Usage\n\n`main.py`\n```python\nfrom locotoml import LocoTOML\n\n# Set the default language to Japanese and the fallback language to English\nloc = LocoTOML(locale=\"ja\", fallback_locale=\"en\", locale_dir=\"loc\")\n\n# \u3053\u3093\u306b\u3061\u306f\nprint(loc.greeting.hello())\n\n# \u3053\u3093\u306b\u3061\u306f\uff01\u592a\u90ce\u3055\u3093\nprint(loc.greeting.hello_to_user(user=\"\u592a\u90ce\"))\n```\n\nTemporarily Specify Language for Translation\n\n`main.py`\n```python\n# Hello\nprint(loc.greeting.hello(\"en\"))\n\n# Hello! John\nprint(loc.greeting.hello_to_user(\"en\", user=\"John\"))\n```\n\nFallback Example\nt notifies the relevant line and file name where it was called, supporting development.\n\n`main.py`\n```python\n# Log: 2024-11-17 20:23:03 | WARNING    | main.py:18 - Missing translation: greeting.hello in: fr, return key name\n# Hello\nprint(loc.greeting.hello(\"fr\")) # Non-existent translation language\n\n# Log: 2024-11-17 20:23:03 | WARNING    | main.py:23 - Missing translation: greeting.goodbye in: ja, falling back to en\n# Log: 2024-11-17 20:23:03 | WARNING    | main.py:25 - Missing translation: greeting.goodbye in: en, return key name\n# greeting.goodbye\nprint(loc.greeting.goodbye())\n```\n\nUnused Arguments Example\nIt notifies the relevant line and file name in the log, similar to fallback.\n\n`main.py`\n```python\n# Log: 2024-11-17 20:23:03 | WARNING    | main.py:29 - Unused keys: {'message': 'hogehoge'}\n# \u3053\u3093\u306b\u3061\u306f\nprint(loc.greeting.hello(message=\"hogehoge\"))\n```\n\nTranslation Files Used in `main.py`\n\n`loc/ja.toml`\n```toml\nsample = \"\u30b5\u30f3\u30d7\u30eb\"\n\n[greeting]\nhello = \"\u3053\u3093\u306b\u3061\u306f\"\nhello_to_user = \"\u3053\u3093\u306b\u3061\u306f\uff01{user}\u3055\u3093\"\n```\n\n`loc/en.toml`\n```toml\nsample = \"Sample\"\n\n[greeting]\nhello = \"Hello\"\nhello_to_user = \"Hello! {user}\"\n```\n\nIn addition to the above sample code, practical examples are available in the [example](https://github.com/drago-suzuki58/LocoTOML/tree/main/examples) folder. Please take a look.\n\n## Q&A\n\n### What language codes should I use for translations?\n\nBasically, you are free to use any language code as long as it matches the TOML file name. (Even `UwU.toml` will be recognized correctly!) However, for readability, we recommend using standard formats such as ISO 639-1 (`en`, etc.) or ISO-3166 (`US`).\n\n### Are default and fallback languages required?\n\nThe default language is required, but the fallback language is not. If not set, `en` will be automatically set as the fallback language.\n\n### Can I use formats other than TOML (e.g., YAML)?\n\nNo, currently only TOML is supported. If there is high demand, we may develop a separate library like LocoYAML.\n\n## Contribution\n\nLocoTOML is an open-source project! Bug reports and feature suggestions are welcome.\n\n## Update Info\n\n<details>\n<summary>Click to show update information</summary>\n\n### v0.2.0\n\n- Initial release\n\n</details>\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "LocoTOML is a lightweight Python library for multi-language support, using hierarchical TOML-based translations with fallback and detailed logging for missing keys.",
    "version": "0.2.0",
    "project_urls": {
        "Homepage": "https://github.com/drago-suzuki58/LocoTOML",
        "Issues": "https://github.com/drago-suzuki58/LocoTOML/issues",
        "Repository": "https://github.com/drago-suzuki58/LocoTOML"
    },
    "split_keywords": [
        "toml",
        " localization",
        " translation",
        " localisation",
        " multi-language"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "61becbab8f9b3366868c5491f1c83d1ec2f108010d04a9b04131e3897825fe88",
                "md5": "5c27b680ca45ae5333c90e3e72bc3c43",
                "sha256": "1eacc53f3a3b62971014471007c83696cd59ab3d2d03de9f2460574da7fa1c8c"
            },
            "downloads": -1,
            "filename": "locotoml-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5c27b680ca45ae5333c90e3e72bc3c43",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.11",
            "size": 3853,
            "upload_time": "2024-11-17T19:28:31",
            "upload_time_iso_8601": "2024-11-17T19:28:31.875863Z",
            "url": "https://files.pythonhosted.org/packages/61/be/cbab8f9b3366868c5491f1c83d1ec2f108010d04a9b04131e3897825fe88/locotoml-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c29237404798016e48b676102d7317d2ae7b97c2c8f38657e99c5df54630c959",
                "md5": "50292d2f237539213c51ce68b4945fc9",
                "sha256": "4420d1e8b9359a034252e777fac6ef17d3cab67e76b173cc2cbbb4fee474b8c6"
            },
            "downloads": -1,
            "filename": "locotoml-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "50292d2f237539213c51ce68b4945fc9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.11",
            "size": 3444,
            "upload_time": "2024-11-17T19:28:33",
            "upload_time_iso_8601": "2024-11-17T19:28:33.047167Z",
            "url": "https://files.pythonhosted.org/packages/c2/92/37404798016e48b676102d7317d2ae7b97c2c8f38657e99c5df54630c959/locotoml-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-17 19:28:33",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "drago-suzuki58",
    "github_project": "LocoTOML",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "locotoml"
}
        
Elapsed time: 2.62587s