Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

py-universalize

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

py-universalize

The internationalization (i18n) library for Python.

  • 1.0.0
  • Source
  • PyPI
  • Socket score

Maintainers
1

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

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc