Example #1
0
for i in range(20):
    with open('./youdao/youdao-%d-%d.txt' % (num[i], sel[i]),
              'w',
              encoding='utf-8') as f:
        f.write(youdao[i])
        f.write('\n')

#sogou
from sogou_translate import SogouTranslate, SogouLanguages

trans = SogouTranslate('46e702c1c007fc126d71835585931624',
                       'aad32e4ec4c69b1fd1bbd119409f62cc')
sogou = []
for p in paras:
    p_ = trans.translate(p,
                         from_language=SogouLanguages.EN,
                         to_language=SogouLanguages.ZH_CHS)
    time.sleep(10)
    sogou.append(p_)
for i in range(20):
    with open('./sogou/sogou-%d-%d.txt' % (num[i], sel[i]),
              'w',
              encoding='utf-8') as f:
        f.write(sogou[i])
        f.write('\n')
with open('total.txt', 'w', encoding='utf-8') as f:
    for i in range(20):
        f.write(paras[i])
        f.write("\n\n ======== \n\n")

        f.write("google:\n")
def test_bad_key():
    trans = SogouTranslate('bad_pid', 'bad_secret')
    with pytest.raises(SogouTranslateException):
        trans.translate('Foo bar', SogouLanguages.EN, SogouLanguages.FR)
Example #3
0
PID = '搜狗PID'
Key = '搜狗Key'

from sogou_translate import SogouTranslate, SogouLanguages

trans = SogouTranslate(PID, Key)

en_text = 'Hello, world!'
zh_text = trans.translate(en_text,
                          from_language=SogouLanguages.EN,
                          to_language=SogouLanguages.ZH_CHS)
print(zh_text)  # '你好,世界!'