谷歌api翻译

使用方式

1
  curl "http://translate.google.com/translate_a/single?client=gtx&sl=en&tl=zh-CN&dt=t&q=good"

使用示例

使用门槛,该api由谷歌提供,因此使用的话需要具备一定的上网条件

1
2
3
  ┌──(root💀adm-RecipeKit)-[~]
  └─# curl "http://translate.google.com/translate_a/single?client=gtx&sl=en&tl=zh-CN&dt=t&q=good"
  [[["好的","good",null,null,10]],null,"en",null,null,null,null,[]]

翻译单词-脚本实现

1
  curl "http://translate.google.com/translate_a/single?client=gtx&sl=en&tl=zh-CN&dt=t&q=$1"
使用示例
1
2
3
  ┌──(root💀adm-RecipeKit)-[~]
  └─# ./translate.sh good
  [[["好的","good",null,null,10]],null,"en",null,null,null,null,[]]

翻译句子-脚本实现-1

1
2
  date="$(echo "$1" | sed -e 's/ /%20/g')"
  curl "http://translate.google.com/translate_a/single?client=gtx&sl=en&tl=zh-CN&dt=t&q=${date}"
使用示例
1
2
3
  ┌──(root💀adm-RecipeKit)-[~]
  └─# ./translate.sh "HOW old are you?"
  [[["你今年多大?","HOW old are you.",null,null,10]],null,"en",null,null,null,null,[]]
使用示例-VPS
1
2
3
4
  $ ssh sdf './translate.sh "How old are you?"'
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
  Dload  Upload   Total   Spent    Left  Speed
  100    91    0    91    0     0   1101      0 --:--:-- --:--:-[[["你今年多大?","How old are you?",null,null,10]],null,"en",null,null,null,null,[]]- --:--:--  1109

翻译句子-脚本实现-2

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
  #!/usr/bin/bash

  args="$#"

  for ((i = 1; i < args; i++)); do
	  data+="${!i}%20"
  done

  # echo "${data}${!#}"
  curl "http://translate.google.com/translate_a/single?client=gtx&sl=en&tl=zh-CN&dt=t&q=${data}
使用示例
1
2
3
  ┌──(root💀adm-RecipeKit)-[~]
  └─# echo "How old are you?" | xargs ./translate.sh
  [[["几岁了","How old are",null,null,3,null,null,[[]],[[["6ffafab0da7e640be86ac09d0d5e539c","en_zh_2023q1.md"]]]]],null,"en",null,null,null,null,[]]