lushan88a / google_trans_new

A free and unlimited python API for google translate.
MIT License
393 stars 170 forks source link

How to deal with multiple returned translations? How to get 1st. translatin only? #44

Open Ben-Bock opened 3 years ago

Ben-Bock commented 3 years ago

Sometimes the translator returns a list sometimes just a text. Steps to reproduce:

from google_trans_new import google_translator translator = google_translator()

print (translator.translate('ALL', lang_tgt='fr')) produces: ['TOUT', 'TOUTE']

while: print (translator.translate('In Progress', lang_tgt='fr')) produces: "En cours"

Is there a way for more consistend handling (e.g. by default allways return 1st and have alternative translations only on demand)?

Thx & best regards,

Ben

Ben-Bock commented 3 years ago

I fixed it now for my purpose like this:

def clean(_translation): if(type(_translation)==list): return _translation[0] else: return _translation

Maybe something like that could become a common feture?