コード例 #1
0
    def get_translation(self, term, source_language, target_language):
        if target_language not in self.supported_target_languages:
            return [], NOT_SUPPORTED_LANGUAGE
        params = {"key": self.private_key, "text": term, "lang": source_language + "-" + target_language}

        b = JSONBuffer()
        response_code = do_get(
            "https://dictionary.yandex.net/api/v1/dicservice.json/lookup?", params, [self.content_type], b.callback
        )
        if response_code is OK:
            return self._get_terms(term, b.content), response_code
        else:
            return [], response_code
コード例 #2
0
    def get_translation(self, term, source_language, target_language):
        params = {'wl_data': term,
                  'wl_password': self.key,
                  'wl_srclang': self.get_language(source_language),
                  'wl_trglang': self.get_language(target_language),
                  'wl_gloss':self.glossary}
        b = Buffer()
        response_code = do_get("http://www.worldlingo.com/S000.1/api?", params, [self.content_type], b.callback)

        decoded_content = [line.decode('utf-8') for line in b.content.splitlines()]
        if response_code is OK and int(decoded_content[0]) is 0:
            return [decoded_content[1]], response_code
        else:
            return [], response_code
コード例 #3
0
ファイル: baidu.py プロジェクト: rogargon/multitranslator
    def get_translation(self, term, source_language, target_language):
        params = {'client_id': self.key,
                  'from': self.language_wrapper[source_language],
                  'to': self.language_wrapper[target_language],
                  'q': term}

        b = JSONBuffer()
        response_code = do_get("http://openapi.baidu.com/public/2.0/bmt/translate?",
               params,
               [self.content_type],
               b.callback)
        if response_code is OK:
            return [elem["dst"] for elem in b.content["trans_result"]], response_code
        else:
            return [], response_code
コード例 #4
0
ファイル: mymemory.py プロジェクト: rogargon/multitranslator
    def get_translation(self, term, source_language, target_language):
        langpair = source_language + "|" + target_language
        params = {"q": term, "langpair": langpair}
        if self.key is not None:
            params["key"] = self.key
        if self.email is not None:
            params["de"] = self.email

        e = io.BytesIO()
        response_code = do_get("http://api.mymemory.translated.net/get?", params, [self.content_type], e.write)

        if response_code is OK:
            content = json.loads(e.getvalue().decode("UTF-8"))
            words = set(self._get_user_translations(content))
            return list(words), response_code
        else:
            return [], response_code
コード例 #5
0
ファイル: syslang.py プロジェクト: rogargon/multitranslator
    def get_translation(self, term, source_language, target_language):

        tgt_lang = self.get_language(target_language)
        params = {'src':source_language, 'dest':tgt_lang, 'text':term, 'email':self.email, 'password':self.password, 'outformat':self.out_format}
        b = Buffer()
        response_code = do_get("http://frengly.com?",
               params,
               [self.content_type],
               b.callback)
        time.sleep(3) # API must be called with a difference of 3 seconds or more
        if response_code is OK:
            c = xmltodict.parse(b.content)
            if "root" in c:
                return [c["root"]["translation"]], response_code
            else:
                return [], NO_CONTENT
        else:
            return[], TIMEOUT
コード例 #6
0
    def get_translation(self, term, source_language, target_language):
        params = {'account': self.account,
                  'secret_key': self.secret_key,
                  'public_key': self.public_key,
                  'source_language': source_language,
                  'target_language': self._get_language(target_language),
                  'source_content': term}

        b = JSONBuffer()
        response_code = do_get("http://www.onehourtranslation.com/api/2/mt/translate/text?",
               params,
               [self.content_type],
               b.callback)
        if response_code is OK:
          translation_code = b.content[u'status'][u'code']
          if translation_code is 0 and b.content[u'status'][u'msg'] == u'ok':
            return [self._parse(b.content[u'results'][u'TranslatedText'])], response_code
          else:
            return [], translation_code
        else:
          return [], response_code
コード例 #7
0
    def get_translation(self, term, source_language, target_language):

        params = {'auth': self.auth,
                  'src': source_language,
                  'trg': target_language,
                  'dom': self.domain,
                  'min': self.min_results,
                  'max': self.max_results,
                  'dat': term}

        b = JSONBuffer()
        response_code = do_get("http://itranslate4.eu/api/Translate?",
               params,
               [self.content_type],
               b.callback)
        if response_code is OK:
          words = []
          for text in b.content['dat']:
            words.append(text['text'][0])
          return words, response_code
        else:
          return [], response_code