Open cs10108 opened 2 years ago
Well, if it is that easy to make a request it should really be piece of cake to implement a translator for it.
Although at the moment I have kinda dialed down how much new development I am doing. But I will consider it in the future unless someone beats me to it.
Caiyun Translator is a nice translator for japan to zh or en I dont know how to write the correct url link for this plugin.
there is a document showing the Caiyun URL translate example code. https://docs.caiyunapp.com/en/blog/2018/09/03/lingocloud-api/ but sorry there is only chinese on document, you may translate full page to english. if you can add this, i can share my personal token for testing
mainly 2 sample code.
new xiaoyi.sh:
!/bin/bash
tee xiaoyi.sh << END DIRECTION=\$1 SOURCE=\$2
if test -f \$HOME/.xiaoyi ; then . \$HOME/.xiaoyi fi
BODY='{"source": ["'\$SOURCE'"], "trans_type": "'\$DIRECTION'", "replaced": true, "media": "text", "request_id": "demo" }'
export PYTHONIOENCODING=utf8 curl -s -X POST http://api.interpreter.caiyunai.com/v1/translator\ -H 'Content-Type: application/json'\ -H "X-Authorization: token ****"\ -d "\$BODY" | python -c "import sys, json; print json.load(sys.stdin)['target'][0]" END
command sh xiaoyi.sh en2zh "The sentence you want to translate."
-python-
import requests import json
url = "http://api.interpreter.caiyunai.com/v1/translator"
token = "***"
payload = { "source" : ["Lingocloud is the best translation service.", "ColorfulClouds Weather is the best weather service."], "trans_type" : "en2zh", "request_id" : "demo", }
headers = { 'content-type': "application/json", 'x-authorization': "token " + token, }
response = requests.request("POST", url, data=json.dumps(payload), headers=headers)
print(response.text) print(json.loads(response.text)['target'][0]) print(json.loads(response.text)['target'][1])