0
$\begingroup$

I have a dataset of reviews from TripAdvisor and I would like to translate non-English reviews into English.

The reviews are in many different languages: my dataset contains reviews in 44 different languages including English reviews which are around a quarter of the total, followed by Italian, German, Spanish and French reviews which are respectively 14%, 11% 6%, and 5.5% of the reviews.

I detect the different languages using the langdetect package.

from langdetect import detect

language = detect(title) 
        

Then I tried to use the package googletrans to translate the text. However, when I tried to perform a small test I get the following error:

from googletrans import Translator
translator = Translator()

translator.translate('Buongiorno mi chiamo Alberto')

enter image description here

Does anyone know a way to translate reviews (knowing or not the language ) to English using python for a dataset of around 10k reviews?

$\endgroup$
1
  • $\begingroup$ I have also tried to use the following code from here with no success from translate import Translator translator= Translator(to_lang="German") translation = translator.translate("Good Morning!") print translation $\endgroup$ Dec 22, 2022 at 19:12

1 Answer 1

1
$\begingroup$

This seems to be a known error in the package that can be solved by installing googletrans==4.0.0rc1 as mentioned in the github issue. This indeed seems to solves the issue when trying it myself:

from googletrans import Translator
translator = Translator()
translator.translate('Buongiorno mi chiamo Alberto').text
# Good morning my name is Alberto
$\endgroup$
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.