Skip to main content

Locales

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

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.2.tar.gz (2.6 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.2-py3-none-any.whl (3.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: Locales-0.0.2.tar.gz
  • Upload date:
  • Size: 2.6 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.2.tar.gz
Algorithm Hash digest
SHA256 c286ae770cbc5bacce074a2981c7cf6092a89cf10fc3aa7df9214f56fcdf7742
MD5 026afad7e9a9b64115c4d29492257d87
BLAKE2b-256 a94989c3242769d5fdcf96d437601fa182fcb65209153567911c06ee5a5132e5

See more details on using hashes here.

File details

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

File metadata

  • Download URL: Locales-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e4a438d394565b59965822d19c6d3207948019f255f7f87845019ea5ffbb03a2
MD5 a0e5e776568a08d1cbd4217af4a783af
BLAKE2b-256 0aa1f0d0341907c1bd5991bb110e14306888ec4d94bd2e0b06b1489990e33c9e

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 files

0.0.1

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page