Simple and Elegant Python3 Internationalization (i18n) Tool
Project description
🌍 Easy AI18n
Easy AI18n is a modern internationalization tool library for Python3. It supports AI translation, multi-user scenarios, and full string formatting syntax, making globalization of your project more elegant and natural.
✨ Key Features:
- 🚀 Easy to Use: Implement i18n with just a few lines of code
- ✨ Elegant Syntax: Use
_()to wrap translatable texts, seamlessly integrating into your code - 🤖 AI Translation: Supports translation using large language models (LLMs) for high-quality results
- 📝 Full Formatting Support: Fully supports all Python string formatting syntaxes
- 🌐 Multi-language Support: Choose languages using
[]selector for multilingual support
🔍 Comparison with Other i18n Tools
| Other i18n Tools | EasyAI18n |
|---|---|
Requires manual maintenance of keys and i18n files, high development cost |
Automatically extracts translation content, no manual file maintenance needed |
Supports only partial formatting syntax |
Fully supports all formatting syntax |
No real-time multi-language switching, unsuitable for multi-user scenarios |
Supports default language and multi-language switching, adaptable to multi-user environments |
⚡ Quick Start
📦 Installation
pip install easy-ai18n
🧪 Simple Example
/i18n.py
from easy_ai18n import EasyAI18n
i18n = EasyAI18n()
_ = i18n.i18n()
if __name__ == "__main__":
i18n.build(to_locales=["ja"])
/main.py
from i18n import _
def main():
print(_("Hello, world!")['ja'])
if __name__ == "__main__":
main()
🗂️ Project Structure
easy_ai18n
├── core # Core functionality module
│ ├── builder.py # Builder: extract, translate, generate YAML files
│ ├── i18n.py # Main translation logic
│ ├── loader.py # Loader: load translation files
│ └── parser.py # AST parser
├── prompts # Translation prompts
├── translator # Translator module
└── main.py # Project entry point
📘 Usage Tutorial
🛠️ Custom Translation Function Names
from easy_ai18n import EasyAI18n
i18n = EasyAI18n(
func_names=["_t", '_'] # Custom translation function names
)
_t = i18n.i18n()
_ = _t
print(_t("Hello, world!"))
print(_("Hello, world!"))
🤖 Use AI for Translation
from easy_ai18n import EasyAI18n
from easy_ai18n.translator import OpenAIBulkTranslator
translator = OpenAIBulkTranslator(api_key=..., base_url=..., model='gpt-4o-mini')
i18n = EasyAI18n()
i18n.build(to_locales=["ru", "ja", 'zh-Hant'], translator=translator)
_ = i18n.i18n()
print(_("Hello, world!")['zh-Hant'])
🔎 Language Selector
from easy_ai18n import EasyAI18n
i18n = EasyAI18n()
_ = i18n.i18n()
_t = _['ja']
d = {
1: _('apple'),
2: _('banana'),
3: _t('orange'),
}
print(d[1]['zh-hans']) # output: 苹果
print(d[2]) # output: banana
print(d[3]) # output: みかん
👥 Multi-user Language Scenarios (e.g. Telegram Bot)
Use custom language selector to dynamically select languages in multi-user environments:
/i18n.py:
from pyrogram.types import Message
from easy_ai18n import EasyAI18n, PostLocaleSelector
class MyPostLocaleSelector(PostLocaleSelector):
def __getitem__(self, msg: Message):
# ......
lang = msg.from_user.language_code
return super().__getitem__(lang)
i18n = EasyAI18n()
_ = i18n.i18n(post_locale_selector=MyPostLocaleSelector)
if __name__ == "__main__":
i18n.build(to_locales=['en', 'ru'])
/bot.py:
from pyrogram import Client
from pyrogram.types import Message
from i18n import _
bot = Client("my_bot")
@bot.on_message()
async def start(__, msg: Message):
await msg.reply(_[msg]("Hello, world!"))
if __name__ == "__main__":
bot.run()
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 easy_ai18n-1.1.1.tar.gz.
File metadata
- Download URL: easy_ai18n-1.1.1.tar.gz
- Upload date:
- Size: 20.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e69e2925828faed75ddfa84a360d78109dd2153ee70fc29a8d6d136d2cd91ad4
|
|
| MD5 |
5180a570ed913f88743a540a5628984b
|
|
| BLAKE2b-256 |
bed2cf1ed131d2483dda3e427660ad20d91da8c9f98957578e3b0fd522d00bbc
|
Provenance
The following attestation bundles were made for easy_ai18n-1.1.1.tar.gz:
Publisher:
python-publish.yml on z-mio/easy-ai18n
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
easy_ai18n-1.1.1.tar.gz -
Subject digest:
e69e2925828faed75ddfa84a360d78109dd2153ee70fc29a8d6d136d2cd91ad4 - Sigstore transparency entry: 669948612
- Sigstore integration time:
-
Permalink:
z-mio/easy-ai18n@55be031bb3a6249ae80217612155303b8cb7f623 -
Branch / Tag:
refs/tags/v1.1.1 - Owner: https://github.com/z-mio
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@55be031bb3a6249ae80217612155303b8cb7f623 -
Trigger Event:
release
-
Statement type:
File details
Details for the file easy_ai18n-1.1.1-py3-none-any.whl.
File metadata
- Download URL: easy_ai18n-1.1.1-py3-none-any.whl
- Upload date:
- Size: 19.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6217a743495da8b0ba0015eef6128407cfdd50819e7bbbbf78013644537bc64a
|
|
| MD5 |
bfadf3de46d91dabea7522254a3797a6
|
|
| BLAKE2b-256 |
bee439ecb929267a0bdb54c49bc378002f60b35c88c1959d346375889d22072f
|
Provenance
The following attestation bundles were made for easy_ai18n-1.1.1-py3-none-any.whl:
Publisher:
python-publish.yml on z-mio/easy-ai18n
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
easy_ai18n-1.1.1-py3-none-any.whl -
Subject digest:
6217a743495da8b0ba0015eef6128407cfdd50819e7bbbbf78013644537bc64a - Sigstore transparency entry: 669948641
- Sigstore integration time:
-
Permalink:
z-mio/easy-ai18n@55be031bb3a6249ae80217612155303b8cb7f623 -
Branch / Tag:
refs/tags/v1.1.1 - Owner: https://github.com/z-mio
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@55be031bb3a6249ae80217612155303b8cb7f623 -
Trigger Event:
release
-
Statement type: