这是一个小巧、简单的实用工具,它可以解析 Xcode 的 .xcstrings
文件,请求 ChatGPT 翻译每个条目,然后将结果以 xcstrings
JSON 格式保存回去。
此工具被硬编码为使用 ChatGPT-4。 虽然 ChatGPT3.5 价格 значительно 更低,但它不能提供令人满意的效果。 因此,为了确保此工具不会助长 Apple 平台上应用程序中低劣翻译的涌现,刻意省略了通过命令行标志选择模型的功能。
请注意,**强烈建议** 由合格的人员测试翻译结果,因为即使是 ChatGPT-4 也几乎肯定不会产生完美的结果。
此工具支持我个人目前使用的所有功能,但并非 xcstrings
支持的所有功能(例如,我尚未测试复数字符串或随设备变化的字符串)。 欢迎 Pull Requests 来添加这些缺失的功能。
只需拉取此仓库,然后从仓库根目录运行以下命令
swift run ai-translate /path/to/your/Localizable.xcstrings -o <your-openai-API-key> -v -l de,es,fr,he,it,ru,hi,en-GB
帮助输出
USAGE: ai-translate <input-file> --languages <languages> --open-ai-key <open-ai-key> [--verbose] [--skip-backup] [--force]
ARGUMENTS:
<input-file>
OPTIONS:
-l, --languages <languages> a comma separated list of language codes (must match the language codes used by xcstrings)
-o, --open-ai-key <open-ai-key>
Your OpenAI API key, see: https://platform.openai.com/api-keys
-v, --verbose
-s, --skip-backup By default a backup of the input will be created. When this flag is provided, the backup is skipped.
-f, --force Forces all strings to be translated, even if an existing translation is present.
-h, --help Show help information.