Skip to main content

Module for multilingual solutions

Project description

PyLocales

Locales - module for multilingual projects

Getting Started

Prerequisites

Locales uses only standard library json. You need to write the translations in json format

{
  "languages": {
      "ru": "Р СѓСЃСЃРєРёР№", "eng": "English", "sp": "EspaГ±ol"
  },

  "messages": {
      "welcome": {
          "ru": "Добро пожаловать!",
          "eng": "Welcome!"
      },
      "goodbye": {
          "ru": "РџРѕРєР°",
          "eng": "Goodbye",
          "sp": "AdiГіs"
      }
  }
}

Keys languages and messages required.

To generate the same file use:

import Locales

Locales().example()

Installing

You can install Locales using pip

$ pip install locales

or download Locales.py and drop to folder with your project

Using

import Locales

loc = Locales("filename.json")
loc.set_default_lang("eng")  # Set the language by default

print(loc.get("welcome"))
# Welcome!

print(loc.get("welcome", "ru"))
# Добро пожаловать!

print(loc.get_all("goodbye")
# dict of key "goodbye"  ->  {'ru': 'РџРѕРєР°', 'eng': 'Goodbye', 'sp': 'AdiГіs'}

print(loc.get_by_name("English"))
# returns the abbreviation(key) of the language  ->  eng

Authors

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

Locales-0.0.1.tar.gz (1.9 kB view details)

Uploaded Source

Built Distribution

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

Locales-0.0.1-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

Details for the file Locales-0.0.1.tar.gz.

File metadata

  • Download URL: Locales-0.0.1.tar.gz
  • Upload date:
  • Size: 1.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.20.0 setuptools/40.7.2 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.0

File hashes

Hashes for Locales-0.0.1.tar.gz
Algorithm Hash digest
SHA256 4f4bbda55c5d57e886376d7a940124c85ae374bea302be465d0b95b14e279711
MD5 3ea6e0d2175cc3032f1dcfd0cc35fa98
BLAKE2b-256 e1caacc037db13013848cf7a6dd4853d457233a3c040f25fbf846c33b2a6cd80

See more details on using hashes here.

File details

Details for the file Locales-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: Locales-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 2.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.20.0 setuptools/40.7.2 requests-toolbelt/0.9.1 tqdm/4.30.0 CPython/3.7.0

File hashes

Hashes for Locales-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 05e342e092d68244f2ec75fcf56b2c265de15309bf7858ea1d5bf6f0421ede0f
MD5 bafe42cb8c13a399ccf16945a8837ed6
BLAKE2b-256 d81145f591cfb26e99c47aebe85f1faccc16f02a78965cef8a7842cfa7fdd53e

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