1.4.0 • Published 7 months ago

linguee-client v1.4.0

Weekly downloads
3
License
MIT
Repository
github
Last release
7 months ago

Linguee Client

build-and-run-tests

Translate words using the Linguee online service.

How it works

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:

const linguee = require("linguee-client");

linguee.translate("answer", "EN", "ES")
  .then(result => {
      console.log(result);
  })
  .catch(error => {
      console.log(error);
  });

Typescript:

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);
}

The result depends on the word to be translated.

{
  "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": []
    }
  ]
}

Test

npm run test:single

TODOs

  • Improve responses with the less common translations, and audio examples.
  • Allow to set the languages for translation.
  • Add test coverage.
  • Add documentation pages.

License

MIT

Linguee

Website

Terms and Conditions

1.4.0

7 months ago

1.4.0-beta.0

7 months ago

1.3.2

2 years ago

1.3.1

4 years ago

1.3.0

5 years ago

1.0.0

5 years ago

1.0.1-alpha.3

5 years ago

1.1.0-0

5 years ago

1.0.1-alpha.2

5 years ago

1.0.1-alpha.1

5 years ago

1.0.1-alpha.0

5 years ago