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

Release files for Locales 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Locales 0.0.2
File Size Uploaded
Locales-0.0.2.tar.gz 2.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Locales 0.0.2
File Interpreter ABI Platform
Locales-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 6.3 kB

Release files / Locales-0.0.2.tar.gz

Download URL Locales-0.0.2.tar.gz
Size 2.6 kB
Tags Source
SHA-256 checksum
How to use checksums
c286ae770cbc5bacce074a2981c7cf6092a89cf10fc3aa7df9214f56fcdf7742
BLAKE2b-256 checksum
How to use checksums
a94989c3242769d5fdcf96d437601fa182fcb65209153567911c06ee5a5132e5
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / Locales-0.0.2-py3-none-any.whl

Download URL Locales-0.0.2-py3-none-any.whl
Size 3.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e4a438d394565b59965822d19c6d3207948019f255f7f87845019ea5ffbb03a2
BLAKE2b-256 checksum
How to use checksums
0aa1f0d0341907c1bd5991bb110e14306888ec4d94bd2e0b06b1489990e33c9e
Upload date
Uploaded using Trusted Publishing?
What is 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

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page