Test a Translation (Quick Script)
Nuvi needs proof the translator engine actually works before wiring it into the bot. This tiny script is that proof.
Let’s send some text to the server using a short Python file.
Create a new file named test_translate.py:
import requests
# Test 1: Language Detection
print("Testing language detection...")
detect_payload = {"q": "Hello world!"}
detect_resp = requests.post("http://127.0.0.1:5000/detect", json=detect_payload)
print("Detection result:", detect_resp.json())
# Test 2: Translation
print("\nTesting translation...")
translate_payload = {
"q": "Hello world!",
"source": "en",
"target": "es",
"format": "text"
}
translate_resp = requests.post("http://127.0.0.1:5000/translate", json=translate_payload)
print("Translation result:", translate_resp.json())
Run it (make sure the LibreTranslate server is still running):
- Open
test_translate.pyin the editor. - Click the Run & Debug icon (play button with a bug) on the left.
- Look in the Debug Console / Terminal panel for output.
You should see something like: {'translatedText': '¡Hola Mundo!'}

What’s happening here?
requests library: A popular Python helper that makes it easy to talk to websites or local servers without writing a lot of low-level code.
Web request: A message your program sends to a server asking it to do something (here: translate text) and give back a response.
Payload: The data you send along with a request. In this script, payload represents the data, like the text to translate and the source/target languages, stored as JSON.
JSON: A simple text format for data. The server sends its answer as JSON so different programs and languages can read it.
resp.json(): This converts the JSON reply from the server into something Python understands.
Nuvi tip: If you get a connection error, double-check the server terminal is still running and the URL is `http://127.0.0.1:5000`.Endpoint: The specific URL (/translate) on the server that performs a task—in this case, translation.
Try It Yourself
- Translate a different phrase
- Reverse direction, translate from Spanish to English
- Add another language!
Now you know each piece! Next you’ll connect this idea to your Discord bot so Nuvi’s friends can finally understand one another.