The internationalization (i18n) library for Python.
Project description
PyUniversalize
The internationalization (i18n) library for Python.
Installing
PyUniversalize can be installed with pip:
pip install py_universalize
Alternatively, you can grab the latest source code from GitHub:
$ git clone https://github.com/shriyashwarghade/py_universalize
$ cd py_universalize
$ pip install .
Importing Package
import universalize
Setting up PyUniversalize
Setup can be done 2 ways
-
Passing configuration as an parameter.
universalize.setup({ "primary": { "code": "en", "file": "en.json", "display_name": "English" }, "languages": [ { "code": "fr", "file": "fr.json", "display_name": "French" } ] } )
-
Passing configuration as an Json file path.
universalize.setup('setup.json')
// setup.json { "primary": { "code": "en", "file": "en.json", "display_name": "English" }, "languages": [ { "code": "fr", "file": "fr.json", "display_name": "French" } ] }
Each language block has 3 keys.
code: Language code,
file: Language translation json file location
display_name: Language display name
Translate
Once you've completed the setup, you can use locale function with the value by using the dot notation, ex: HOME.HELLO.
The translate parser understands nested JSON objects. This means that you can have a translation that looks like this:
// fr.json
{
"HOME": {
"HELLO": "Hola"
}
}
universalize.locale('HOME.HELLO','fr')
locale function accepts two parameters
text: Dot notated string
language_code: Translate text to the given language code. This is an optional parameter. If not given text will be translated to primary language.
Change Primary Language
universalize.set_primary_language('en')
Get Languages List
Returns an array of currently available languages
universalize.get_languages()
License
MIT
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file py_universalize-1.0.0.tar.gz.
File metadata
- Download URL: py_universalize-1.0.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
96821cadee12c2da0ff78db2e428a63d85daa9fe52efc08b9853b257b36e66eb
|
|
| MD5 |
42050682776d982d70286ab0ca9be430
|
|
| BLAKE2b-256 |
2c45a2485a250720181f42f1526fe5fe36d0242dc1df6a948a75c9863867ee22
|
File details
Details for the file py_universalize-1.0.0-py3-none-any.whl.
File metadata
- Download URL: py_universalize-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
690d70820bd767abdc1f8bbe7f2e5d52bc5bdadfeaed4ae94a8a2473d6e02411
|
|
| MD5 |
5c1ca4866479f31b4e8be6777090f927
|
|
| BLAKE2b-256 |
3bb2cb72b7d548cedbd6f5d73dca614f96224d5d877e7964cb482726e31d44a6
|