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 不支持形式
我需要输入什么才能将目标语言变成英语
您要求进行一定程度的正式翻译(代码中的
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}");
}
}
您可以在官方文档这里找到更多信息。