We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Translate Document using Aspose.Words

Hi Adam,

Is it feasible to translate the content of Microsoft word document from English to any other language or vice versa using ASPOSE utilities.

Could you please provide us a small example to use this utility if it exists?

Thanks & Regards,
Ashish Gupta

This message was posted using Email2Forum by aske012.

Hi Ashish,

Thanks for your inquiry.

I’m afraid Aspose.Words and any Aspose component in general does not provide this functionality.

However you may be able to use a different component inconjunction with Aspose.Words to achieve what you need. For example, please see the code below which uses the GoogleTranslateAPI to translate the document from English to German. Please note that I believe that the GoogleTranslateAPI may now require some sort of licensing in order to use.

Document doc = new Document("Rendering.doc");
TranslateClient client = new TranslateClient("Test Translation");
// Translate each paragraph in the document.
foreach (Paragraph para in doc.GetChildNodes(NodeType.Paragraph, true))
{
    string translatedText = string.Empty;
    try
    {
        string paragraphText = para.Range.Text.Trim();
        // Translate the paragraph text using Google Translate API. In this case from English to German.
        translatedText = client.Translate(paragraphText, Language.English, Language.German);
        // Replace the original text with the translation. 
        if (!string.IsNullOrEmpty(paragraphText))
            para.Range.Replace(paragraphText, translatedText, false, false);
    }
    catch (Exception e)
    {
        // Skip any paragraphs which cause an exception, most likely caused by AW encountereing string with a special char. Decide how to handle other exceptions here too.
    }
}
doc.Save("Document Translated.doc");

Thanks,