# gt: General Translation CLI tool: gt save-local
URL: https://generaltranslation.com/zh/docs/cli/reference/commands/save-local.mdx
Docs index: https://generaltranslation.com/llms.txt
Description: 将本地翻译修改同步回 General Translation platform。gt save-local 命令的 API 参考。

通过提交差异，将你对翻译文件所做的本地修改发送回 General Translation platform。它不会将任何新翻译加入队列——只会同步你的本地更改。请参阅[管理翻译](/docs/cli/guides/managing-translations#save-local)。

当你或译者手动编辑已下载的翻译文件，并希望这些更改同步到平台时，请使用此命令。

*注意：需要 `GT_API_KEY` 和 `GT_PROJECT_ID`。*

```bash
npx gt save-local
```

## 工作方式 [#how-it-works]

1. 从 `gt.config.json` 读取你配置的文件。
2. 确定当前的 git branch。
3. 通过比较内容哈希，识别自上次下载以来发生变更的文件。
4. 获取服务器上的原始内容，并为每个已变更的文件计算 diff。
5. 将这些差异提交到平台。只处理已变更的文件。
6. 当至少保存了一个 diff，且已配置发布或设置了 `--publish` 时，将应用已配置的 CDN publish 和 unpublish 规则。若没有本地变更，则跳过发布。

## 标记 [#flags]

| 参数                    | 描述                            | 类型        | 可选 | 默认值              |
| --------------------- | ----------------------------- | --------- | -- | ---------------- |
| `--api-key <key>`     | General Translation 的 API 密钥。 | `string`  | 是  | `GT_API_KEY`     |
| `--project-id <id>`   | 项目 ID。                        | `string`  | 是  | `GT_PROJECT_ID`  |
| `-c, --config <path>` | config file 的路径。              | `string`  | 是  | `gt.config.json` |
| `--publish`           | 保存本地差异后使用 CDN 发布规则。           | `boolean` | 是  | `false`          |

## 示例 [#example]

```bash
# 将翻译文件中的本地编辑发送回平台
npx gt save-local

# 同步编辑并将更新后的翻译发布到 CDN
npx gt save-local --publish
```

## 其他注意事项 [#notes]

* CLI 会在锁文件中记录已下载的翻译，并且只处理自上次下载以来有变更的文件。
* 默认情况下，[`gt translate`](/docs/cli/reference/commands/translate) 和 [`gt stage`](/docs/cli/reference/commands/stage) 不会保存本地修改。可使用 `--save-local` 为单次运行启用该步骤，或使用 [`options.saveLocal`](/docs/cli/reference/config#save-local) 为所有运行启用。若要同步编辑而不启动新的翻译任务，请使用 `gt save-local`。
* Apple 的 `.strings` 与 `.stringsdict` 文件以及 Android 的 `strings.xml` 文件会作为完整的原始文档进行验证并保存。对于 `.xcstrings`，尽管所有区域设置共用一个文件，CLI 仍会分别跟踪并提交每个区域设置的片段。
* 绝不要将 API 密钥存储在 `gt.config.json` 中。CLI 会自动从环境变量中读取 `GT_API_KEY`。

## Sitemap

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