This project is a Word document (.docx) translator built with Microsoft Azure Translator Text API, developed in Python and designed to run in environments such as Google Colab.
The script reads a .docx file, translates its content paragraph by paragraph, and generates a new translated document.
- Python
- Azure Translator Text API
- Requests
- python-docx
- Google Colab
The application performs the following steps:
- Reads a
.docxdocument - Iterates through each paragraph
- Sends the text to Azure Translator API
- Receives the translated text
- Creates a new
.docxfile with the translated content
Before running the code, you must configure your Azure Translator credentials.
subscription_key = "YOUR_AZURE_TRANSLATOR_KEY"
endpoint = "https://api.cognitive.microsofttranslator.com"
location = "eastus2"
language = "pt-br"- Upload your .docx file to the environment
- Update the input file path:
input_file = "/content/music.docx"- Run the script:
translate_document(input_file)- The translated file will be saved with a language suffix:
music_pt-br.docx- Code example:
translate_document("/content/music.docx")- Output:
Original file: music.docx
Translated file: music_pt-br.docx
Each paragraph is translated individually and preserved in the final document.
- The source language is set to English (from: 'en')
- The target language can be changed using the language variable
- Empty paragraphs are still processed
- Large documents may consume more API quota