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
- vffuunnyy - Initial work - @vffuunnyy
Project details
Release history Release notifications | RSS feed
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 hashes)