Skip to main content

Fast, optimized and high-performance, high-load oriented library for i18n and l10n

Project description

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.

(back to top)

📚 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.

(back to top)

🚀 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.

(back to top)

💻 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'))

(back to top)

🔧 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)

(back to top)

💬 Support

If you encounter any issues or have questions about hermes_langlib, please:

(back to top)

🤝 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.

(back to top)

License

Distributed under the GNU LGPL 2.1 License. See LICENSE for more information.

(back to top)


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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hermes_langlib-0.1.4.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hermes_langlib-0.1.4-py3-none-any.whl (25.0 kB view details)

Uploaded Python 3

File details

Details for the file hermes_langlib-0.1.4.tar.gz.

File metadata

  • Download URL: hermes_langlib-0.1.4.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.9 Linux/6.12.23

File hashes

Hashes for hermes_langlib-0.1.4.tar.gz
Algorithm Hash digest
SHA256 e427c0afa5362932987d77e904f2cf0f9a9d706742888addcfdacbe47f2b29bb
MD5 77291c13608bb291ce021b477d9adabc
BLAKE2b-256 33791fdc8d8c962f85318a07f881d75d5939d712bc0dbfa748fa0b0350e84ec7

See more details on using hashes here.

File details

Details for the file hermes_langlib-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: hermes_langlib-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 25.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.9 Linux/6.12.23

File hashes

Hashes for hermes_langlib-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d8b3ffeabd1faddb61a6db25737725b7ae3220dba23c5b6b0cf33f68059dff68
MD5 62b764ddd7e328bc8577daeb42229f28
BLAKE2b-256 b3c4934303e2e36fa5e52c452b3c0d7f16d8556ce2857091118b73be229220d3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page