translate method

translate(source_document, target_language)

Translates the provided document into the specified target language.

def translate(self, source_document: aspose.words.Document, target_language: aspose.words.ai.Language):
    ...
ParameterTypeDescription
source_documentDocument
target_languageLanguage

Remarks

Same approach as OpenAiModel.translate(): the whole document is sent as one piece of text marked with run separators, to preserve the original formatting by restoring the translation back into the original runs. A small local model damages a run separator more often than a cloud model, so any run that could not be restored this way is translated again individually, by Aspose.Words.AI.AsposeLlmModel.Translate(Aspose.Words.Run,Aspose.Words.AI.Language).

Examples

Shows how to translate a document with a local model.

doc = aw.Document(file_name=MY_DIR + "Document.docx")
with aw.ai.AsposeLlmModel("Qwen25_3BPresetCpu") as model:
    translated_doc = model.translate(doc, aw.ai.Language.GERMAN)
    translated_doc.save(file_name=ARTIFACTS_DIR + "AI.AsposeLlmTranslate.docx")

See Also