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}");
}
}
I used "EN" for target language but it gave me some errors then I used EN-GB for target language:
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}");
}
}
and it says formality is not supported for given target_lang
What do I need to enter for target language to become English
You are requesting to translate with a certain level of formality (new DocumentTranslateOptions { Formality = Formality.More }
in your code). However, not all languages support setting a formality (e.g. some non-English languages like German have a formal and an informal version of "you"). You can call the languages endpoint to get up-to-date information which languages these are - British English currently does not support formality, so you need to change your code to exclude this formality option:
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}");
}
}
You can find more information in the official docs here.