Hermes-LangLib
Fast, optimized and high-performance, high-load oriented library for i18n and l10n
Explore the docs »
Getting Started
·
Basic Usage
·
Key Features
·
Specification
·
License
Hermes LangLib - a fast and productive python library for translating, localizing and internationalizing your applications. The library is aimed at high speed and stability; it can be used in highly loaded projects.
Check Other My Projects
- SQLSymphony - simple and fast ORM in sqlite (and you can add other DBMS)
- Burn-Build - simple and fast build system written in python for C/C++ and other projects. With multiprocessing, project creation and caches!
- OptiArch - shell script for fast optimization of Arch Linux
- libnumerixpp - a Powerful C++ Library for High-Performance Numerical Computing
- pycolor-palette - display beautiful log messages, logging, debugging.
- shegang - powerful command interpreter (shell) for linux written in C
- pyEchoNext - EchoNext is a lightweight, fast and scalable web framework for Python.
📚 Key Features
- Intuitive API: Pythonic, object-oriented interface for interacting with routes and views.
- Comprehensive Documentation: Detailed usage examples and API reference to help you get started.
- Modular Design: Clean, maintainable codebase that follows best software engineering practices.
- Extensive Test Coverage: Robust test suite to ensure the library's reliability and stability.
- Various types of localization storage: you can store localization in JSON, TOML, YAML and INI formats or in RAM.
- Automatic translation: you can enable automatic translation of your localization if the required word is not found.
🚀 Getting Started
HermesLangLib is available on PyPI. Simply install the package into your project environment with PIP:
pip install hermes_langlib
Once installed, you can start using the library in your Python projects.
💻 Usage Examples
Main Example
Directory tree:
├── example.toml
└── locales
└── default.json
Example config-file example.toml:
locale_directory="locales"
default_locale_file="default.json"
default_language="RU_RU"
translator="google"
Example locale file locales/default.json:
{
"locales": {
"RU": ["RU_RU"],
"EN": ["EN_EN", "EN_US"]
},
"RU": {
"RU_RU": {
"title": "Библиотека для интернационализации",
"description": "Библиотека, которая позволит переводить ваши приложения",
"mails_message": {
"plural": "count",
"^0$": "У вас нет ни одного письма",
"11": "У вас есть {count} писем",
"1$|1$": "У вас есть {count} письмо",
"^(2|3|4)$|(2|3|4)$": "У вас есть {count} письма",
"other": "У вас есть {count} писем"
}
}
},
"EN": {
"EN_EN": {
"title": "Library for internationalization",
"description": "A library that will allow you to translate your applications",
"mails_message": {
"plural": "count",
"^0$": "You do not have any mail.",
"^1$": "You have a new mail.",
"other": "You have {count} new mails."
}
},
"EN_US": {
"title": "Library for internationalization",
"description": "A library that will allow you to translate your applications",
"mails_message": {
"plural": "count",
"^0$": "You do not have any mail.",
"^1$": "You have a new mail.",
"other": "You have {count} new mails."
}
}
}
}
Example usage:
from hermes_langlib.locales import LocaleManager
from hermes_langlib.storage import load_config
config = load_config('example.toml')
locale_manager = LocaleManager(config)
print(locale_manager.get('title - {version}', 'default', 'RU_RU', version="0.1.0"))
print(locale_manager.get('title - {version}', 'default', 'RU', version="0.1.0"))
print(locale_manager.get('mails_message.', 'default', 'RU_RU', count=0))
print(locale_manager.get('mails_message', 'default', 'RU_RU', count=1))
print(locale_manager.get('mails_message', 'default', 'RU_RU', count=11))
print(locale_manager.get('mails_message', 'default', 'RU_RU', count=2))
print(locale_manager.get('mails_message', 'default', 'RU_RU', count=22))
print(locale_manager.get('mails_message', 'default', 'RU_RU', count=46))
print(locale_manager.get('mails_message', 'default', 'RU_RU', count=100000001))
print(locale_manager.translate("You have only three mails", "en", 'ru'))
print(locale_manager.translate("У вас всего три письма", "ru", 'en'))
🔧 Specifications
The core of your project is the configuration. It can be loaded via a file (TOML, JSON, YAML, INI are supported) or created directly in code.
Loaded via a file:
from hermes_langlib.storage import load_config
config = load_config('example.toml')
Or created in code:
from hermes_langlib.storage.base import Config
from hermes_langlib.translators.providers import TranslatorProviders
config = Config(
config_file = None,
locale_directory = "locales",
default_locale_file = "default.json",
default_language = "RU_RU",
translator = TranslatorProviders.google
)
TranslatorProviders is an enum class with translator providers. To do this, used deep-translator:
class TranslatorProvider:
def __init__(self, translator):
self.translator = translator
def __call__(self, source: str, target: str, phrase: str):
translator = self.translator(source=source, target=target)
return translator.translate(phrase)
class TranslatorProviders(Enum):
google = TranslatorProvider(GoogleTranslator)
chatgpt = TranslatorProvider(ChatGptTranslator)
microsoft = TranslatorProvider(MicrosoftTranslator)
pons = TranslatorProvider(PonsTranslator)
linguee = TranslatorProvider(LingueeTranslator)
mymemory = TranslatorProvider(MyMemoryTranslator)
yandex = TranslatorProvider(YandexTranslator)
papago = TranslatorProvider(PapagoTranslator)
deepl = TranslatorProvider(DeeplTranslator)
qcri = TranslatorProvider(QcriTranslator)
💬 Support
If you encounter any issues or have questions about hermes_langlib, please:
- Check the documentation for answers
- Open an issue on GitHub
- Reach out to the project maintainers via the mailing list
🤝 Contributing
We welcome contributions from the community! If you'd like to help improve hermes_langlib, please check out the contributing guidelines to get started.
License
Distributed under the GNU LGPL 2.1 License. See LICENSE for more information.
HermesLangLib is a lightweight, fast and scalable web framework for Python Copyright (C) 2024 Alexeev Bronislav (C) 2024
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
Metadata
Release files for hermes_langlib 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hermes_langlib-0.1.4.tar.gz | 22.6 kB | Without provenance | Details for hermes_langlib-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hermes_langlib-0.1.4-py3-none-any.whl | Python 3 | none | any | Details for hermes_langlib-0.1.4-py3-none-any.whl |
Total release size: 47.6 kB
Release files / hermes_langlib-0.1.4.tar.gz
| Download URL | hermes_langlib-0.1.4.tar.gz |
|---|---|
| Size | 22.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e427c0afa5362932987d77e904f2cf0f9a9d706742888addcfdacbe47f2b29bb
|
|
BLAKE2b-256 checksum How to use checksums |
33791fdc8d8c962f85318a07f881d75d5939d712bc0dbfa748fa0b0350e84ec7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.2 CPython/3.12.9 Linux/6.12.23
|
Release files / hermes_langlib-0.1.4-py3-none-any.whl
| Download URL | hermes_langlib-0.1.4-py3-none-any.whl |
|---|---|
| Size | 25.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d8b3ffeabd1faddb61a6db25737725b7ae3220dba23c5b6b0cf33f68059dff68
|
|
BLAKE2b-256 checksum How to use checksums |
b3c4934303e2e36fa5e52c452b3c0d7f16d8556ce2857091118b73be229220d3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.2 CPython/3.12.9 Linux/6.12.23
|
Security for hermes_langlib 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.