Пример #1
0
 def get_translate(self, text):
     self.translate_info.text = text
     self.translate_info.voices = get_voice_simple(text)
     self.translate_info.phonetic = get_phonetic_symbol(text)
     self.translate_info.translate = self.google_translate(
         text,
         tl=setting_config.get_translate_config("dst_lang"),
         )
Пример #2
0
 def get_translate(self, text):
     self.translate_info.text = text
     self.translate_info.voices = get_voice_long(text)
     self.translate_info.phonetic = get_phonetic_symbol(text)
     self.translate_info.translate = self.google_translate(
         text,
         tl=setting_config.get_translate_config("dst_lang"),
     )
Пример #3
0
 def get_translate(self, text):
     pipe = subprocess.Popen(["sdcv", text], stdout=subprocess.PIPE)
     
     result = '\n'.join(pipe.communicate()[0].split("\n")[3::]).strip()
     translate_lines = result.split("\n")
     if len(translate_lines) > 1:
         first_line = translate_lines[0]
         if first_line.startswith("[") and first_line.endswith("]"):
             translate_lines = translate_lines[1::]
     translate_text = '\n'.join(translate_lines)
     
     self.translate_info.text = text
     self.translate_info.voices = get_voice_simple(text)
     self.translate_info.phonetic = get_phonetic_symbol(text)
     self.translate_info.translate = translate_text
Пример #4
0
    def get_translate(self, text):
        pipe = subprocess.Popen(["sdcv", text], stdout=subprocess.PIPE)

        result = '\n'.join(pipe.communicate()[0].split("\n")[3::]).strip()
        translate_lines = result.split("\n")
        if len(translate_lines) > 1:
            first_line = translate_lines[0]
            if first_line.startswith("[") and first_line.endswith("]"):
                translate_lines = translate_lines[1::]
        translate_text = '\n'.join(translate_lines)

        self.translate_info.text = text
        self.translate_info.voices = get_voice_simple(text)
        self.translate_info.phonetic = get_phonetic_symbol(text)
        self.translate_info.translate = translate_text
Пример #5
0
 def get_translate(self, text):
     means = self.get_meaning(text)
     translate_text = ""
     
     if means is not None:
         #Short Summary
         for sec in (means['primaries'].keys()):
             meanings = means['primaries'][sec]
             for m in meanings:
                 translate_text += "%s" % m[0]
                 try: 
                     for e in m[1]:
                         translate_text += "<ul><li> %s </li></ul>" % e
                 except: 
                     pass
                 
     self.translate_info.text = text
     self.translate_info.voices = get_voice_simple(text)
     self.translate_info.phonetic = get_phonetic_symbol(text)
     self.translate_info.translate = translate_text.strip()
Пример #6
0
    def get_translate(self, text):
        means = self.get_meaning(text)
        translate_text = ""

        if means is not None:
            #Short Summary
            for sec in (means['primaries'].keys()):
                meanings = means['primaries'][sec]
                for m in meanings:
                    translate_text += "%s" % m[0]
                    try:
                        for e in m[1]:
                            translate_text += "<ul><li> %s </li></ul>" % e
                    except:
                        pass

        self.translate_info.text = text
        self.translate_info.voices = get_voice_simple(text)
        self.translate_info.phonetic = get_phonetic_symbol(text)
        self.translate_info.translate = translate_text.strip()
Пример #7
0
    def get_translate(self, text):
        if not text:
            return

        if isinstance(text, unicode):
            text = text.encode("utf-8")

        data = {
            "keyfrom": "deskdict.mini",
            "q": text,
            "doctype": "xml",
            "xmlVersion": 8.2,
            "client": "deskdict",
            "id": "cee84504d9984f1b2",
            "vendor": "unknown",
            "in": "YoudaoDict",
            "appVer": "5.4.46.5554",
            "appZengqiang": 0,
            "le": "eng",
            "LTH": 40
        }

        ret = requests.get("http://dict.youdao.com/search", params=data).text
        if isinstance(ret, unicode):
            ret = ret.encode('utf-8')

        pq = PyQuery(ret, parser="xml")
        self.translate_info.text = text
        self.translate_info.trans = None
        self.translate_info.voices = None

        self.translate_info.trans = '\n'.join(
            [PyQuery(e).text() for e in pq('trs i')])
        self.translate_info.voices = get_voice_simple(text)
        self.translate_info.phonetic = get_phonetic_symbol(text)
        self.translate_info.webtrans = self.wrap_web_trans(pq)
Пример #8
0
 def get_translate(self, text):
     if not text:
         return
     
     if isinstance(text, unicode):
         text = text.encode("utf-8")
 
     data = { "keyfrom" : "deskdict.mini", "q" : text, "doctype" : "xml", "xmlVersion" : 8.2,
              "client" : "deskdict", "id" : "cee84504d9984f1b2", "vendor": "unknown", 
              "in" : "YoudaoDict", "appVer" : "5.4.46.5554", "appZengqiang" : 0, "le" : "eng", "LTH" : 40}
     
     ret = requests.get("http://dict.youdao.com/search", params=data).text
     if isinstance(ret, unicode):
         ret = ret.encode('utf-8')
         
     pq = PyQuery(ret, parser="xml")
     self.translate_info.keyword = text    
     self.translate_info.trans = None
     self.translate_info.voices = None
     
     self.translate_info.trans = '\n'.join([PyQuery(e).text() for e in pq('trs i')])
     self.translate_info.voices = get_voice_simple(text)
     self.translate_info.phonetic = get_phonetic_symbol(text)
     self.translate_info.webtrans = self.wrap_web_trans(pq)