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.
@flawcra/translate-tools-core
Advanced tools
Readme
The translate tools core kit contains a interfaces and default implementations of basic translation entities.
This package is part of translate tools project.
Main purpose of core package it's standardization a translator entities.
This package contains few translators and its have different status and support different platforms.
Translator name | Platforms | API key | Status |
---|---|---|---|
GoogleTranslator | browser, nodejs | not required | ready to use |
YandexTranslator | browser | not required | ready to use |
BingTranslatorPublic | browser | not required | unstable, ready to use for translate short text with low frequency |
ReversoTranslator | browser | not required | unstable |
Install package npm install @translate-tools/core
WARNING: this library is still under construction, so types is not obey semver and may be change unpredictable. To avoid problems with builds, fix a version of package on minor part.
example: ~0.2.0
Code example
import { GoogleTranslator } from '@translate-tools/core/translators/GoogleTranslator';
const translator = new GoogleTranslator();
// Translate single string
translator
.translate('Hello world', 'en', 'de')
.then((translate) => console.log('Translate result', translate));
NOTE: For use with nodejs you should specify user agent
In most cases for nodejs, translator will work incorrectly without User-Agent
import { GoogleTranslator } from '@translate-tools/core/translators/GoogleTranslator';
const translator = new GoogleTranslator({
headers: {
'User-Agent':
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.81 Safari/537.36',
},
});
translator
.translate('Hello world', 'en', 'de')
.then((translate) => console.log('Translate result', translate));
For use with browser you should specify CORS proxy in most cases when translator is not work
import { GoogleTranslator } from '@translate-tools/core/translators/GoogleTranslator';
// Use some CORS proxy service address as prefix
const translator = new GoogleTranslator({
corsProxy: 'https://crossorigin.me/',
});
translator
.translate('Hello world', 'en', 'de')
.then((translate) => console.log('Translate result', translate));
// Or use your own transform function
const translator = new GoogleTranslator({
corsProxy(url) {
return `https://my-cors-proxy/${url}/some-postfix`;
},
});
translator
.translate('Hello world', 'en', 'de')
.then((translate) => console.log('Translate result', translate));
Translator it's basic entity for translate text.
Namespace types/Translator
ITranslator
with basic structure of translator objectTranslator
which implement ITranslator
and define static membersNamespace translators
Contains a translators which extends Translator
and use API of popular translate services.
Also contains FakeTranslator
for mock and tests
import { GoogleTranslator } from '@translate-tools/core/translators/GoogleTranslator';
const translator = new GoogleTranslator();
// Translate single string
translator
.translate('Hello world', 'en', 'de')
.then((translate) => console.log('Single translate', translate));
// Translate multiple string
translator
.translateBatch(['Translator can translate few strings', 'at one time'], 'en', 'de')
.then((translate) => console.log('Batch translate', translate));
Translate scheduler it's task manager which try fit many translate requests to one request to Translator
.
It's very useful for cases when you have many requests to translate short text but your Translator
have limits for API requests.
Namespace util/Scheduler
Interface ITranslateScheduler
Scheduler
SchedulerWithCache
import { Scheduler } from '@translate-tools/core/util/Scheduler';
import { GoogleTranslator } from '@translate-tools/core/translators/GoogleTranslator';
const translator = new GoogleTranslator();
const scheduler = new Scheduler(translator);
// Scheduler will join this requests and execute it as one request
// Scheduler may implement it any way, it may group requests by languages or other way,
// it may call `translate` method or `translateBatch`, etc
scheduler
.translate('My first translation request', 'en', 'de')
.then((translate) => console.log('Request #1', translate));
scheduler
.translate('My second translation request', 'en', 'de')
.then((translate) => console.log('Request #2', translate));
You can specify options in constructor for each Translator
class.
Not all modules is use all keys.
type: string
Access key for requests to API
type: boolean
Union text array to 1 request (or more, but less than usually anyway).
Option for reduce the number of requests, but it may generate artifacts in translated text.
type: Record<string, string>
Additional headers for requests
type: string | ((url: string) => string)
Proxy prefix or transform function which return url with CORS proxy
CORS proxy useful to avoid CORS error in browser or to mask server requests as browser requests.
All requests will send through this proxy server and this server will modify headers
FAQs
A free and unlimited API for Google Translate, Yandex, Bing
The npm package @flawcra/translate-tools-core receives a total of 0 weekly downloads. As such, @flawcra/translate-tools-core popularity was classified as not popular.
We found that @flawcra/translate-tools-core 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.