Giter Site home page Giter Site logo

cnfilms / izi18n Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 35 KB

Simple python library for language Internationalisation

Home Page: https://cnfilms.github.io/izi18n/

License: BSD 3-Clause "New" or "Revised" License

Python 98.87% Shell 1.13%
json language python internationalisation

izi18n's Introduction

izi18n Downloads

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

izi18n's People

Contributors

koffiisen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.