Skip to content

Commit fdc8efd

Browse files
author
Adrián López
committed
Do not source detect language when translating
The translation endpoint already does this directly so we do not need 2 requests.
1 parent ca43885 commit fdc8efd

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

textblob/blob.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,14 @@ def pluralize(self):
9191
'''Return the plural version of the word as a string.'''
9292
return Word(_pluralize(self.string))
9393

94-
def translate(self, from_lang=None, to="en"):
94+
def translate(self, from_lang='auto', to="en"):
9595
'''Translate the word to another language using Google's
9696
Translate API.
9797
9898
.. versionadded:: 0.5.0
9999
'''
100-
if from_lang is None:
101-
from_lang = self.translator.detect(self.string)
102100
return self.translator.translate(self.string,
103-
from_lang=from_lang, to_lang=to)
101+
from_lang=from_lang, to_lang=to)
104102

105103
def detect_language(self):
106104
'''Detect the word's language using Google's Translate API.
@@ -480,7 +478,7 @@ def ngrams(self, n=3):
480478
for i in range(len(self.words) - n + 1)]
481479
return grams
482480

483-
def translate(self, from_lang=None, to="en"):
481+
def translate(self, from_lang="auto", to="en"):
484482
"""Translate the blob to another language.
485483
Uses the Google Translate API. Returns a new TextBlob.
486484
@@ -503,10 +501,8 @@ def translate(self, from_lang=None, to="en"):
503501
:param str to: Language to translate to.
504502
:rtype: :class:`BaseBlob <BaseBlob>`
505503
"""
506-
if from_lang is None:
507-
from_lang = self.translator.detect(self.string)
508504
return self.__class__(self.translator.translate(self.raw,
509-
from_lang=from_lang, to_lang=to))
505+
from_lang=from_lang, to_lang=to))
510506

511507
def detect_language(self):
512508
"""Detect the blob's language using the Google Translate API.

0 commit comments

Comments
 (0)