# gt: General Translation CLI tool: GT
URL: https://generaltranslation.com/zh/docs/cli/reference/formats/gt-jsx-files.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 使用 General Translation 翻译 gt-next、gt-react 和 gt-react-native 项目。gt 文件格式的 API 参考。

`gt` 文件格式用于存储使用 [`gt-react`、`gt-next` 或 `gt-react-native`](/docs/react/overview) 的项目翻译内容。运行 [`gt translate`](/docs/cli/reference/commands/translate) 时，CLI 会扫描你的源代码，查找内联内容——例如 [`<T>`](/docs/react/reference/components/t) 组件和 [`useGT`](/docs/react/reference/hooks/use-gt) 调用——以及你的字典，并将结果写入这种格式。

## 配置 [#config]

在 `files` 下添加一个 `gt` 条目。它支持设置 `output` 路径，并使用 `[locale]` 占位符将翻译保存到本地。

```json title="gt.config.json"
{
  "defaultLocale": "en",
  "locales": ["fr", "es"],
  "files": {
    "gt": {
      "output": "public/i18n/[locale].json"
    }
  }
}
```

这会将法语和西班牙语的译文分别保存到 `public/i18n/fr.json` 和 `public/i18n/es.json`，你可以使用 [`loadTranslations`](/docs/react/reference/functions/load-translations) 加载它们。

## 存储选项 [#storage]

* **本地：**将 `output` 设为把翻译打包到应用中。这是默认设置——在此配置下，CLI 不会发布到 CDN。
* **CDN：**省略 `output` 并启用发布，改为在运行时加载翻译。请参阅 [CDN 发布](/docs/cli/reference/config#cdn-publishing)。

目前，每个区域设置只能生成一个输出文件。

## 内联内容解析 [#parsing]

`gt` 条目接受一个 `parsingFlags` 对象，用于控制 CLI 解析内联内容的方式。默认情况下，所有标志均为禁用状态。

```json title="gt.config.json"
{
  "files": {
    "gt": {
      "parsingFlags": {
        "autoderive": true,
        "devHotReload": true,
        "enableAutoJsxInjection": true,
        "includeSourceCodeContext": true,
        "legacyGtReactImportSource": false
      }
    }
  }
}
```

* `autoderive` — 解析 [`t()`](/docs/react/reference/functions/t-function)、`gt()` 和 [`msg()`](/docs/react/reference/functions/msg) 调用中的插值，以及 [`<T>`](/docs/react/reference/components/t) 组件内表达式中的插值，并将其视为已由 [`derive()`](/docs/react/reference/functions/derive) 包裹处理，为每个可能的值生成单独的翻译条目。接受 `true` 或对象，例如 `{ "jsx": true, "strings": false }`。参见[自动派生翻译](/docs/cli/guides/using-autoderive)。
* `devHotReload` — 在开发期间为新内容启用运行时翻译。`true` 会启用字符串翻译；使用如 `{ "strings": true, "jsx": true }` 之类的对象可分别控制字符串和 JSX 的处理。
* `enableAutoJsxInjection` — 在构建时将可翻译的 JSX 文本包裹在 [`<T>`](/docs/react/reference/components/t) 组件中，这样你就无需手动添加了。参见[自动 JSX 注入](/docs/cli/guides/using-auto-jsx)。
* `includeSourceCodeContext` — 将周围的源代码行作为额外上下文包含到每条翻译中。替代已弃用的顶层 `files.gt.includeSourceCodeContext` 键。
* `legacyGtReactImportSource` — 使编译器注入的导入解析为 `gt-react/browser`。仅在旧版 `gt-react` 导出该路径时启用；当前版本使用根级 `gt-react` 导入。

## Sitemap

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