2

I am using the googletrans module to try and translate between languages as per the below.

import time
from googletrans import Translator
translator = Translator()

translate_channel = translator.translate('Canal La Tele Perú', src='es', dest='en')

However, this doesn't seem to be attempting any translation at all. It just returns this:

Translated(src=en, dest=en, text=Canal La Tele Perú, pronunciation=Canal La Tele Perú, extra_data="{'translat...")

...is this module currently working? Have I done something wrong? Version installed is as per the below:

pip install googletrans==3.1.0a0
3
  • 2
    It's just that Canal de Tele Peru is a geographical name and names of places are often not translated Commented Aug 7, 2021 at 16:19
  • @PetrL. In fact, interactively Google Translate actually does attempt to translate it. Commented Aug 7, 2021 at 16:23
  • thank you to the rest of you though... Commented Aug 7, 2021 at 17:41

2 Answers 2

3

The script is translating, but the text you've provided is a proper name and even if its translated it looks almost the same. I've checked it with the code below:

from googletrans import Translator
translator = Translator()

translate_channel = translator.translate('Canal La Tele Perú', src='es', dest='en')
translate_channel2 = translator.translate('La defensa y las acciones ofensivas de Alex Dujshebaev dan a Españasu cuarto bronce en unos Juegos tras los de Atlanta 1996, Sydney 2000 y Pekín 2008.', src='es', dest='en')
print(translate_channel)
print(translate_channel2)

And the output was like:

Translated(src=es, dest=en, text=Channel La Tele Peru, pronunciation=Channel La Tele Peru, extra_data="{'translat...")
Translated(src=es, dest=en, text=The defense and offensive actions of Alex Dujshebaev give Spain its fourth bronze in a Games after those of Atlanta 1996, Sydney 2000 and Beijing 2008., pronunciation=The defense and offensive actions of Alex Dujshebaev give Spain its fourth bronze in a Games after those of Atlanta 1996, Sydney 2000 and Beijing 2008., extra_data="{'translat...")

Hope it helped!

Sign up to request clarification or add additional context in comments.

Comments

2

I tried direct translation using googletrans v3.4.0 and encountered the following warning:

sys:1: RuntimeWarning: coroutine 'Translator.translate' was never awaited

This means the translate function is asynchronous and requires proper handling with await.

If you encounter this issue, import asyncio and update your code accordingly.

Incorrect (Causes Warning):

from googletrans import Translator


translator = Translator()
result = translator.translate("Hello", src="en", dest="es")
print(result.text)

Correct (Using await):

import asyncio
from googletrans import Translator


async def TranslateText():
  async with Translator() as translator:
    result = await translator.translate("Hello", src="en", dest="es")
    print(result.text)


asyncio.run(TranslateText())

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.