# General Translation Changelog: gt-cli 2.8.0: 支持 Python 项目
URL: https://generaltranslation.com/zh/blog/gt-cli_v2_8_0.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 
Authors: Ernest McCarter
Published: 2026-03-10

## 概述

`gt` CLI 现已支持 Python 项目。在 Flask 或 FastAPI 项目中运行 [`gt upload`](/docs/cli/reference/commands/upload) 时，会从 Python 源文件中提取 [`t()`](/docs/python/reference/functions/t) 调用，并将其注册到 GT 平台。

## 变更内容

新的 `@generaltranslation/python-extractor` 包可解析 Python 源文件并提取翻译调用。CLI 会检查你的 `pyproject.toml`、`requirements.txt` 或 `setup.py` 中是否包含 `gt-flask` 或 `gt-fastapi`，以自动识别 Python 项目。

该提取器支持：

* 带关键字参数插值的 `t("string literal")` 调用
* [`declare_var()`](/docs/python/reference/functions/declare-var)：将动态 f-string 表达式标记为变量
* [`declare_static()`](/docs/python/reference/functions/declare-static)：嵌入应在提取时求值的静态表达式
* Python 特有的元数据 kwargs (`_context`、`_id`、`_max_chars`) ——使用以下划线开头的关键字参数，而不是 JavaScript 库中使用的 options 对象

## 示例

```python
from gt_flask import t

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

[`gt upload`](/docs/cli/reference/commands/upload) 会提取字符串并将其注册到平台。[`gt translate`](/docs/cli/reference/commands/translate) 会为你已配置的区域设置生成翻译。命令和工作流与 JavaScript 库相同。

## 链接

* [gt-flask 和 gt-fastapi 开发日志](/devlog/gt-flask_v0_1_0)
* [CLI 文档](/docs/cli/reference/config)
* [源代码 (CLI) ](https://github.com/generaltranslation/gt)
* [源代码 (Python) ](https://github.com/generaltranslation/gt-python)

## Sitemap

See the full [sitemap](https://generaltranslation.com/sitemap.md) for all pages.
