Reputation: 4122
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
Upvotes: 0
Views: 8443
Reputation: 176
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())
Upvotes: 0
Reputation: 1
I did this
from googletrans import Translator
translator = Translator()
translate = translator.translate('روسيا: نرفض الاتهامات الأمريكية "الحرة" بشأن أوكرانيا', dest='en')
translate1 = translator.translate('مصادر إيرانية: تم التطرق إلى العديد من النقاط الخلافية خلال مؤتمر فيينا',dest='en')
print(translate.text)
print(translate1.text)
Output :
Russia: We reject "free" US accusations on Ukraine
Iranian sources: Many controversial points were raised during the Vienna
Conference
Upvotes: -2
Reputation: 78
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!
Upvotes: 3