# General Translation Python SDKs: derive
URL: https://generaltranslation.com/zh/docs/python/reference/functions/derive.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 在 General Translation Python 中，用一组有限的变体标记内容，以便在构建时提取。derive 的 API 参考。

将内容标记为可进行静态分析，以便 General Translation CLI 能在构建时提取所有可能的翻译条目。它是一个恒等函数——会原样返回你传入的内容——仅作为标记使用。

## 概览 [#overview]

使用 `derive` 包装具有有限个可能值的静态表达式，通常放在 [`t`](/docs/python/reference/functions/t) 调用中。在运行时，`derive` 会原样返回其输入；在提取阶段，CLI 会为每个结果生成一个翻译条目。

```python
from gt_flask import derive, t  # 或：from gt_fastapi，或：from gt_i18n

message = t(f"The {derive('boy' if gender == 'male' else 'girl')} is playing.")
```

签名：

```python
derive(content: object) -> object
```

由 `gt_i18n` 和各框架包从 `generaltranslation.static` 重新导出。用法请参阅[声明变量和变体](/docs/python/guides/declaring-variables)。

## 工作原理 [#how-it-works]

* **运行时恒等。** 它会原样返回 `content`；唯一作用是为 CLI 标记内容。
* **静态分析。** 所有可能的 outcome 都必须在 构建时 可静态分析，以便 CLI 为每种 outcome 生成一个 entry。
* **动态值。** 使用 [`declare_var`](/docs/python/reference/functions/declare-var) 将 dynamic content 包装到派生句子中。

## 参数 [#parameters]

| 参数                    | 描述                | 类型       | 可选 | 默认值 |
| --------------------- | ----------------- | -------- | -- | --- |
| [`content`](#content) | 具有一组有限可能取值的静态表达式。 | `object` | 否  | —   |

### `content` [#content]

**类型** `object` · **必填**

一个静态表达式，其可能值是有限且确定的。

## 返回值 [#returns]

**类型** `object`

原样返回 `content`。该函数只是供 CLI 使用的恒等标识。

## 示例 [#example]

```python
from gt_flask import t, derive, declare_var

t(f"{declare_var(name, name='name')} adopted a {derive('cat' if is_cat else 'dog')}.")
```

*注意：[`declare_static`](/docs/python/reference/functions/declare-static) 是 `derive` 的已弃用别名。新代码请使用 `derive`。*

## Sitemap

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