Security News
Supply Chain Attack Detected in @solana/web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
translation.js
Advanced tools
收集多种翻译接口并用同一个 API 调用。
互联网上有很多可供免费使用的翻译接口,比如百度翻译、谷歌翻译、有道翻译、必应翻译等等,它们的接口不尽相同,但原理都是发起 HTTP 请求获取翻译结果。translation.js 的目标就是统一这些接口的调用方式,可以使用一种方法调用不同的多个接口。借助于 Browserify 与 SuperAgent 的力量,它可以同时运行在 node.js 与浏览器端。
以百度翻译接口为例,你可以申请多个 apiKey 在 translation.js 中生成多个百度翻译实例,那么调用百度翻译时, translation.js 会轮流使用各个实例进行翻译。这样做能有效降低由于使用次数过多而导致 apiKey 被封禁的风险。
如果某一个翻译接口没有被添加,你也可以很方便的自定义翻译接口。欢迎提交 PR 添加更多的翻译接口!
const Translation = require('translation.js'),
t = new Translation();
t.create('BaiDu',{ apiKey:'YourApiKey - 1' });
t.create('BaiDu',{ apiKey:'YourApiKey - 2' });
t.create('YouDao',{ apiKey:'key', keyFrom:'from' });
t.create('Google');
t.create('GoogleCN');
t.create('Bing');
// 暂时支持上面这些翻译接口
// 翻译
t.translate({ api:'BaiDu', text:'test' }).then(resultObj => console.dir(resultObj) , errMsg => console.log(errMsg));
// 获取这段文本的语音地址
t.audio({ api:'BaiDu', text:'test' }).then(audioUrl => console.log(audioUrl) , errMsg => console.log(errMsg));
// 检测语种
t.detect({ api:'BaiDu', text:'test' }).then(lan => console.log(lan) , errMsg => console.log(errMsg));
待写。
载入 browser/translation.js ,构造函数会定义为全局变量 Translation
。
注意:内置的翻译接口都不支持 CORS,请确保浏览器端的运行环境允许跨域,例如你可以在 Chrome 扩展程序 中使用。
这个项目原本是划词翻译的一部分,被用于统一翻译接口的调用方式;在开发 v6.0 版的划词翻译中,我想扩展它的功能,然后发现它完全可以被抽离出来单独维护——于是我就这么做了 :)
FAQs
The npm package translation.js receives a total of 108 weekly downloads. As such, translation.js popularity was classified as not popular.
We found that translation.js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.