问题描述
我正在尝试使用 Microsoft Translator API 将文本从波兰语翻译成任何其他语言。在波兰语中,有几个特殊字符,如“ą”、“ś”、“ż”等。当我发送没有特殊字符的 HTTP 请求时:
POST /translate?api-version=3.0&from=pl&to=en HTTP/1.1
Ocp-Apim-Subscription-Key: ********
Ocp-Apim-Subscription-Region: ******
Content-Length: 21
Host: api.cognitive.microsofttranslator.com
Connection: close
User-Agent: Apache-HttpClient/4.5.10 (Java/15.0.2)
Accept-Encoding: gzip,deflate
[{"Text": "Gramatyka"}]
我收到了正确的翻译:
[{"translations":[{"text":"grammar","to":"en"}]}]
但是,波兰语单词或句子很可能包含特殊字符:
POST /translate?api-version=3.0&from=pl&to=en HTTP/1.1
Ocp-Apim-Subscription-Key: ********
Ocp-Apim-Subscription-Region: ********
Content-Length: 21
Host: api.cognitive.microsofttranslator.com
Connection: close
User-Agent: Apache-HttpClient/4.5.10 (Java/15.0.2)
Accept-Encoding: gzip,deflate
[{"Text": "Roślina"}]
此请求导致错误代码 400000:
{"error":{"code":400000,"message":"One of the request inputs is not valid."}}
如果我将特殊字符更改为标准字符(例如将“ś”更改为“s”),则 API 不会提供正确的翻译。例如:
[{"Text": "Roslina"}]
结果:
[{"translations":[{"text":"Roslina","to":"en"}]}]
而“roślina”应翻译为“植物”。
这个问题也适用于其他语言。例如德语:
[{"Text": "Wörterbuch"}]
也会导致 400000 错误。
有没有人找到解决方法?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)