# gt: General Translation CLI tool: gt generate URL: https://generaltranslation.com/zh/docs/cli/reference/commands/generate.mdx --- title: gt generate description: 为 General Translation 项目生成源模板文件。gt generate 命令的 API 参考。 --- 为默认locales和目标locales生成源模板文件,格式与 [`translate`](/docs/cli/reference/commands/translate) 命令使用的格式相同。如果你不通过 General Translation API,而是自行处理翻译,可使用此命令,然后通过[本地翻译](/docs/react/guides/storing-translations)提供结果。 *注意:仅适用于框架库和内联库——`gt-next`、`gt-react`、`gt-react-native`、`gt-tanstack-start`、`gt-node`、`gt-flask` 和 `gt-fastapi`。基础 (非框架) 项目不会注册此命令。如果你使用 General Translation API,请改用 [`gt translate`](/docs/cli/reference/commands/translate)。* 请先配置项目,然后再生成模板。 ```bash npx gt configure npx gt generate ``` ## 工作方式 [#how-it-works] 1. 读取 `gt.config.json`,确定默认locales和目标locales。 2. 扫描源代码中的内联内容——[``](/docs/react/reference/components/t) 组件和 [`useGT`](/docs/react/reference/hooks/use-gt) 调用——并像 [`gt translate`](/docs/cli/reference/commands/translate) 收集内容一样,将 dictionary 也包含在内。 3. 为每个locales写入一个 `translate` 所用格式的源模板文件,且无需调用 General Translation API。 ## 标志 [#flags] `generate` 接受与 [`gt translate`](/docs/cli/reference/commands/translate#flags) 相同的标志。下面列出的是最常用的几个;完整列表请参阅上方链接的参考文档。 | Parameter | Description | Type | Optional | Default | | ------------------------------- | -------------------------- | ---------- | -------- | ------------------------------------------ | | `--src ` | source files 的 Glob 模式。 | `string[]` | 是 | `src`、`app`、`pages`、`components` 的 glob 模式 | | `--dictionary ` | dictionary file 的路径。 | `string` | 是 | — | | `--tsconfig, --jsconfig ` | TS 或 JS config file 的路径。 | `string` | 是 | 自动检测 | | `--inline` | 包含内联内容,例如 `` 和 `useGT`。 | `boolean` | 是 | `true` | | `--default-locale ` | 项目的 source 区域设置。 | `string` | 是 | `en` | | `--ignore-errors` | 忽略扫描内联内容时发现的错误。 | `boolean` | 是 | `false` | ## 示例 [#example] ```bash # 为已配置的 locales 生成 templates npx gt generate # 从自定义源区域设置生成,忽略扫描错误 npx gt generate --default-locale en-US --ignore-errors ``` ## 其他说明 [#notes] 生成模板文件后,使用[本地翻译](/docs/react/guides/storing-translations)将其提供给用户。每当 source 内容发生变化时,都请重新运行 `generate`。