Flask-TransAlchemy
Simple translation support for Flask-SQLAlchemy based database tables.
Usage
Initialize the TransAlchemy extension with the Flask and Flask-SQLAlchemy instances.
from flask import Flask
from flask_transalchemy import TransAlchemy
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
db = SQLAlchemy(app)
translations = TransAlchemy(app, db)
if __name__ == '__main__':
app.run()
To add translatable abilities to your models, use the
TranslatableMixin class. The translatable columns should be defined in the
translatable_columns class attribute.
from flask_transalchemy import TranslatableMixin
class SomeModel(db.Model, TranslatableMixin):
translatable_columns = ['text_field']
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
text_field = db.Column(db.String(40))
not_translatable_text_field = db.Column(db.String(10))
Translations not bind to any model can also be utilized with the set_label()
and get_label() methods.
with app.app_context():
set_label('hello', 'Welcome {name}!', language='en')
set_label('hello', 'Willkommen {name}!', language='de')
set_label('hello', 'Bienvenue {name}!', language='fr')
set_label('hello', 'Bienvenido {name}!', language='es')
@app.route('/<name>')
def hello(name: str):
return get_label('hello').format(name=name)
If the label_route parameter was specified at initialization, the label
translations are accessible over the provided route. Visiting
/<label_route>/hello?name=John would return Welcome John! in the previous
case. This might be useful for frontend or client application development.
Metadata
Release files for Flask-TransAlchemy 0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| Flask-TransAlchemy-0.1.tar.gz | 3.4 kB | Without provenance | Details |
Release files / Flask-TransAlchemy-0.1.tar.gz
| Download URL | Flask-TransAlchemy-0.1.tar.gz |
|---|---|
| Size | 3.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f807055ac7245e8f341cd5f76a6d584baf90f1143308ac0d0840115349423010
|
|
BLAKE2b-256 checksum How to use checksums |
98aedb25a4247c00fa0ecf307a4e7edc1528bd63c52e15759c2e1f2ce83c37ba
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.7.0
|
Security for Flask-TransAlchemy 0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.