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.0.tar.gz (2.8 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: Flask-Banana-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 5bd9c07e3a35a19b4ed3274981b441b6e0dc7b7d305b592a52703c205916f6fc
MD5 9558a242ceb4dce701bb06fb39ee7a2f
BLAKE2b-256 a1986650bdfe5a935f825e79bfcdd109a9e008d597e8d548eee79e347e15a192

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: Flask_Banana-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7e31e3e920c8cf526a5bed1a15c897da41db9ecf5048a41a44ee4363a0bc43ee
MD5 50a6f1dab51e96549334bb89601b5a31
BLAKE2b-256 8488ea9de5d81d7645354e5d6a3a8354220f313205a21d5eb21e51dbef4dcf63

See more details on using hashes here.

Provenance

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