translate method
translate(source_document, target_language)
Translates the provided document into the specified target language. This operation leverages the connected AI model for content translating.
def translate(self, source_document: aspose.words.Document, target_language: aspose.words.ai.Language):
...
Parameter | Type | Description |
---|---|---|
source_document | Document | The document to be translated. |
target_language | Language | The language into which the document will be translated. |
Returns
A new Document object containing the translated document.
Examples
Shows how to translate text using Google models.
doc = aw.Document(file_name=MY_DIR + 'Document.docx')
api_key = system_helper.environment.Environment.get_environment_variable('API_KEY')
# Use Google generative language models.
model = aw.ai.AiModel.create(aw.ai.AiModelType.GEMINI_15_FLASH).with_api_key(api_key)
translated_doc = model.translate(doc, aw.ai.Language.ARABIC)
translated_doc.save(file_name=ARTIFACTS_DIR + 'AI.AiTranslate.docx')
See Also
- module aspose.words.ai
- class AiModel