Integrates the banana i18n library into Flask applications
Project description
Localize your Flask application using the banana file format, popularized by MediaWiki.
Usage
In your app.py:
from flask import Flask from flask_banana import Banana from pathlib import Path app = Flask(__name__) banana = Banana(app, Path(__file__).resolve().parent / 'i18n')
You can also use the init_app pattern as well.
In your template the _(...) function is aliased to banana.translate():
<body> <p>{{ _('some-message-key') }}</p> </body>
To change the language, set the banana.language property. You might also want to try the Flask-ULS library for better client-side support for changing the interface language.
Flask-ULS integration
Flask-Banana can automatically configure and integrate with Flask-ULS, just pass the ULS instance to Banana during setup:
app = Flask(__name__) uls = ULS(app) banana = Banana(app, Path(__file__).resolve().parent / 'i18n', uls)
Banana will configure ULS to enable all of the languages that have translations and then default to using the language configured through ULS.
Configuration
BANANA_DEFAULT_LANGUAGE (default: 'en'): the language to default to if one hasn’t been manually set through Banana nor ULS.
License
Flask-Banana 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-Banana-0.1.1.tar.gz
.
File metadata
- Download URL: Flask-Banana-0.1.1.tar.gz
- Upload date:
- Size: 2.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 333d043d1bc4c8ca07b0d8a40a9e64da8c30fff54720d24d163e81b067e499bc |
|
MD5 | 35e3b86def771102da3cbf6f530b21dc |
|
BLAKE2b-256 | dad2750d051d6a1ec920355b218457966475609a26a4dd100bfe9e94488557b5 |
File details
Details for the file Flask_Banana-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: Flask_Banana-0.1.1-py3-none-any.whl
- Upload date:
- Size: 3.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.0.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3343ad5ab4dbcd640da8ca517f5e0b6a605845eba32cfa91c3c36b0967599ed3 |
|
MD5 | 2319daf5d72656bfd8c4f3d5d5d9dfec |
|
BLAKE2b-256 | b97c725d15c1a8c13530da9eec27f130eeab9d8f35318364a057470c34ff9f62 |