Skip to main content

Forge i18n — traduction par catalogues JSON, locale par défaut et fallback, helper trans() pour Jinja.

Project description

forge-mvc-i18n

Opt-in Forge pour l'internationalisation. Extrait du core (ADR-027) : le core ne contient que les primitives générales ; la traduction est une brique spécialisée, optionnelle.

Contenu

  • trans(key, locale=None, translations_dir="translations") : traduit une clé via le catalogue de la locale, avec repli sur la locale de fallback puis sur la clé elle-même.
  • load_catalog(locale, translations_dir) : charge et valide un catalogue translations/<locale>.json (objet JSON de chaînes), mis en cache.
  • clear_translation_cache() : vide le cache des catalogues.
  • get_default_locale / set_default_locale, get_fallback_locale / set_fallback_locale : pilotent la configuration du noyau (i18n_default_locale, i18n_fallback_locale).
  • Exceptions : I18nError, TranslationCatalogError.

Quand le paquet est installé, le renderer Jinja du noyau expose automatiquement trans() comme fonction globale des templates.

Installation

pip install --pre forge-mvc-i18n

Configuration

Les locales par défaut et de fallback sont des clés du noyau, configurables au démarrage :

import core.forge as forge

forge.configure(i18n_default_locale="fr", i18n_fallback_locale="en")

Exemple

from forge_mvc_i18n import trans

# translations/fr.json -> {"common.save": "Enregistrer"}
trans("common.save")            # "Enregistrer"
trans("inconnu")                # "inconnu" (repli sur la clé)

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

forge_mvc_i18n-1.0.0rc1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file forge_mvc_i18n-1.0.0rc1-py3-none-any.whl.

File metadata

File hashes

Hashes for forge_mvc_i18n-1.0.0rc1-py3-none-any.whl
Algorithm Hash digest
SHA256 cae69cb69e762e4a91904310d62718abb824f52860538d6215faf8b4ae19fadb
MD5 5e0512b2f14b503b3ee44a7ed6287e3d
BLAKE2b-256 08498daf51ab29e818b6db4bd633d67f411938fcd2f89d44b8d6fe83c75338ac

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