Linguister
![Known Vulnerabilities](https://snyk.io/test/github/TomSputz/linguister/badge.svg)
A free and unlimited API for Google Translate built in typescript :dollar::no_entry_sign:
Features
- Auto language detection
- Full typing
- Spelling correction
- Language correction
- Fast and reliable – it uses the same servers that translate.google.com uses
Install
npm install --save linguister
Usage
The module automatically exposes a default wrapper through the translate
export, however if you want to spawn the requests differently, you can extend Linguister.TranslateAPI
, calling _translate
for the API request
From automatic language detection to English:
import {translate} from 'linguister'
translate('Ik spreek Engels', {to: 'en'}).then(res => {
console.log(res.text)
console.log(res.from.language.iso)
}).catch(err => {
console.error(err)
})
From English to Dutch with a typo:
translate('I spea Dutch!', {from: 'en', to: 'nl'}).then(res => {
console.log(res.text)
console.log(res.from.text.autoCorrected)
console.log(res.from.text.value)
console.log(res.from.text.didYouMean)
}).catch(err => {
console.error(err)
})
Sometimes, the API will not use the auto corrected text in the translation:
translate('I spea Dutch!', {from: 'en', to: 'nl'}).then(res => {
console.log(res);
console.log(res.text)
console.log(res.from.text.autoCorrected)
console.log(res.from.text.value)
console.log(res.from.text.didYouMean)
}).catch(err => {
console.error(err)
})
API
Table of Contents
LangFrom
Returns the ISO 639-1 code of the desiredLang – if it is supported by Google Translate
Parameters
query
string – the name or the code of the desired language
Returns string The ISO 639-1 code of the language
TranslateAPI
Used to spawn api requests. Will handle a ratelimit
Parameters
ratelimit
(optional, default 1000
)
translate
Translate a string using google's translate API
Parameters
text
String The text to translateopts
Object Options for the request (optional, default {}
)
opts.from
String? The language to translate fromopts.to
String? The language to translate to
Returns Promise<Translation> The translation response
Coverage
To run the coverage task, the coveralls token must be set in the COVERALLS_REPO_TOKEN enviroment variable
License
MIT © Tom Sputz