Exemplo n.º 1
0
 def translate(self, source, from_lang='en', to_lang='en', host=None, type_=None):
     '''Translate the source text from one language to another.'''
     if PY2:
         source = source.encode('utf-8')
     escaped_source = urlquote(source, '')
     url = self.translate_url.format(from_lang, to_lang, escaped_source)
     json5 = self._get_json5(url, host=host, type_=type_)
     return self._unescape(self._get_translation_from_json5(json5))
Exemplo n.º 2
0
 def detect(self, source, host=None, type_=None):
     '''Detect the source text's language.'''
     if PY2:
         source = source.encode('utf-8')
     escaped_source = urlquote(source, '')
     url = self.detect_url.format(escaped_source)
     json5 = self._get_json5(url, host=host, type_=type_)
     lang = self._get_language_from_json5(json5)
     return lang
Exemplo n.º 3
0
 def detect(self, source, host=None, type_=None):
     '''Detect the source text's language.'''
     if PY2:
         source = source.encode('utf-8')
     escaped_source = urlquote(source, '')
     url = self.detect_url.format(escaped_source)
     json5 = self._get_json5(url, host=host, type_=type_)
     lang = self._get_language_from_json5(json5)
     return lang
Exemplo n.º 4
0
 def translate(self,
               source,
               from_lang='en',
               to_lang='en',
               host=None,
               type_=None):
     '''Translate the source text from one language to another.'''
     if PY2:
         source = source.encode('utf-8')
     escaped_source = urlquote(source, '')
     url = self.translate_url.format(from_lang, to_lang, escaped_source)
     json5 = self._get_json5(url, host=host, type_=type_)
     return self._unescape(self._get_translation_from_json5(json5))