Skip to main content

Internationalization library. Python implementation of roddeh/i18njs

Project description

i18npy

PyPI PyPI - Python Version Codecov GitHub

This is Python implementation of roddeh/i18njs (http://i18njs.com/). It's fully compatible with it's JSON dictionaries syntax.

Usage

Installation

pip install i18npy

Samples

With external dictionary and global i18n instance

pl.json

{
  "values": {
    "Hello World": "Witaj świecie",
    "I have %n cookies": [
      [null, null, "Nie ma rączek, nie ma ciasteczek"],
      [0, 0, "Nie mam ciasteczek"],
      [1, 1, "Mam jedno ciasteczko"],
      [2, 4, "Mam %n ciasteczka"],
      [5, null, "Mam %n ciasteczek"]
    ]
  }
}

code

from i18npy import i18n, i18n_load

i18n_load("./pl.json")

i18n("Hello World")
# Witaj świecie

KEY = "I have %n cookies"
i18n(KEY, None)
# Nie ma rączek, nie ma ciasteczek

i18n(KEY, 0)
# Nie mam ciasteczek

i18n(KEY, 1)
# Mam jedno ciasteczko

i18n(KEY, 3)
# Mam 3 ciasteczka

i18n(KEY, 5)
# Mam 5 ciasteczek

Create translator instances

import i18npy

lang_pl = i18npy.create({
  "values": {
    "Hello World": "Witaj świecie",
    "I have %n cookies": [
      [None, None, "Nie ma rączek, nie ma ciasteczek"],
      [0, 0, "Nie mam ciasteczek"],
      [1, 1, "Mam jedno ciasteczko"],
      [2, 4, "Mam %n ciasteczka"],
      [5, None, "Mam %n ciasteczek"]
    ]
  }
})

lang_pl.translate("Hello World")
# Witaj świecie

lang_pl.translate("I have %n cookies", 3)
# Mam 3 ciasteczka

Word of appreciation

The original i18njs library ha been written by roddeh. The library code is based on his code, which is also licensed by MIT.

License

This project is licensed under MIT License - see the LICENSE file for details.

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

i18npy-1.0.0.tar.gz (5.6 kB view hashes)

Uploaded Source

Built Distribution

i18npy-1.0.0-py3-none-any.whl (5.9 kB view hashes)

Uploaded Python 3

Supported by

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