{"id":13644789,"url":"https://github.com/linyuxuanlin/auto-i18n","last_synced_at":"2025-04-21T10:34:28.488Z","repository":{"id":200244874,"uuid":"705110801","full_name":"linyuxuanlin/Auto-i18n","owner":"linyuxuanlin","description":"使用 ChatGPT 自动将 Markdown 文件批量翻译为多语言 | Auto translate Markdown files to multi languages using ChatGPT","archived":false,"fork":false,"pushed_at":"2024-07-16T01:58:01.000Z","size":130,"stargazers_count":362,"open_issues_count":3,"forks_count":26,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-09T17:42:23.270Z","etag":null,"topics":["blog","chatgpt","chatgpt-api","python","website"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linyuxuanlin.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-10-15T03:46:21.000Z","updated_at":"2024-11-08T19:02:09.000Z","dependencies_parsed_at":"2024-08-02T01:19:23.089Z","dependency_job_id":null,"html_url":"https://github.com/linyuxuanlin/Auto-i18n","commit_stats":null,"previous_names":["linyuxuanlin/auto-i18n"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linyuxuanlin%2FAuto-i18n","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linyuxuanlin%2FAuto-i18n/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linyuxuanlin%2FAuto-i18n/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linyuxuanlin%2FAuto-i18n/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linyuxuanlin","download_url":"https://codeload.github.com/linyuxuanlin/Auto-i18n/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250040804,"owners_count":21365167,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blog","chatgpt","chatgpt-api","python","website"],"created_at":"2024-08-02T01:02:13.438Z","updated_at":"2025-04-21T10:34:23.475Z","avatar_url":"https://github.com/linyuxuanlin.png","language":"Python","funding_links":[],"categories":["NLP"],"sub_categories":[],"readme":"# Auto-i18n：使用 ChatGPT 的自动多语言翻译工具\n\nAuto-i18n 是一个使用 ChatGPT 自动将 Markdown 文件批量翻译为多语言的工具。它实现了博客文章 i18n(Internationalization) 的全自动化。你仅需将博文推送至 GitHub 仓库，即可借助 GitHub Actions 实现自动转译为多种语言。（目前支持英语、西班牙语和阿拉伯语，后续将提供更多语言支持）\n\nAuto-i18n 的主要特性：\n\n- **批量多语言翻译**：Auto-i18n 提供了批量翻译的功能，使你能够将一整个路径下的所有 Markdown 文档一次性翻译多语言，极大地提高了多语言化项目的效率。\n- **兼容 Front Matter**：Auto-i18n 兼容 Markdown Front Matter 语法，你可以自定义不同字段的翻译或替换规则。\n- **固定内容替换**：Auto-i18n 还支持固定内容替换。如果你希望文档中一些重复字段的译文保持不变，这个功能可以帮助你实现文档的一致性。\n- **自动化工作流**：你可以使用 GitHub Actions 实现自动化的翻译流程\"。。无需手动干预，翻译工作会自动进行并更新文档，使你能够更专注于内容。\n\n## 快速上手\n\n1. 将仓库克隆到本地，把 `env_template.py` 重命名为 `env.py`，并提供你的 ChatGPT API。如果你没有自己的 API，可以到 [GPT_API_free](https://github.com/chatanywhere/GPT_API_free) 申请到一个免费的；也可以借助 [go-chatgpt-api](https://github.com/linweiyuan/go-chatgpt-api) 把网页版 ChatGPT 转 API 使用。\n2. 安装必需的模块：`pip install -r requirements.txt` 。\n3. 执行命令 `python auto-translater.py` 运行程序，它将会自动处理测试目录 `testdir/to-translate` 下的所有 Markdown 文件，批量翻译为英语、西班牙语、阿拉伯语。（后续将提供更多语言支持）\n\n## 详细描述\n\n程序 `auto-translater.py` 的运行逻辑如下：\n\n1. 程序将自动处理测试目录 `testdir/to-translate` 下的所有 Markdown 文件，你可以在 `exclude_list` 变量中排除不需要翻译的文件。\n2. 处理后的文件名会被记录在自动生成的 `processed_list.txt` 中。下次运行程序时，已处理的文件将不会再次翻译。\n3. 对于原本使用英文撰写的文章，程序不会重新翻译成英文，也不会翻译回中文，而会翻译为其他语言。你需要在文章中添加字段 `\u003e This post was originally written in English.`（注意在上下各留一个空行），以便程序识别。请参考 [测试文章\\_en.md](https://github.com/linyuxuanlin/Auto-i18n/blob/main/testdir/to-translate/测试文章_en.md)。\n4. 如果需要重新翻译指定文章（例如，翻译结果不准确，或文章内容发生更改等），你可以在文章中加入字段 `[translate]`（同样需要在上下各留一个空行）。这将会忽略 `exclude_list` 和 `processed_list` 的规则，强制进行翻译处理。请参考 [测试文章\\_force-mark.md](https://github.com/linyuxuanlin/Auto-i18n/blob/main/testdir/to-translate/测试文章_force-mark.md)。\n5. 如果 Markdown 文件中包含 Front Matter，将按照程序内的规则 `front_matter_translation_rules` 选择以下处理方式：\n   1. 自动翻译：由 ChatGPT 翻译。适用于文章标题或文章描述字段。\n   2. 固定字段替换：适用于分类或标签字段。例如同一个中文标签名，不希望被翻译成不同的英文标签造成索引错误。\n   3. 不做任何处理：如果字段未出现在以上两种规则中，将保留原文，不做任何处理。适用于日期、url 等。\n\n## GitHub Actions 自动化指南\n\n你可以在自己项目仓库下创建 `.github/workflows/ci.yml`，当检测到 GitHub 仓库更新后，可以使用 GitHub Actions 自动进行翻译处理，并自动 commit 回原仓库。\n\n`ci.yml` 的内容可参考模板：[ci_template.yml](https://github.com/linyuxuanlin/Auto-i18n/blob/main/ci_template.yml)\n\n你需要在仓库的 `Settings` - `Secrets and variables` - `Repository secrets` 中添加两个 secrets：`CHATGPT_API_BASE` 和 `CHATGPT_API_KEY`，并在程序 `auto-translater.py` 中将 `import env` 语句注释掉。\n\n## 错误排除\n\n1. 如果需要验证 ChatGPT API key 的可用性，可以使用程序 [verify-api-key.py](https://github.com/linyuxuanlin/Auto-i18n/blob/main/Archive/verify-api-key.py) 进行测试。如果在国内使用官方 API，需要有本地代理。\n2. 如果 Markdown 中的 Front Matter 无法被正常识别，可以使用程序 [detect_front_matter.py](https://github.com/linyuxuanlin/Auto-i18n/blob/main/Archive/detect_front_matter.py) 测试。\n3. 在使用 GitHub Actions 遇到问题时，请优先检查路径引用是否正确（例如 `dir_to_translate` `dir_translated_en` `dir_translated_es` `dir_translated_ar` `processed_list`）。\n\n## 待解决的问题\n\n1. 在某些特殊的情况下，可能会出现翻译不准确、或某些字段没有翻译的情况，建议翻译后手动校验再发布文章。\n2. （已解决）~~如果 Markdown 中包含 Front Matter，将保留 Front Matter 的原始内容。Front Matter 部分参数翻译的功能正在开发中。~~\n\n## 贡献\n\n欢迎你参与本项目的改进！如果您想要贡献代码、报告问题或提出建议，请查看 [贡献指南](https://github.com/linyuxuanlin/Auto-i18n/blob/main/CONTRIBUTING.md)。\n\n## 版权和许可\n\n本项目采用 [MIT 许可证](https://github.com/linyuxuanlin/Auto-i18n/blob/main/LICENSE)。\n\n## 问题和支持\n\n如果你在使用 Auto-i18n 时遇到任何问题，或者需要技术支持，请随时 [提交问题](https://github.com/linyuxuanlin/Auto-i18n/issues)。\n\n我的博客使用 Auto-i18n 实现了多语言支持，你可以到 [Power's Wiki](https://wiki-power.com) 查看 Demo 效果。\n\n[![](https://wiki-media-1253965369.cos.ap-guangzhou.myqcloud.com/img/202310222223670.png)](https://wiki-power.com)\n\n## 致谢\n\n- 感谢 [chatanywhere/GPT_API_free](https://github.com/chatanywhere/GPT_API_free) 提供的免费 ChatGPT API key。\n- 感谢 [linweiyuan/go-chatgpt-api](https://github.com/linweiyuan/go-chatgpt-api) 提供的把网页版 ChatGPT 转 API 的方法。\n\n[![Star History Chart](https://api.star-history.com/svg?repos=linyuxuanlin/Auto-i18n\u0026type=Date)](https://star-history.com/#linyuxuanlin/Auto-i18n\u0026Date)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinyuxuanlin%2Fauto-i18n","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinyuxuanlin%2Fauto-i18n","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinyuxuanlin%2Fauto-i18n/lists"}