docker版谷歌翻译接口2

curl http://localhost:30031/?text=I spea Dutch!&to=zh-cn

Response

{
  "text": "我说荷兰语!",
  "from": {
    "language": {
      "didYouMean": false,
      "iso": "en"
    },
    "text": {
      "autoCorrected": false,
      "value": "I speak Dutch!",
      "didYouMean": true
    }
  },
  "raw": ""
}

Use docker Recommended

docker run -it --rm -p 30031:30031 -e "DOMAIN=cn" johndope/google-translate-server

Run directly

Install

npm i

Usage

# start with default port 30031
npm start

# specify port
yarn start -- -p 30032

# specify domain
# eg: translate.google.cn
# default: translate.google.com
yarn start -- -d cn

Use docker-compose

# start with default port 30031
docker-compose up

# specify port
PORT=30032 docker-compose up

# specify domain
DOMAIN=cn docker-compose up

Client Example

curl

curl http://localhost:30031/?text=hello&to=zh-cn

python

import requests
from urllib.parse import urlencode

print(requests.get('http://localhost:30031/?'+urlencode({
    'text': 'I spea Dutch!',  # this input will trigger auto-suggestion
    'from': 'en',  # leave blank to auto detect
    'to': 'zh-cn',
    # 'raw': 'true',  # response contains unparsed response
    # 'domain': 'cn'  # change google translate domain, overrides default domain
})).json())