Package: linguee-api
Linguee APILingueeprovides excellent dictionary and translation memory service. Unfortunately, there is no way you can get automated access to it. Linguee API fixes the problem. It acts as a proxy and converts their HTML responses to easy-to-use JSON API.API endpointsThe proxy provides three API endpoints: for translations, for examples, and external sources.The API documentation and the playground is available for the sample installation:Documentation and API playgroundThe same documentation, but formatted with ReDocSample installationSample installation is available athttps://linguee-api.fly.dev.Get translations of the word "bacalhau" from Portuguese to English:https://linguee-api.fly.dev/api/v2/translations?query=bacalhau&src=pt&dst=en.Get a list of curated examples:https://linguee-api.fly.dev/api/v2/examples?query=bacalhau&src=pt&dst=en.Get examples from external sources:https://linguee-api.fly.dev/api/v2/external_sources?query=bacalhau&src=pt&dst=en.Local installationInstall the Linguee API.$pipinstalllinguee-apiRun the API server withuvicorn(installed as a dependency.)$uvicornlinguee_api.api:app
...
INFO:Uvicornrunningonhttp://127.0.0.1:8000(PressCTRL+Ctoquit)...Openhttp://127.0.0.1:8000. You will be redirected to the API documentation page, where you can test the API.Supported languagesAPI supports all the languages, supported by Linguee. As in Linguee, not all language pairs are valid though. Supported languages:bg(Bulgarian),cs(Czech),da(Danish),de(German),el(Greek),en(English),es(Spanish),et(Estonian),fi(Finnish),fr(French),hu(Hungarian),it(Italian),ja(Japan),lt(Lithuanian),lv(Latvian),mt(Maltese),nl(Dutch),pl(Polish),pt(Portuguese),ro(Romanian),ru(Russian),sk(Slovak),sl(Solvene),sv(Swedish),zh(Chinese).Response structureLemmasEvery query (a random string) can match several so-called lemma objects.According to Wikipedia,lemmais the canonical form, dictionary form, or citation form of a set of words.In English, for example, break, breaks, broke, broken, and breaking are forms of the same lexeme, with "break" as the lemma by which they are indexed.In the API, lemmas have the only required attribute, "text," but may have optional elements, such as part of speech ("pos") and audio links with pronunciations.TranslationsEvery lemma has one or more translations. The translation is a lemma in a different language and has a similar structure with the necessary text field and optional part of speech and audio links.ExamplesIn addition to lemmas, the API returns several usage examples curated by dictionary authors. Examples are the short phrases, annotated with one or more equivalents in different languages. When appropriate, examples may contain the part-of-speech form and audio links.External SourcesOn top of curated examples, Linguee provides links to external sources. The API returns objects containing the phrase snipped in the original language and an equivalent snippet in the translation.Usage examples with Python and requestsOnce installed on Heroku, Linguee API can be used as any other API service. I recommend using therequestslibrary.Translate a word or a phrase from one language to another with PythonA request to the sample API installation to translate the word "bacalhau" from Portuguese to English.importrequestsapi_root="https://linguee-api.fly.dev/api/v2"resp=requests.get(f"{api_root}/translations",params={"query":"bacalhau","src":"pt","dst":"en"})forlemmainresp.json():fortranslationinlemma['translations']:print(f"{lemma['text']}->{translation['text']}")This will print:bacalhau -> cod
bacalhau -> codfishProvide translation examples with PythonA request to the sample API installation to get all usage examples of "bacalhau" along with their translations.importrequestsapi_root="https://linguee-api.fly.dev/api/v2"resp=requests.get(f"{api_root}/examples",params={"query":"bacalhau","src":"pt","dst":"en"})forexampleinresp.json():fortranslationinexample["translations"]:print(f"{example['text']}->{translation['text']}")This will print:bacalhau desfiado -> shredded cod
lombo de bacalhau -> codfish fillet
...
bacalhau do Atlântico -> Atlantic codGet access to real world usage examples with PythonA request to the sample API installation to get all real-world usage examples of "bacalhau" along with their translations.importrequestsapi_root="https://linguee-api.fly.dev/api/v2"resp=requests.get(f"{api_root}/external_sources",params={"query":"bacalhau","src":"pt","dst":"en"})forsourceinresp.json():print(f"{source['src']}->{source['dst']}")This will print a long list of real-world examples like this:É calculado o esforço de [...] pesca de todos os navios que capturam bacalhau. -> The fishing effort of all [...] the vessels catching cod will be calculated.Bash, curl and jq usage exampleOnce installed on Heroku, Linguee API can be used as any other API service.For Bash scripts you can use curl andjq, a command-line JSON parser.Translate a word or a phrase from one language to another with BashA request to the sample API installation to get all usage examples of "bacalhau" along with their translations.curl-s'https://linguee-api.fly.dev/api/v2/translations?query=bacalhau&src=pt&dst=en'|jq-c'{text: .[].text, translation: .[].translations[].text}'This will print{"text":"bacalhau","translation":"cod"}{"text":"bacalhau","translation":"codfish"}Provide translation examples with BashA request to the sample API installation to get all usage examples of "bacalhau" along with their translations.curl-s'https://linguee-api.fly.dev/api/v2/examples?query=bacalhau&src=pt&dst=en'|jq-c'{text: .[].text, translation: .[].translations[].text}'This will print something like this:{"text":"bacalhau desfiado","translation":"shredded cod"}{"text":"bacalhau desfiado","translation":"codfish fillet"}...{"text":"bacalhau do Atlântico","translation":"Atlantic cod"}Get access to real world usage examples with BashA request to the sample API installation to get all real-world usage examples of "bacalhau" along with their translations.curl-s'https://linguee-api.fly.dev/api/v2/external_sources?query=bacalhau&src=pt&dst=en'|jq-c'{src: .[].src, dst: .[].dst}'This will print a long list of real-world examples like this:{"src":"É calculado o esforço de [...] pesca de todos os navios que capturam bacalhau.","dst":"The fishing effort of all [...] the vessels catching cod will be calculated."}...FAQThe API server returns "The Linguee server returned 503"This error means that the Linguee website temporarily blocks the API client for sending too many requests. If you use the sample API server onhttps://linguee-api.fly.dev, you can try to send the request later or consider installing your API server, where you won't share the same IP address with other users.Terms and ConditionsIf you use the API, make sure you comply withLinguee Terms and Conditions,
and in particular with that clause:Both private and business usage of linguee.com services is free of charge.
It is however strictly prohibited to forward on our services to third
parties against payment