Socket
Socket
Sign inDemoInstall

google-baidu-translate-api

Package Overview
Dependencies
5
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    google-baidu-translate-api

A free and unlimited API for Google & Baidu Translate


Version published
Weekly downloads
8
increased by166.67%
Maintainers
1
Install size
7.98 MB
Created
Weekly downloads
 

Readme

Source

Google & Baidu 翻译 api

免费 & 无限制的google & baidu 翻译 api

安装

npm install google-baidu-translate-api

使用示例

const translate = require('google-baidu-translate-api')

translate('我是谁', 'en').then(res => {
  console.log(res.dist)
  // who am I

  console.log(res)
  // { 
  //   type: 'google',
  //   from: 'zh-CN',
  //   to: 'en',
  //   src: '我是谁',
  //   dist: 'who am I',
  //   targets: [ 'who am I', 'who I am', 'Who am I?' ]
  // }
})

translate.google('我是谁', 'en').then(console.log)
translate.baidu('我是谁', 'en').then(console.log)

API

translate()

先尝试使用 google 翻译,如果失败再使用 baidu 翻译

参数如下:

translate(
  word: string, // [必填] 要翻译的文字
  to: string, // [必填] 要翻译成什么语言
  from: string // 原本字符的语言,默认 auto 自动识别
): Promise<{
  type: string, // 服务 google | baidu
  from: string, // 原本字符的语言
  to: string, // 翻译后的语言
  src: string, // 原本被翻译的字符
  dist: string, // 翻译后字符
  targets: string[] // 翻译后字符的其他相似项
}>
translate.google()

使用 google 翻译,参数同 translate()

translate.baidu()

使用 baidu 翻译,参数同 translate()

支持的语言

baidu 支持的语言列表:http://api.fanyi.baidu.com/api/trans/product/apidoc#languageList google 支持的语言列表:https://cloud.google.com/translate/docs/languages

思路

使用 http 请求获取 google 翻译 和 baidu 翻译页面,模拟页面翻译,google 翻译的host 默认为 translate.google.cn,无需梯子

Thanks

google-translate-api: https://github.com/matheuss/google-translate-api baidu-translate-api: https://github.com/TimLuo465/baidu-translate-api

本项目基于以上两个项目扩展,代码大部分来自于以上两个项目

FAQs

Last updated on 12 Dec 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc