Skip to main content

A lightweight, extensible i18n utility for Python projects

Project description

PyLyglot

PyLyglot est une bibliothèque Python de traduction simple, extensible et thread-safe, utilisant le pattern singleton pour centraliser la gestion des langues. Elle permet la traduction de clés hiérarchiques avec gestion du fallback et formatage dynamique.

📦 Fonctionnalités

  • Chargement automatique de fichiers JSON de traduction.
  • Détection automatique de la langue du système.
  • Fallback intelligent vers des langues plus générales (ex: fr-CAfren).
  • Clés hiérarchiques via la notation dot.key.
  • Formatage avec str.format().
  • Gestion personnalisée des clés manquantes.

🛠 Installation

pip install pylyglot

Ou ajoute-le directement à ton pyproject.toml si tu utilises Poetry.

📁 Structure des fichiers

Les fichiers de langue doivent être placés dans un répertoire lang/ à la racine de ton projet. Exemple :

lang/
├── en.json
├── fr.json

Exemple de fichier en.json :

{
    "_meta": {
      "version": "1.0",
      "author": "Your Name"
    },
    "menu": {
        "start": "Start",
        "quit": "Quit"
    },
    "welcome": "Welcome, {username}!"
}

🚀 Utilisation

  • 1 Créer le dossier /lang à la racine de votre proket
  • 2 ajouter les fichiers de langues
from pylyglot import PyLyglot

def missing_key_handler(key):
    return f"<<{key}>>"

pl = PyLyglot(missing_key_handler=missing_key_handler)

print(pl("menu.start"))              # Start
print(pl("menu.quit"))               # Quit
print(pl("welcome", username="Alice"))  # Welcome, Alice!

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

pylyglot-1.0.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

pylyglot-1.0.0-py3-none-any.whl (6.3 kB view details)

Uploaded Python 3

File details

Details for the file pylyglot-1.0.0.tar.gz.

File metadata

  • Download URL: pylyglot-1.0.0.tar.gz
  • Upload date:
  • Size: 5.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for pylyglot-1.0.0.tar.gz
Algorithm Hash digest
SHA256 18e174c670ccb1e9846f526f0d311380f5b6081cbb3b5c173c56b6c2d3d5b265
MD5 dba88c664d37e0d9407efa2e7367d4bf
BLAKE2b-256 1db6abe403272a82844d23acc084a20bf0a8db1d6f84e69109af82dc3418641f

See more details on using hashes here.

File details

Details for the file pylyglot-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pylyglot-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for pylyglot-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 312cf921e318b6dd11d3c2cdca7040fbc30c18f8bfef7ee5714020d4d37ecde7
MD5 fd778f23557d752bc35ec4f7ef05a2d6
BLAKE2b-256 2db0afd7050e431e44eac806f11bb402e75ba8175932f876bc927ce4e72ff9aa

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