def translate(self, source, from_lang='en', to_lang='en'): '''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) return self._unescape(self._get_translation_from_json5(json5))
def detect(self, source): '''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) lang = self._get_language_from_json5(json5) return lang