Skip to main content

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


Download files

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

Source Distribution

Flask-Banana-0.1.2.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

Flask_Banana-0.1.2-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file Flask-Banana-0.1.2.tar.gz.

File metadata

  • Download URL: Flask-Banana-0.1.2.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

Hashes for Flask-Banana-0.1.2.tar.gz
Algorithm Hash digest
SHA256 da586ad99b1ae476f387d2f4def8e672fd9a1d9c07fbf18ef2b25538e1065c70
MD5 d9cca07ab2f6523bb7db75bc93a13b3b
BLAKE2b-256 b80a5bacec10657ffc0a20073d2ff311d7edf0afd246065ea668b1effe7ed01c

See more details on using hashes here.

File details

Details for the file Flask_Banana-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: Flask_Banana-0.1.2-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

Hashes for Flask_Banana-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 50011f85d777ef1a3b58030c27bb2beb9ea8ec518084fc63f0101febaaa81521
MD5 195e2d7af8552c6af83c365f289bdd8f
BLAKE2b-256 651df4e75945d3b72c4997ae8278873069d765a82c75693e10c12e078b3fc97f

See more details on using hashes here.

Supported by

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