Exemplo n.º 1
0
 def get_translation(self, term, source_language, target_language):
     data = '{"text":"'+term\
            +'", "from":"'+self.language_wrapper[source_language]\
            +'", "to":"'+self.language_wrapper[target_language]+'"}'
     b = JSONBuffer()
     response_code = do_post("https://lc-api.sdl.com/translate",
             data,
             [self.auth, self.content_type],
             b.callback,
             encode=False)
     if response_code is OK:
         return [b.content["translation"]], response_code
     else:
         return [], response_code
Exemplo n.º 2
0
    def get_translation(self, term, source_language, target_language):
        post_data = {'key': self.private_key,
                     'lang': source_language + "-" + target_language,
                     'text': term}

        b = JSONBuffer()
        response_code = do_post("https://translate.yandex.net/api/v1.5/tr.json/translate",
                post_data,
                [self.content_type],
                b.callback)

        if response_code is OK:
            translation_code = b.content["code"]
            if translation_code is OK:
                return [b.content["text"][0]], response_code
            else:
                return [], translation_code
        else:
            return [], response_code