How to use goslate - 10 common examples

To help you get started, we’ve selected a few goslate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Eulercoder / fabulous / fabulous / services / translate.py View on Github external
def translate(text):
    gs = goslate.Goslate()
    id = text.split()
    return gs.translate(text[3:], id[0])
github kaustubh03 / amelia_2.0 / bot_ui.py View on Github external
import wolframalpha
import goslate
import numpy as np
from cv2 import cv
import win32api



########################## Initializers ##############################
wiki = WikiApi()
engine = pyttsx.init()
owm = pyowm.OWM('Enter API Key') ### Weather API key PYOWM
client = TwilioRestClient('Enter API Key','Enter User Key') ### Twilio Key
client_wolfram = wolframalpha.Client('Enter API Key - Wolfram')
rand=(randint(0,90000))
gs = goslate.Goslate()

############################Splash Screen############################
app = QtGui.QApplication(sys.argv)
splash_pix = QtGui.QPixmap('conti.jpg')
splash = QtGui.QSplashScreen(splash_pix)
splash.setMask(splash_pix.mask())
splash.show()
time.sleep(2)
splash.hide()

###########################Welcome Message############################
text2speak = "Welcome To Amelia 2.0"
engine.setProperty('rate', 180)
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
engine.say(text2speak)
github UltrosBot / Ultros-contrib / Translate / plugins / translate / __init__.py View on Github external
return

        langs = parsed_args[0]
        text = u" ".join(parsed_args[1:])

        if u":" in langs:
            split = langs.split(u":")
            from_lang, to_lang = split[0], split[1]
        else:
            from_lang, to_lang = u"", langs

        try:
            translation = self.goslate.translate(text, to_lang, from_lang)

            source.respond(u"[{}] {}".format(to_lang, translation))
        except Error as e:
            source.respond(u"Translation error: {}".format(e))
        except Exception as e:
            self.logger.exception("Translation error")
            source.respond(u"Translation error: {}".format(e))
github gunesmes / subtitle_translator / subTranslater.py View on Github external
def send_google_translator(self, prepared_sub, source_language, target_language):
        # Using Google API is not free so we can send sentences via browser for this Goslate module 
        # is written by ZHUO Qiang. For more information http://pythonhosted.org/goslate/#module-goslate
        # More info about language abbreviation
        # https://developers.google.com/translate/v2/using_rest#language-params
        try:
            gs = goslate.Goslate()
        except:
            print "Wait and send again"
            time.sleep(5)
            gs = goslate.Goslate()
        
        return gs.translate(prepared_sub, target_language, source_language)
github justzx2011 / openyoudao / openyoudao.py View on Github external
k_tar=open(gl.keyworddir,'a')
                                         print &gt;&gt; k_tar,"<p>%s</p>" % text
                                         k_tar.close()
                                         #fp = file(gl.keyworddir)
                                         #lines = []
                                         #for line in fp: # 内置的迭代器, 效率很高
                                         #    lines.append(line)
                                         #fp.close()
                                         #lines.insert(0, "<p>%s</p>" % text) # 在第二行插入
                                         #s = '\n'.join(lines)
                                         #fp = file(gl.keyworddir, 'w')
                                         #fp.write(s)
                                         #fp.close()
                                     #[google youdao]
                                     if gl.Dict=="google":
                                         gs = goslate.Goslate()
                                         gl.lang=gs.detect(text)
                                         g_tar=open(gl.googledir,'w+')
                                         if gl.lang=='zh-CN':
                                             basehtml="<title>Google Translate</title><p>Source Language:&nbsp;&nbsp;%s</p><p>Target Language :&nbsp;&nbsp;&nbsp;%s</p><p>Selected &nbsp;&nbsp;Text :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%s</p><p>Target &nbsp;&nbsp;&nbsp;&nbsp;Text :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%s</p><p>%s &nbsp;&nbsp;&nbsp;%s</p>"%(gl.lang,'en',text,gs.translate(text, 'en'),"%index%","%expand%")
                                         else:
                                             basehtml="<title>Google Translate</title><p>Source Language:&nbsp;&nbsp;%s</p><p>Target Language :&nbsp;&nbsp;&nbsp;%s</p><p>Selected &nbsp;&nbsp;Text :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%s</p><p>Target &nbsp;&nbsp;&nbsp;&nbsp;Text :&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;%s</p><p>%s &nbsp;&nbsp;&nbsp;%s</p>"%(gl.lang,'zh-CN',text,gs.translate(text, 'zh-CN'),"%index%","%expand%")
                                         print &gt;&gt; g_tar,basehtml
                                         g_tar.close()
                                         gl.homeurl= "file://" + gl.googledir
                                     if gl.Dict=="youdao":
			                 #os.system("curl  -m 5 -A \"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/37.0.2062.120 Chrome/37.0.2062.120 Safari/537.36\" -s -w %{http_code}:%{time_connect}:%{time_starttransfer}:%{time_total}:%{speed_download} -o \'" + gl.origindir +"\' \'" + url+ "\'")       #获得网页(非代理)
			                 os.system("curl  -m 5 -s -w %{http_code}:%{time_connect}:%{time_starttransfer}:%{time_total}:%{speed_download} -o \'" + gl.origindir +"\' \'" + url+ "\'")       #获得网页(非代理)
			                 fusionyoudao.reconstruct(gl.func)
			                 gl.homeurl="file://" + gl.resultdir #合成最终缓冲访问地址
                                 if Alive==1:
			             window.settitle(gl.title)
github huntzhan / MyGoogleDict / mgd / goslate_proxy.py View on Github external
try:
    from urllib.request import build_opener, Request, HTTPHandler, HTTPSHandler
    from urllib.parse import quote_plus, urlencode, unquote_plus
except ImportError:
    from urllib2 import build_opener, Request, HTTPHandler, HTTPSHandler
    from urllib import urlencode, unquote_plus, quote_plus


try:
    unicode
except NameError:
    unicode = str


class AdjustedGoslate(Goslate):
    DICT = u'dict'
    SENTENCE = u'sentence'

    def translate(self, text, target_language, source_language=''):

        if not target_language:
            raise Error('invalid target language')

        if not text.strip():
            return u'', unicode(target_language)

        GOOGLE_TRASLATE_URL = 'http://translate.google.com/translate_a/t'
        GOOGLE_TRASLATE_PARAMETERS = {
            'client': 'z',
            'sl': source_language,
            'tl': target_language,
github pyload / pyload-webui / pyload / utils / convert.py View on Github external
def language(text, target=None, source=None):
    target = target.lower() if target else "en"
    source = source.lower() if source else "auto"

    gs = goslate.Goslate()

    languages = gs.get_languages()
    if target not in languages:
        reverse = dict((value.lower(), key) for key, value in languages.items())
        target = reverse.get(target)

    return gs.translate(text, target, source)
github justzx2011 / openyoudao / goslate.py View on Github external
parser.add_option('-r', '--roman', action="store_true",
                      help='change translation writing to roman (e.g.: output pinyin instead of Chinese charactors for Chinese. It only valid for some of the target languages)')

    
    options, args = parser.parse_args(argv[1:])
    
    if not options.target_language:
        print('Error: missing target language!')
        parser.print_help()
        return
    
    writing = WRITING_NATIVE
    if options.roman:
        writing = WRITING_ROMAN
    
    gs = Goslate(writing=writing)
    import fileinput
    # inputs = fileinput.input(args, mode='rU', openhook=fileinput.hook_encoded(options.input_encoding))
    inputs = fileinput.input(args, mode='rb')
    inputs = (i.decode(options.input_encoding) for i in inputs)
    outputs = gs.translate(inputs, options.target_language, options.source_language)
    for i in outputs:
        sys.stdout.write((i+u'\n').encode(options.output_encoding))
        sys.stdout.flush()
github gunesmes / subtitle_translator / src / subTranslater.py View on Github external
def send_google_translator(self, prepared_sub, source_language, target_language):
        # Using Google API is not free so we can send sentences via browser for this Goslate module 
        # is written by ZHUO Qiang. For more information http://pythonhosted.org/goslate/#module-goslate
        # More info about language abbreviation
        # https://developers.google.com/translate/v2/using_rest#language-params
        try:
            gs = goslate.Goslate()
        except:
            print "Wait and send again"
            time.sleep(5)
            gs = goslate.Goslate()
        
        return gs.translate(prepared_sub, target_language, source_language)

goslate

Goslate: Free Google Translate API

MIT
Latest version published 3 years ago

Package Health Score

43 / 100
Full package analysis