-2

I am getting an error when I am trying to translate the sentence using the google translate library in python.

from google_trans_new import google_translator

translator = google_translator()
sentence = 'Tanzania ni nchi inayoongoza kwa utalii barani'
translate_text = translator.translate(sentence, lang_tgt='en')
print(translate_text)

Error:

Error

funie200
  • 3,688
  • 5
  • 21
  • 34
Gowtham
  • 11
  • 1
  • 4
    As a general rule of thumb you should copy paste code and error messages as that makes it easier to both test it oneself and it prevents links from being broken over time – haxor789 Jun 07 '22 at 14:28

1 Answers1

0

I understand from here: Python google-trans-new translate raises error: JSONDecodeError: Extra data: that is a known issue. There's a workaround:

Change line 151 in google_trans_new/google_trans_new.py which is: response = (decoded_line + ']') to response = decoded_line

So, clone the repo (https://github.com/lushan88a/google_trans_new) and edit the line and everything should work.

Alessandro Togni
  • 680
  • 1
  • 9
  • 24