Translate Word, PDF, Web documents in Python

Python solution for translating documents using AI

Seamless integration with Google Gemini generative language models provides extensive AI-based document processing capabilities for Python applications.

View code snippet

Translate Documents to 300+ Languages in Python

Automate document translation using Google Gemini AI models with Aspose.Words for Python via .NET. Translate DOC, DOCX, RTF, PDF, HTML, Markdown, ODT, TXT, and EPUB files into over 300 languages while preserving the original layout and formatting. The AI-based engine detects the source language automatically — even in multi-language documents — and leaves untranslated only those fragments it cannot identify.

Why Developers Choose Aspose.Words for Document Translation

  • Single API call to translate an entire document
  • Automatic source-language detection for mixed-language documents
  • Output preserved in the original format and layout
  • Support for DOC, DOCX, RTF, PDF, ODT, HTML, Markdown, TXT, EPUB, and more

Authentication requires a Google API key. For a full list of supported AI models, see the API Reference.

Start translating documents in Python today — try the live demo above.

Example code in Python for translating a document
Select the target format from the list
Run code
pip install aspose-words
Copy
doc = aw.Document("Document.docx")
api_key = os.getenv("API_KEY")

# Use Google generative language models.
model = aw.ai.AiModel.create(aw.ai.AiModelType.GEMINI_FLASH_LATEST).with_api_key(api_key)

translated_doc = model.translate(doc, aw.ai.Language.ARABIC)
translated_doc.save("Output.docx")
doc = aw.Document("Document.docx")
# Pass an empty string if the self-hosted model does not require an API key.
model = CustomAiModel("my-model-24b", "https://your-server.com/v1").with_api_key("")

translated_doc = model.translate(doc, aw.ai.Language.ARABIC)
translated_doc.save("Output.docx")

class CustomAiModel(aw.ai.OpenAiModel):
    def __init__(self, name, url):
        super().__init__(name)
        self._url = url
    @property
    def url(self):
        return self._url
Run code

How to translate a document in Python

  1. Install Aspose.Words for Python via .NET.
  2. Add a library reference (import the library) to your Python project.
  3. Open the source file in Python.
  4. Invoke Translate method, passing in your document along with the target Language.
  5. Once completed, you will receive a translated document that you can save as a new file in the format you need.

Python via .NET library to translate documents

We host our Python packages in PyPi repositories. Please follow the step-by-step instructions on how to install "Aspose.Words for Python via .NET" to your developer environment.

System Requirements

This package is compatible with Python ≥3.5 and <3.12. If you develop software for Linux, please have a look at additional requirements for gcc and libpython in Product Documentation.

5%

Subscribe to Aspose Product Updates

Get monthly newsletters and offers directly delivered to your mailbox.

© Aspose Pty Ltd 2001-2026. All Rights Reserved.