Back

gt-cli@2.8.0

Ernest McCarter avatarErnest McCarter
gt-cliv2.8.0pythonpython-extractorgt-flaskgt-fastapii18n

Overview

The gt CLI now supports Python projects. Running gt upload in a Flask or FastAPI project extracts t() calls from your Python source files and registers them with the GT platform.

What changed

A new @generaltranslation/python-extractor package parses Python source files and extracts translation calls. The CLI auto-detects Python projects by checking for gt-flask or gt-fastapi in your pyproject.toml, requirements.txt, or setup.py.

The extractor handles:

  • t("string literal") calls with keyword variable interpolation
  • declare_var() for marking dynamic f-string expressions as variables
  • declare_static() for embedding static expressions that should be evaluated at extraction time
  • Python-specific metadata kwargs (_context, _id, _max_chars) -- underscore-prefixed keyword arguments rather than the options object used in the JavaScript libraries

Example

from gt_flask import t

@app.get("/error")
def error():
    return {"error": t("Something went wrong. Please try again.", _context="error page")}

gt upload extracts the string and registers it with the platform. gt translate generates translations for your configured locales. Same commands, same workflow as the JavaScript libraries.