DeepL API文档翻译:英文目标语言设置与正式度报错问题
问题
调用DeepL API的TranslateDocumentAsync接口翻译土耳其语(TR)文档至英文时,遇到两个问题:
- 使用目标语言代码
"EN"时触发错误; - 改用
"EN-GB"后,收到「给定目标语言不支持正式度设置」的报错。
需要找到能成功翻译英文且支持正式度设置的目标语言代码。
解决方案
DeepL的文档翻译接口中,**美式英语代码"EN-US"**支持正式度(Formality)设置,而通用英文代码"EN"、英式英语代码"EN-GB"在文档翻译场景下不支持该配置。
修正后的代码示例如下:
try { await translator.TranslateDocumentAsync( new FileInfo("deneemq11.docx"), new FileInfo("deneemq11(11).docx"), "TR", "EN-US", new DocumentTranslateOptions { Formality = Formality.More }); } catch (DocumentTranslationException exception) { // If the error occurs *after* upload, the DocumentHandle will contain the document ID and key if (exception.DocumentHandle != null) { var handle = exception.DocumentHandle.Value; MessageBox.Show($"Document ID: {handle.DocumentId}, Document key: {handle.DocumentKey}"); } else { MessageBox.Show($"Error occurred during document upload: {exception.Message}"); } }
内容的提问来源于stack exchange,提问作者Yakup Aktepe
相关产品推荐
相关产品推荐

