How to Translate Text in Python

Using the WhatsMate Translation REST API

This article shows you how to translate text in Python.

To translate text (e.g. from English to Portuguese) from a Python script, do this:

  1. Copy the following source code to your Python script.
  2. Specify the language code of the original text on line 10.
  3. Specify the language code of your target language on line 11.
  4. Specify the text that needs to be translated on line 12.
  5. Install the Requests library because the sample script depends on it: pip install requests
  6. Make your script executable: chmod 755
  7. Run the script to see the result: ./

Looking for your language code? See the complete listing.

The trial account only allows you to call the translation API up to 10 times for learning purpose. Subscribe to a Premium plan to use the translation API seriously.

Want to translate text in another programming language? Check out the Translation API page.