npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

google-baidu-translate-api

v1.0.3

Published

A free and unlimited API for Google & Baidu Translate

Downloads

12

Readme

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

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