# react-native: gt.config.json URL: https://generaltranslation.com/zh/docs/react-native/api/config/gt-config-json.mdx --- title: gt.config.json description: gt.config.json 文件 --- {/* 自动生成:请勿直接编辑。请在 content/docs-templates/ 中编辑 template。 */} ## 概述 `gt.config.json` 文件用于存储项目配置。 它包含重要信息,例如项目的 `projectId`、支持的区域设置等。 它还包含重要的内部信息,例如项目的 `versionId`。 此文件会被 (1) 你的 [``](/docs/react-native/api/components/gtprovider) 组件和 (2) [`gt translate`](/docs/cli/translate) 命令读取。 因此,我们建议将配置保存在 `gt.config.json` 文件中,而不是通过 prop 传给你的 [``](/docs/react-native/api/components/gtprovider) 组件。 通常,任何以下划线开头的内容 (例如 `_versionId`) 都是内部属性,不应修改。 除此之外,其他内容都可以修改。 *** ## 字段 | 字段 | 类型 | 说明 | | ------------------- | ---------- | ----------------------- | | `projectId` | `string` | 你在 GT 系统中的项目唯一标识符 | | `locales` | `string[]` | 项目支持的区域设置代码数组 | | `defaultLocale` | `string` | 缺少翻译时作为回退的主要区域设置代码 | | `cacheUrl` | `string` | 用于缓存翻译数据的 URL 端点 | | `runtimeUrl` | `string` | 用于 runtime 翻译服务的 URL 端点 | | `stageTranslations` | `boolean` | 暂存版/预览翻译功能的配置 | | `files` | `object` | 用于开发和测试的本地翻译文件路径 | | `_versionId` | `string` | 用于跟踪项目版本的内部属性 (请勿修改) | ### `cacheUrl` 和 `runtimeUrl` 如果你将翻译存储在云端,`cacheUrl` 就是缓存的基础 URL。 `runtimeUrl` 是 runtime 的基础 URL,仅用于开发环境中的翻译。 ### `stageTranslations` `stageTranslations` 是 `gt` 工具中的一个标志,用于将你的翻译标记为“待审核”。 这意味着这些翻译必须先经过人工批准,才能通过 [`gt translate`](/docs/cli/translate) 命令部署到生产环境。 ### `files` `files` 字段用于指定本地存储翻译的路径 (而不是存储在云端) 。 具体来说,`output` 字段用于指定翻译将写入的位置。 ```json { "files": { "gt": { "output": "public/_gt/[locale].json" } }, } ``` 如需了解如何使用 `files` 字段的更多信息,请参阅 CLI 工具的[配置文档](/docs/cli/reference/config)。 #### `parsingFlags` `files.gt.parsingFlags` 对象用于控制编译器如何解析源文件。 | 标志 | 类型 | 默认值 | 说明 | | ------------------------ | --------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------ | | `enableAutoJsxInjection` | `boolean` | `false` | 在 build 时自动将可翻译的 JSX 文本包裹在翻译组件中。参见[自动 JSX 注入](/docs/cli/features/auto-jsx-injection)。 | | `autoderive` | `boolean` | `false` | 自动将 `t()`、`gt()` 和 `msg()` 调用中的插值视为 [`derive()`](/docs/react-native/api/strings/derive) 调用。参见 [autoderive](/docs/cli/features/autoderive)。 | ```json title="gt.config.json" { "files": { "gt": { "output": "public/_gt/[locale].json", "parsingFlags": { "enableAutoJsxInjection": true, "autoderive": true } } } } ``` {/* ### `_versionId` 要点: - 仅供内部使用 - 你也可以自定义版本名称 */} *** ## 示例 ### 指定 locales ```json title="gt.config.json" { "defaultLocale": "en", // 主要区域设置为英语 "locales": ["fr", "es"] // 次要区域设置为法语和西班牙语 } ``` {/* ### 指定自定义 versionId */} *** ## 说明 * `gt.config.json` 文件用于指定项目配置。 * [``](/docs/react-native/api/components/gtprovider) 组件和 [`gt translate`](/docs/cli/translate) 命令都会读取该文件。 * 该文件应放在项目根目录下。 ## 后续步骤