A simple to use Dart package, for detecting & translating text and html pages using Yandex.Translate API
Show some ❤️, by putting ⭐
This package is readily avaiable for use.
- Fetches list of languages along with language codes, supported by Yandex.Translate API
- Detects which language given text belongs to
- Translates text or html page to certain language, denoted by language code
First get yourself a Yandex.Translate API Key, which can be found here.
Fetch list of supported language :
Languages('api_key')
.fetch()
.then(
(data) => print(data),
onError: (e) => print(e),
).then((val) => exit(0));
Response in case of success,
{
ru: 'Russian',
en: 'English',
}
Response in case of error,
{
error: ' ... '
}
Detect language of text :
DetectIt('api_key')
.detect('Hello World', hint: [
'en',
'de',
'ru',
'hi',
]) // hints are to be prioritized by platform while detecting language, if provided
.then(
(data) => print(data),
onError: (e) => print(e),
)
.then((val) => exit(0));
Response in case of success,
{
lang: 'en'
}
Response in case of error,
{
error: ' ... '
}
Translate Text :
TranslateIt('api_key')
.translate(
'<!DOCTYPE html><html><head><title>Hello World</title></head><body><p>Hello World</p></body></html>',
'en-ru', // only `ru` will also do same job
type: 'html') // type is `html`, cause this text is markedup
.then(
(data) => print(data),
onError: (e) => print(e),
)
.then((val) => exit(0));
English | Russian |
---|---|
Response in case of success,
{
text: ' ... '
}
Response in case of error,
{
error: ' ... '
}
Translation API is powered by Yandex.Translate, so all thanks goes to them.
If you're interested in learning more about T&C, take a look here.
You can also go for priced version.
Hoping, it was helpful 😉