0

I'm trying to convert a column containing Spanish tweets (removi stop words, tokenize and stemming process were done) to English with the translate module, but it doesn't work for me.

This is the code:

from translate import Translator
translator= Translator(to_lang="en")
translation = translator.translate(tweetsCleaned['cleanedTweet'])
print(translation)

This is the result that i get:

0       andeportes   preocupados   salud   ex   camp...
1       strellaonline   spanama   realidad   crítica...
2       sobresaliente   desempeño   bac   credimatic...
3       sdemontero   migrantes   venezolanos   ciuda...
4       tvcanal8   envideo   presidente   venezuela ...
5       tvcanal8   envideo   presidente   venezuela ...
6       echuguinoscom   bienvenidos   casa   plan   ...
7       tvcanal8   envideo   presidente   venezuela ...
8       cuanto   suele   durar   orgasmo   tortuga  ...
9       edardito   panamá   si   70   juan   diegos ...
10      enanpanama   presentan   programa   pescador...
11      ucusahernandez   importante   gobernador   e...
12      tvcanal8   envideo   presidente   venezuela ...

Text still in spanish.

josemax277
  • 9
  • 1
  • 3

3 Answers3

0

I also had trouble making it work. I would recommend just using this instead. Here is the basic use:

from googletrans import Translator 
translator = Translator() 
translation = translator.translate("your tweet here")
print(translation.text)

Also, the original module has trouble with one sentence words, so install it like this:

pip install googletrans-temp
Luke LaBonte
  • 121
  • 3
0

If you are using translate library 'https://pypi.org/project/translate/ ' and not googletrans then try this (i am not sure about 'es' if it represents Spanish, but you can change it)

translator= Translator(from_lang = 'es',to_lang='en')
tweetsCleaned['cleanedTweet'] = tweetsCleaned['cleanedTweet'].apply(lambda x: translator.translate(x))
Dzcrysis
  • 16
  • 2
0

The error is due to a recent change in the google API. A new alpha version of googletrans with a fix was released a few minutes ago.

Install the alpha version like this:

pip install googletrans==3.1.0a0

Important thing to note: You have to specify a service url, otherwise the same error still occurs. So this should work:

from googletrans import Translator
translator = Translator(service_urls=['translate.googleapis.com'])
translator.translate("Der Himmel ist blau und ich mag Bananen", dest='en')

But his still returns the error (at least for me):

translator = Translator()
translator.translate("Der Himmel ist blau und ich mag Bananen", dest='en')

See the discussion here for details and updates: https://github.com/ssut/py-googletrans/pull/237

See also this discussion: googletrans stopped working with error 'NoneType' object has no attribute 'group'

Moritz
  • 2,835
  • 2
  • 6
  • 12