# General Translation Python SDKs: t_fallback
URL: https://generaltranslation.com/zh/docs/python/reference/functions/t-fallback.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 在 General Translation Python 中，无需执行翻译查找即可插值字符串。t_fallback 的 API 参考。

可将 `t_fallback` 用于需要插值但不应翻译的字符串，例如已采用默认区域设置的内容。由于它从不执行翻译查找，因此无需初始化管理器即可使用。

## 概览 [#overview]

调用 `t_fallback` 时，传入源字符串，并将插值变量作为关键字参数提供。它会返回插值后的字符串，并委托给 [`interpolate_message`](/docs/python/reference/functions/interpolate-message)。与 [`t`](/docs/python/reference/functions/t) 不同，它不会读取管理器或查找翻译，因此即使管理器尚未初始化也能使用。

```python
from gt_i18n import t_fallback

message = t_fallback("Hello, {name}!", name="World")
```

签名：

```python
t_fallback(message: str, **kwargs: object) -> str
```

从 `gt_i18n` 中导入 `t_fallback`。框架包不会重新导出该项。

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

* **不翻译。** 它仅执行插值，不会对翻译进行哈希、查找或拉取。
* **插值。** 变量会使用 ICU MessageFormat 语法替换，包括 source 中任何已声明的 `_gt_` 变量。
* **错误安全。** 如果消息无法格式化，[`interpolate_message`](/docs/python/reference/functions/interpolate-message) 会返回原始 source，而不会抛出错误。

## 参数 [#parameters]

| 参数                    | 描述                            | Type  | 可选 | 默认值 |
| --------------------- | ----------------------------- | ----- | -- | --- |
| [`message`](#message) | 要进行插值的 ICU MessageFormat 字符串。 | `str` | 否  | —   |
| [`kwargs`](#kwargs)   | 用于插值到消息中的变量。                  | 关键字参数 | 是  | —   |

### `message` [#message]

**类型** `str` · **必填**

用于插值的 ICU MessageFormat 字符串。

### `kwargs` [#kwargs]

**类型** 关键字参数 · **可选**

用于插值到消息中的变量。

## 返回值 [#returns]

**类型** `str`

插值后的字符串。

## 示例 [#example]

```python
from gt_i18n import t_fallback

t_fallback("Welcome, {name}!", name="Alice")
# → "Welcome, Alice!"
```

## Sitemap

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