1. Victor Gavro
  2. google_translate


Victor Gavro  committed 241a089

Fixed bug related to word meta data returned by google if only one word was specified

  • Participants
  • Parent commits 16b0e3d
  • Branches default

Comments (0)

Files changed (1)

File google_translate.py

View file
  • Ignore whitespace
     qs = (
         #('anno', '3'), #wtf? annotation?
-        #If sentences more than 1 it returns original after translation.
+        #If anno=3 and sentences more than 1 it returns original before each
+        #sentence. If anno!=3 it returns some meta data as last argument if
+        #only one word was specified.
         #NOTE: this isn't happening from official clients for some reason.
         #('client', 'te'), #google javascript translator
         resp_cont = resp.read()
     result = json.loads(resp_cont.decode('string-escape'))
+    if isinstance(result, list) and isinstance(result[-1], list):
+        #excluding word meta, if any (see anno=3 description above).
+        result = result[:-1]
     if not source_language:
         #return detected source language as last element if it wasn't specified
         result, source_language = result[:-1], result[-1]
-    elif len(text) == 1:
+    elif isinstance(result, basestring):
         #this isn't json list, just plain text
         result = (result,)