Back

gt-flask@0.1.0 / gt-fastapi@0.1.0

Ernest McCarter avatarErnest McCarter
gt-flaskgt-fastapigt-i18nv0.1.0pythonflaskfastapii18n

Overview

Initial release of gt-flask and gt-fastapi. These bring the same inline translation model used in gt-next and gt-react to Python web frameworks.

These packages are experimental and may be subject to breaking changes.

Usage

from flask import Flask
from gt_flask import initialize_gt, t

app = Flask(__name__)
initialize_gt(app)

@app.get("/")
def index():
    return {"message": t("Hello, world!")}

@app.get("/greet")
def greet():
    return {"message": t("Hello, {name}!", name=user.name)}

The source string is the source of truth. No key files, no .po files. t() resolves the current locale via framework middleware, looks up a translation by hash, interpolates variables, and falls back to the source string if no translation exists.

Python-specific metadata kwargs (_context, _id, _max_chars) handle disambiguation and constraints using underscore-prefixed keyword arguments.

CLI support

The GT CLI now extracts t() calls from Python source files. See the companion dev log for details on gt upload and gt translate for Python projects.