# General Translation Python SDKs: decode_msg
URL: https://generaltranslation.com/zh/docs/python/reference/functions/decode-msg.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 从 General Translation Python 中编码后的 msg 结果提取人类可读的消息。decode_msg 的 API 参考。

从 [`msg`](/docs/python/reference/functions/msg) 生成的字符串中提取插值后的人类可读消息。它会返回编码后的 options 负载之前的文本。

## 概述 [#overview]

使用编码后的 [`msg`](/docs/python/reference/functions/msg) 结果调用 `decode_msg`。它会在最后一个冒号处拆分，并返回左侧部分。如果没有冒号，则原样返回输入值。

```python
from gt_i18n import decode_msg

decode_msg(encoded_message)
```

签名：

```python
decode_msg(encoded_msg: str) -> str
```

从 `gt_i18n` 导入 `decode_msg`。框架包不会再次导出它。

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

* **按最后一个冒号拆分。** 编码后的 [`msg`](/docs/python/reference/functions/msg) 结果格式为 `{interpolated}:{base64options}`；`decode_msg` 会返回最后一个冒号之前的全部内容。
* **普通输入。** 如果不含冒号，它会原样返回输入，因此普通字符串会直接透传，不会发生任何变化。

## 参数 [#parameters]

| 参数                            | 描述                                                           | 类型    | 可选 | 默认值 |
| ----------------------------- | ------------------------------------------------------------ | ----- | -- | --- |
| [`encoded_msg`](#encoded-msg) | 编码后的 [`msg`](/docs/python/reference/functions/msg) 结果或普通字符串。 | `str` | 否  | —   |

### `encoded_msg` [#encoded-msg]

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

要解码的编码后的 [`msg`](/docs/python/reference/functions/msg) 结果 (或普通字符串) 。

## 返回值 [#returns]

**类型** `str`

插值后的消息；如果不含冒号，则原样返回输入内容。

## 示例 [#example]

```python
from gt_i18n import msg, decode_msg

encoded = msg("Hi, {name}!", name="Bob")
decode_msg(encoded)      # "Hi, Bob!"
decode_msg("Plain text") # "Plain text"
```

## Sitemap

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