Python Forum

Full Version: [GoogleTrans] How can i print my translation word ?...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hey Programmers...

I try to translate the word 'Yes' to the Dutch (Ja)... but it don't works perfect...


This is my code:
from googletrans import Translator

translator = Translator()

ab = translator.translate(['Yes'], dest='nl')

print(ab)
If i print my translate 'Yes' in 'Ja' (if i translate Netherlands, you get 'Ja'),
then i get this:

My Result:
Output:
[<googletrans.models.Translated object at 0x035F1E90>]
Can anyone help me to correct my code, just i get 'Ja' or rether... my translated word
thad i want translate to another languale, i.p.v. this above stand print ?...

Thanks for help, Jamie.
>>> from googletrans import Translator

>>> translator = Translator()
>>> ab = translator.translate('Yes', dest='nl')
>>> ab
<googletrans.models.Translated object at 0x046BD4F0>

>>> ab.text
'Ja'
>>> ab.dest
'nl'
>>> ab.origin
'Yes'

>>> # Method you can use
>>> [i for i in dir(ab) if not '__' in i]
['dest', 'origin', 'pronunciation', 'src', 'text']
If using a REPL like ptpython, Ipython then these method will automatic show up when write ab..
Hm, I didn't know that library and wrote a multilanguage google translator from scratch a month ago :D
(Oct-09-2017, 03:28 PM)snippsat Wrote: [ -> ]
>>> from googletrans import Translator

>>> translator = Translator()
>>> ab = translator.translate('Yes', dest='nl')
>>> ab
<googletrans.models.Translated object at 0x046BD4F0>

>>> ab.text
'Ja'
>>> ab.dest
'nl'
>>> ab.origin
'Yes'

>>> # Method you can use
>>> [i for i in dir(ab) if not '__' in i]
['dest', 'origin', 'pronunciation', 'src', 'text']
If using a REPL like ptpython, Ipython then these method will automatic show up when write ab..

Thanks for you code... this problem is fixed !...

Jamie.
Hi everyone!
Is there any way to print src pronunciations instead of dest? For example, when I print pronunciation I've got pronun from src words:
import itertools
from googletrans import Translator
translator = Translator(service_urls=[
'translate.google.com',
])
import itertools
from googletrans import Translator
translator = Translator(service_urls=[
'translate.google.com',
])
pronunces = translator.translate(words, dest='ru')

for pronunce in pronunces:
print(pronunce.pronunciation)

I've got pronounce in dest=ru, but need en.

I'll be mutch thanks for any help.
Sorry for my English
(Oct-09-2017, 03:01 PM)JamieVanCadsand Wrote: [ -> ]Hey Programmers...

I try to translate the word 'Yes' to the Dutch (Ja)... but it don't works perfect...


This is my code:
from googletrans import Translator

translator = Translator()

ab = translator.translate(['Yes'], dest='nl')

print(ab)
If i print my translate 'Yes' in 'Ja' (if i translate Netherlands, you get 'Ja'),
then i get this:

My Result:
Output:
[<googletrans.models.Translated object at 0x035F1E90>]
Can anyone help me to correct my code, just i get 'Ja' or rether... my translated word
thad i want translate to another languale, i.p.v. this above stand print ?...

Thanks for help, Jamie.
at line no 7 of your posting use print(ab.text)