Simple python library for language Internationalisation
Project description
izi18n
Simple python library for language Internationalisation
Install
pip install izi18n
- Support
JSON
.PO FILES
Method
_
add_translation
add_translation_by_lang
get_i18n
get_locale
gettext
init_translation
load_po_file
set_locale
set_translations_path
translate
translate_by_lang
Usage
Initialisation
from izi18n import init_translation
# Set default language
# Translations_path is where locate all language translations file (JSON file only)
init_translation(language="en", translations_path="../exemples/locales")
Translate
from izi18n import translate, gettext, _
# page.facture.title is the pattern to the key you want to translate
print(translate('page.facture.title'))
# Translate template with values
# default_text is set if the pattern is not found
# **dict() is the kwargs
translate("page.facture.count", default_text="Total facture", **dict(item=5, total=20))
# OR
translate("page.facture.count", default_text="Total facture", item=5, total=20)
# Possibility to use gettext or _() instead from translate
print(gettext('page.facture.title'))
print(_('page.facture.title'))
Translate by Key or Word
from izi18n import translate
# Translate with word key
print(translate("space key"))
translate("cinego")
print(translate("space key 2.Good for me"))
Get I18n class object
from izi18n import get_i18n, get_locale
# Get ui18n Object class
# get_i18n return I18n class (Singleton)
print(get_i18n().language, " OR ", get_locale(), "\n")
print(get_i18n().translate("cinego"))
Load translation from .PO file
from izi18n import load_po_file, get_locale, gettext, translate, _
# Load po files and specify the local of the files
# Stream True it means you avoid to merged with json locales folder files
load_po_file(['app.po', 'messages.po'], "de", stream=True)
# load_po_file("cinego.po", "de")
# load_po_file("messages.po", "de")
print(get_locale())
print(translate("Dimanche"))
print(gettext("Lundi"))
print(_("Visit ${url}", url="https://github.com/cnfilms/izi18n"))
Add or edit translation
from izi18n import init_translation, add_translation, add_translation_by_lang
init_translation(language="fr", translations_path="../exemples/locales")
# Add to current local
add_translation(pattern="page.home.title", value="Bonjour")
# Use if initial language is not defined
add_translation_by_lang(lang="en", pattern="page.home.title", value="Hi!")
add_translation(pattern="page.home.docs", value="Documents", lang="en")
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
izi18n-1.0.2.tar.gz
(18.5 kB
view details)
Built Distribution
izi18n-1.0.2-py3-none-any.whl
(12.4 kB
view details)
File details
Details for the file izi18n-1.0.2.tar.gz
.
File metadata
- Download URL: izi18n-1.0.2.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33d563ff28d73c09fb4dcf1adea01eb04200cf8a86405e08d0c8d63a1a746853 |
|
MD5 | 275aafa352521b8bc06132a6299303d2 |
|
BLAKE2b-256 | 9b147acaab67fff9b75cacddfb0946d9b89308985619e88ff368944294af1f24 |
File details
Details for the file izi18n-1.0.2-py3-none-any.whl
.
File metadata
- Download URL: izi18n-1.0.2-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f925debb3142e3806f877a42fa5caa3fe283ac3b704166fb58f619bcead463de |
|
MD5 | e6d0f6fe3fd96dc5f851ea41890025fc |
|
BLAKE2b-256 | ce7f1df4168f62534a144624d334a7ade1c7df9b291b72179fce472735c13e57 |