linguee-client
Version:
A simple node.js Linguee client.
159 lines (133 loc) • 3.54 kB
Markdown
[](https://github.com/javierdwd/linguee-client/actions/workflows/build-and-test.yml)
Translate words using the Linguee online service.
This library makes a background request to Linguee.com, parse the response and returns an object which contains a set of data.
It traverse the document (HTML response, there is not a JSON api available), hence the results may be affected by changes in the DOM of the service.
## Installation
`npm install linguee-client`
## Usage
_VanillaJS:_
```JS
const linguee = require("linguee-client");
linguee.translate("answer", "EN", "ES")
.then(result => {
console.log(result);
})
.catch(error => {
console.log(error);
});
```
_Typescript:_
```TS
import linguee from "linguee-client"
try {
const translation = await linguee.translate("answer", "EN", "ES");
console.log(translation); // Linguee translation object or void (term was not found).
} catch(err: Error) {
console.log(error);
}
```
```JSON
{
"from": "EN",
"to": "ES",
"queryTerm": "state",
"spelling": null,
"wiki": {
"abstracts": [],
"legal": ""
},
"words": [
{
"additionalInfo": {
"plural": "states"
},
"audios": [
{
"url": "https://...",
"version": "American English"
},
{
"url": "https://...",
"version": "British English"
}
],
"term": "state",
"translations": [
{
"examples": [
{
"phrase": "The state of the economy has improved.",
"translation": "La situación de la economía ha mejorado."
}
],
"term": "situación",
"type": "noun, feminine"
}
],
"type": "noun",
"uncommonTranslations": [
{
"examples": [],
"term": "país",
"type": "noun, masculine"
},
{
"examples": [],
"term": "condición",
"type": "noun, feminine"
},
{
"examples": [],
"term": "nación",
"type": "noun, feminine"
}
]
}
],
"inexactWords": [
{
"additionalInfo": null,
"audios": [
{
"url": "https://...",
"version": "American English"
},
{
"url": "https://...",
"version": "British English"
}
],
"term": "steady state",
"translations": [
{
"examples": [],
"term": "situación estable",
"type": "noun, feminine"
},
{
"examples": [],
"term": "régimen estable",
"type": "noun, masculine"
}
],
"type": "n",
"uncommonTranslations": []
}
]
}
```
`npm run test:single`
- [x] Improve responses with the less common translations, and audio examples.
- [x] Allow to set the languages for translation.
- [ ] Add test coverage.
- [ ] Add documentation pages.
MIT
[](https://www.linguee.com/)
[](https://www.linguee.com/english-spanish/page/termsAndConditions.php)