Deepl API文档翻译英文目标语言问题

问题描述 投票:0回答:1
try
{
    await translator.TranslateDocumentAsync(
          new FileInfo("deneemq11.docx"),
          new FileInfo("deneemq11(11).docx"),
          "TR",
          "EN",
          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}");
    }
}

我使用“EN”作为目标语言,但它给了我一些错误,然后我使用 EN-GB 作为目标语言:

try
{
    await translator.TranslateDocumentAsync(
          new FileInfo("deneemq11.docx"),
          new FileInfo("deneemq11(11).docx"),
          "TR",
          "EN-GB",
          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}");
    }
}

并且它说给定的 target_lang 不支持形式

我需要输入什么才能将目标语言变成英语

c# translation translate deepl
1个回答
0
投票

您要求进行一定程度的正式翻译(代码中的

new DocumentTranslateOptions { Formality = Formality.More }
)。然而,并非所有语言都支持设置形式(例如,某些非英语语言(例如德语)有正式和非正式版本的“you”)。您可以调用语言端点来获取这些语言的最新信息 - 英式英语目前不支持形式,因此您需要更改代码以排除此形式选项:

try
{
    await translator.TranslateDocumentAsync(
          new FileInfo("deneemq11.docx"),
          new FileInfo("deneemq11(11).docx"),
          "TR",
          "EN-GB");
}
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}");
    }
}

您可以在官方文档这里找到更多信息。

© www.soinside.com 2019 - 2024. All rights reserved.