Last updated:
0 purchases
pyuniversalize 1.0.0
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
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.