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

Uploaded Source

Built Distribution

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

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: i18npy-1.0.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.8.10 Linux/5.4.0-7642-generic

File hashes

Hashes for i18npy-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1eba2f37659d313358c667c227ff6f65f817070f84e5aec9d104919bffc57a44
MD5 e6a6a3a29eddb1132ff250f3221f084c
BLAKE2b-256 5bb7b43af49c0db58f80932b880598df32035f158048f3b720bc1f17509a3c65

See more details on using hashes here.

File details

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

File metadata

  • Download URL: i18npy-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.6 CPython/3.8.10 Linux/5.4.0-7642-generic

File hashes

Hashes for i18npy-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ca84f4396a4f747a104e98ce315e2f1d1d1ab554563405c584b220ba7ae6117
MD5 b8c96eae018d8e30cdec2c7c4792ed7e
BLAKE2b-256 319891ff6a331f97e459bd6a7e0c028d15002ac5bd44e376b3a78a3516fe956a

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