@toil/translate
v1.0.8
Published
A library for free and not only using various translation APIs
Downloads
244
Maintainers
Readme
translate
A library for free and not only using various translation APIs, which supports working with JavaScript, TypeScript, and also has built-in separated types for Typebox.
Installation
Installation via Bun:
bun add @toil/translateInstallation via NPM:
npm install @toil/translateGetting started
To start working with the API, you need to create a Translation Client. This can be done using the code provided below.
const client = new TranslationClient({
service: TranslationService.yandexbrowser,
});
const translatedResult = await client.translate(
"The quick brown fox jumps over the lazy dog",
);
const detectResult = await client.detect(
"The quick brown fox jumps over the lazy dog",
);
const langs = await client.getLangs();You can see more code examples here
Available services
| Status | Service | Functions | Limits | | ------ | ----------------- | ------------------------------- | ------------------------------ | | ✅ | YandexBrowser | TranslateDetectGetLangs | 10k chars/req10k chars/req | | ✅ | YandexCloud | TranslateDetectGetLangs | 2k chars/req1k chars/req | | ✅ | YandexTranslate | TranslateDetectGetLangs | 10k chars/req10k chars/req | | ✅ | YandexGPT*¹ | TranslateDetectGetLangs | 10k chars/req10k chars/req | | ✅ | MSEdge | TranslateDetectGetLangs | 50k chars/req50k chars/req | | ✅ | Bing | TranslateDetectGetLangs | 1k chars/req1k chars/req | | ✅ | LibreTranslate*² | TranslateDetectGetLangs | 2k chars/req2k chars/req | | ✅ | OperaAria*³ | TranslateDetectGetLangs | 1k chars/req6k chars/req |
*¹ - translation using YandexGPT only works for the en-ru pair, For all other cases, a translation similar to YandexTranslate is used
*² - by default, obtaining a secret key is disabled. Please install apiKey or enable allowUnsafeEval when creating the client. With allowUnsafeEval some requests may result in an error, probably due to some hard limits on the service side
*³ - translation using OperaAria prohibits the translation of certain forbidden topics and also has geo-restrictions for some countries. The translation is performed using a neural network and may return unexpected results
Build
To build, you must have:
Don't forget to install the dependencies:
bun installStart building:
bun build:allTests
The library has minimal test coverage to check it's performance.
Run the tests:
bun test