Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
baidut
Advanced tools
Readme
Baidu translator for NodeJS and Browser with Promise ready.
On browser, it will make a new request via JSONP as Baidu doesn't support CORS. It offers option to be set either to request for Baidu's HTTP, or HTTPS URL end-point.
On NodeJS, it will make a new request via normal NodeJS's http|https module with options to be set either to go with GET or POST request, and either request for Baidu's HTTP, or HTTPS URL end-point.
Install it via npm install baidut
.
For browser, you can execute npm run build
to create distribution fies in ./dist
directory.
Then inside your .html
file of your project, you can include it via
<script src="dist/Baidut.min.js"></script>
Include it in your project by
var Baidut = require('Baidut');
Prepare Baidu environment first before making a call to translate.
Baidut.builder
.setAppId("2015063000000001")
.setKey("12345678")
.build();
appId=
2015063000000001
, and key=12345678
is working app id and key for Baidu's demo app. You can test using them first.
Then translate it via [default to translate from Chinese to English]
Baidut.translate('苹果')
.then((result) => {
console.log("translated text: " + result.trans_result[0].dst);
}, (e) => {
console.log(e.code + ": " + e.message);
});
Above will translate input text from Chinese to English with POST method of HTTPS request on NodeJS. For browser, it goes with GET method with HTTPS request via JSONP on browser.
You set options via
Baidut.translate('สวัสดี', { http_request: true, get_method: true, from_lang: "th", to_lang: "en" })
.then((result) => {
console.log("translated text: " + result.trans_result[0].dst);
}, (e) => {
console.log(e.code + ": " + e.message);
});
Above set http_request=true
to force it to make a request via HTTP protocol, get_method=true
only available on NodeJS to force it to use GET method for request, and set from_lang="th"
to mark that the source langauge is Thai, and to_lang="en"
to mark the result we want in English.
See list of language support at official document.
As you likely to involve translating Unicode language as well thus defining that your HTML file has UTF-16
encoding is important to have conistency in displaying proper text for non-English language.
Please note that HTML4 support only UTF-8
, but HTML5 support both UTF-8
and UTF-16
.
<head>
...
<meta charset="UTF-16">
...
</head>
There are commands available for development, build documents, build distribution files, and others.
npm run build
- to build a distribution files (included es5-dev, es6, es2015, and minfied version)npm run docs
- to generate document in ./docs
directory. Not that it uses JSDoc from comment in code.npm test
- to run tests for both NodeJS and Browser.e.code
.MIT. See and understand license here.
FAQs
Baidut, translator for Baidu for both NodeJS and Browser
The npm package baidut receives a total of 0 weekly downloads. As such, baidut popularity was classified as not popular.
We found that baidut 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.