# General Translation Changelog: gt-cli 2.9.0: Twilio 内容模板翻译
URL: https://generaltranslation.com/zh/blog/gt-cli_v2_9_0.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 
Authors: Ernest McCarter
Published: 2026-03-10

## 概述

`gt` CLI 现已支持 Twilio Content JSON 文件格式。如果你使用 Twilio 的 Content Template Builder 通过 WhatsApp、SMS 或 RCS 发送结构化消息，现在就可以使用与应用中相同的 [`gt translate`](/docs/cli/reference/commands/translate) 工作流来翻译这些内容模板。

## 为什么这很重要

Twilio 内容模板是用于定义结构化消息的 JSON 文件——包括带变量的文本、快速回复按钮，以及包含媒体和操作的卡片。这些内容模板中包含面向用户的字符串：按钮标签、正文文本、卡片标题。如果你要发送多语言消息，这些字符串就需要翻译。

目前的做法是通过 Twilio Console 或 API，手动为每种语言分别创建一个内容模板。每个内容模板都有自己的 SID、自己的审核周期，以及各自的维护成本。这样一来，对于一条消息在不同语言中具体表达了什么，就没有一个统一的真相来源。

通过这次 CLI 更新，你只需用默认语言编写一次内容模板，其余的交给 [`gt translate`](/docs/cli/reference/commands/translate) 处理。

## 操作演示

假设你正在使用 Twilio 通过 WhatsApp 搭建一个客户支持流程。你有一个快速回复内容模板，用来向用户打招呼，并提供三个选项：

```json
{
  "friendly_name": "support_greeting",
  "language": "en",
  "variables": { "1": "客户" },
  "types": {
    "twilio/quick-reply": {
      "body": "您好，{{1}}。感谢您联系支持。请问我们可以如何帮助您？",
      "actions": [
        { "title": "查询订单状态", "id": "order_status" },
        { "title": "退货", "id": "return_item" },
        { "title": "联系人工客服", "id": "speak_agent" }
      ]
    },
    "twilio/text": {
      "body": "您好，{{1}}。感谢您联系支持。请问我们可以如何帮助您？"
    }
  }
}
```

`actions` 中的 `body` 字段和 `title` 值都是可翻译的字符串。`{{1}}` 变量占位符、`id` 字段以及结构键则不是。


### 第 1 步：配置

将 `twilioContentJson` 添加到 `gt.config.json` 文件的设置中：

```json
{
  "defaultLocale": "en",
  "locales": ["en", "es", "fr", "ja"],
  "files": {
    "twilioContentJson": {
      "include": ["twilio/[locale]/**/*.json"]
    }
  }
}
```

`include` 路径中的 `[locale]` 占位符用于告诉 CLI 到哪里查找源文件，以及将翻译结果保存到哪里。源文件从 `twilio/en/` 读取，翻译后的文件会保存到 `twilio/es/`、`twilio/fr/` 等目录中。


### 第 2 步：`translate`

```bash
npx gt@latest translate
```

系统会为每个已配置的区域设置生成对应的翻译。输出会保留 Twilio JSON 的结构——变化的只有字符串值。

西班牙语输出可能如下：

```json
{
  "friendly_name": "support_greeting",
  "language": "es",
  "variables": { "1": "Customer" },
  "types": {
    "twilio/quick-reply": {
      "body": "Hola, {{1}}. Gracias por contactar con soporte. ¿En qué podemos ayudarte?",
      "actions": [
        { "title": "Ver estado del pedido", "id": "order_status" },
        { "title": "Devolver un artículo", "id": "return_item" },
        { "title": "Hablar con un agente", "id": "speak_agent" }
      ]
    },
    "twilio/text": {
      "body": "Hola, {{1}}. Gracias por contactar con soporte. ¿En qué podemos ayudarte?"
    }
  }
}
```

每个翻译后的文件都是有效的 Twilio Content JSON 内容模板，可直接上传到 Twilio Content API，作为新的特定于区域设置的 内容模板。


## 链接

* [CLI 设置参考文档](/docs/cli/reference/config)
* [Twilio Content Template Builder](https://www.twilio.com/docs/content)
* [来源](https://github.com/generaltranslation/gt/pull/1099)

## Sitemap

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