解决json-autotranslate项目中使用DeepL翻译服务报错问题

解决json-autotranslate项目中使用DeepL翻译服务报错问题

【免费下载链接】json-autotranslate Translate a folder of JSON files containing translations into multiple languages. 【免费下载链接】json-autotranslate 项目地址: https://gitcode.com/gh_mirrors/js/json-autotranslate

在使用json-autotranslate工具进行多语言JSON文件自动翻译时,开发者可能会遇到"Could not fetch supported languages from DeepL"的错误提示。这个问题通常与DeepL翻译服务的配置有关。

问题现象

当执行如下命令时:

yarn json-autotranslate -i src/locales --directory-structure ngx-translate --service deepl --config "mykey"

工具会报错:

Could not fetch supported languages from DeepL
Error: Could not fetch supported languages from DeepL

问题原因

这个错误的核心原因是使用了错误的DeepL服务类型。DeepL实际上提供了两种API服务:

  1. DeepL Pro API (付费服务,对应服务名deepl)
  2. DeepL Free API (免费服务,对应服务名deepl-free)

当开发者使用的是DeepL的免费API密钥时,却错误地指定了--service deepl参数,就会导致无法获取支持的语言列表。

解决方案

正确的做法是根据自己使用的API类型选择对应的服务名称:

  • 如果使用的是DeepL免费API,应该使用deepl-free作为服务名:

    --service deepl-free --config "your_api_key"
    
  • 如果使用的是DeepL付费API,则保持使用deepl作为服务名

技术背景

DeepL的免费和付费API虽然功能相似,但实际上是两个不同的服务端点:

  1. 免费API端点:https://api-free.deepl.com
  2. 付费API端点:https://api.deepl.com

json-autotranslate工具内部会根据指定的服务类型选择不同的API端点进行请求。如果服务类型与API密钥不匹配,就会导致认证失败,无法获取支持的语言列表。

最佳实践

  1. 确认自己使用的是DeepL的哪种API服务(免费还是付费)
  2. 在json-autotranslate配置中使用对应的服务名称
  3. 确保API密钥正确无误
  4. 检查网络连接是否正常,能够访问DeepL的API服务器

通过正确配置服务类型,开发者可以顺利使用json-autotranslate工具配合DeepL进行多语言JSON文件的自动翻译工作。

【免费下载链接】json-autotranslate Translate a folder of JSON files containing translations into multiple languages. 【免费下载链接】json-autotranslate 项目地址: https://gitcode.com/gh_mirrors/js/json-autotranslate

创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值