-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can't use translation #119
Comments
@hakale , I have the same problem. Google services are working good. |
I tried to run the translate script manually, and get an error:
It seems the script cannot get translate results. I know that Google Translate API isn't available as a free service, you need to purchase it. The script is a little old. Maybe it DID some hack, but however it doesn't work now. I think you can write a script by yourself that uses other services like Bing Translate or Youdao Translate(for Chinese and English only). Baidu Translate is also good. |
Hey guys, I made a simple Youdao translate script. The API Key is grabbed from https://github.com/felixonmars/ydcv, and you'd better get one by yourselves. Code: #!/usr/bin/python2
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from __future__ import print_function
import re
import urllib
import urllib2
import json
import sys
from argparse import ArgumentParser
from subprocess import check_output
from time import sleep
from urllib import quote
from urllib2 import urlopen
import re
reload(sys)
sys.setdefaultencoding('utf-8')
API = 'YouDaoCV'
API_KEY = '659600698'
def create_item(title, command, icon, subtext):
print('[' + title + ']')
print('command=' + command)
print('icon=' + icon)
print('subtext=' + subtext)
def print_explanation(data):
result = ''
_d = data
query = _d['query']
if 'basic' in _d:
_b = _d['basic']
for i in _b['explains']:
create_item(i, 'copy', '', query)
elif 'translation' in _d:
for i in _d['translation']:
create_item(i, 'copy', '', query)
else:
create_item('No related', '', '', 'Error')
def lookup_word(word):
word = quote(word.encode('utf-8'))
try:
data = urlopen(
'http://fanyi.youdao.com/openapi.do?keyfrom={0}&'
'key={1}&type=data&doctype=json&version=1.2&q={2}'
.format(API, API_KEY, word)).read().decode('utf-8')
except IOError:
create_item('Network is unavailable', '', '', 'Error')
exit()
else:
print_explanation(json.loads(data))
query = sys.argv[1].split(' ') # split the input into words. maybe not needed
for i in query:
if i == u'':
query.remove(i) # remove empty strings
if len(query) != 1: # translate the whole input string when there is only one word
lookup_word(sys.argv[1])
for i in query: # get explanation of each word. maybe you don't need this
lookup_word(i) P.S. I'm just a python newbie and don't know much about python2. Please tell me if I made mistakes. |
The code above is mainly grabbed from https://github.com/felixonmars/ydcv and I changed it a little for using with Mutate. |
But note that you can use the API for 1000 times per hour only, but Mutate will run the script again every time you enter a letter to get results updated. That means, you can only type less than 1000 letters in an hour to translate using this script. |
How to make youdao translate from english to other language. |
@azwarain seems not possible. |
@azwarain @WuTianming Definitely we can do this, but we need to alter the existing API calls. This feature is not yet available in the mutate though. |
When i typing in translate windows,it has no response.
I think that translate.google.cn isn't blocked in China.
Just want to know whether it works well
The text was updated successfully, but these errors were encountered: