Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_universalize-1.0.0.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_universalize-1.0.0-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

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

Hashes for py_universalize-1.0.0.tar.gz
Algorithm Hash digest
SHA256 96821cadee12c2da0ff78db2e428a63d85daa9fe52efc08b9853b257b36e66eb
MD5 42050682776d982d70286ab0ca9be430
BLAKE2b-256 2c45a2485a250720181f42f1526fe5fe36d0242dc1df6a948a75c9863867ee22

See more details on using hashes here.

File details

Details for the file py_universalize-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for py_universalize-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 690d70820bd767abdc1f8bbe7f2e5d52bc5bdadfeaed4ae94a8a2473d6e02411
MD5 5c1ca4866479f31b4e8be6777090f927
BLAKE2b-256 3bb2cb72b7d548cedbd6f5d73dca614f96224d5d877e7964cb482726e31d44a6

See more details on using hashes here.

Supported by

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