Easy to use integration of the Universal Language Selector in Flask applications
Project description
Integrate the UniversalLanguageSelector (ULS) into your Flask application to allow users to easily change their preferred language in which the application is rendered. It is recommended to use this in conjunction with localizing your application.
Usage
In your app.py:
from flask import Flask from flask_uls import ULS app = Flask(__name__) uls = ULS(app)
You can also use the init_app pattern as well.
In your template:
<head> {% include 'uls/head.html' %} </head> <body> <span class="uls-trigger">Select language</span> {% include 'uls/footer.html' %} </body>
This will load the necessary CSS in the header create a button with the text “Select language” to open up the dialog menu and then load the JavaScript to configure and trigger ULS.
To integrate ULS with other localization systems, you can access the uls.language property to get the currently configured language. It will look at the ?uselang query parameter, the language cookie (set by ULS client-side), and the configured default language.
Configuration
ULS_DEFAULT_LANGUAGE (default: 'en'): the language to default to if the user hasn’t selected one.
ULS_ENABLED_LANGUAGES (default: ['en']): languages that ULS should display as options to the user.
Example
See the example application which allows users to change their language between English and German and then outputs the currently chosen language.
License
Flask-ULS is available under the terms of the GPL, version 3 or any later version.
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
File details
Details for the file Flask-ULS-0.1.1.tar.gz
.
File metadata
- Download URL: Flask-ULS-0.1.1.tar.gz
- Upload date:
- Size: 150.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.2 pkginfo/1.4.2 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70f5d370653533eeabc4cfdeced9ba12e19be4a54ffe212b9e4bdb5525fc80ed |
|
MD5 | 2c5d5f5f344392f65ce0efcdac43f13d |
|
BLAKE2b-256 | db8a4a28ee54ced55126a83ce078dd3851c5a31655b7e6ee9732267e64110d15 |
File details
Details for the file Flask_ULS-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: Flask_ULS-0.1.1-py3-none-any.whl
- Upload date:
- Size: 169.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.2 pkginfo/1.4.2 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3cf0a96c73e0bfea2f891c5f037be97ba8ef2306d62af75ca4b5b06d7e8167a0 |
|
MD5 | 0ec7f9a39a8ad23347aa204f256f587f |
|
BLAKE2b-256 | fa8e73200f547472db0cebde0064d2646318a0df548d1eb30e12b99adbda07a4 |