Git Product home page Git Product logo

s0ftik3 / reverso-api Goto Github PK

View Code? Open in Web Editor NEW
103.0 2.0 22.0 246 KB

馃實 Simple JavaScript Reverso API. Context, Spell Check, Synonyms, Translation and Conjugation are currently available.

Home Page: https://www.npmjs.com/package/reverso-api

License: MIT License

JavaScript 100.00%
reverso reverso-context spell-check translation javascript-reverso reverso-api language synonyms conjugation

reverso-api's Introduction

Reverso API

version downloads telegram chat

logotype

Translate, get context examples or synonyms of words - this and much more you can do with your text queries via this API wrapper.

Navigation

Installing

$ npm i reverso-api

Usage

const Reverso = require('reverso-api')
const reverso = new Reverso()

Congrats! You can use all the available methods now.
Let's read through the README and find out how the things work.

You can pass either callback function...

reverso.getContext(...params, (err, response) => {
    ...
})

or use .then() function.

reverso.getContext(...params).then((response) => {
    ...
})

All the examples below are given using callback function.

Examples

getContext

reverso.getContext(
    'meet me half way',
    'english',
    'russian',
    (err, response) => {
        if (err) throw new Error(err.message)

        console.log(response)
    }
)

Response:

{
    ok: Boolean,
    text: String,
    source: String,
    target: String,
    translations: [String, ...],
    examples: [
        {
            id: Number,
            source: String,
            target: String
        },
        ...
    ]
}

Error:

{ ok: Boolean, message: String }

getSpellCheck

reverso.getSpellCheck('helo', 'english', (err, response) => {
    if (err) throw new Error(err.message)

    console.log(response)
})

Response:

{
    ok: Boolean,
    text: String,
    sentences: [ { startIndex: Number, endIndex: Number, status: String } ... ],
    stats: {
        textLength: Number,
        wordCount: Number,
        sentenceCount: Number,
        longestSentence: Number,
    },
    corrections: [
        {
            id: Number,
            text: String,
            type: String,
            explanation: String,
            corrected: String,
            suggestions: [
                {
                    text: String,
                    definition: String,
                    category: String,
                },
                ...
            ],
        },
    ]
}

Error:

{ ok: Boolean, message: String }

getSynonyms

reverso.getSynonyms('dzie艅 dobry', 'polish', (err, response) => {
    if (err) throw new Error(err.message)

    console.log(response)
})

Response:

{
    ok: true,
    text: String,
    source: String,
    synonyms: [
        { id: Number, synonym: String },
        ...
    ]
}

Error:

{ ok: Boolean, message: String }

getTranslation

鈿狅笍 WARNING: eventually, your server's IP address might get banned by Reverso moderators and you won't receive any data.

reverso.getTranslation(
    'how is going?',
    'english',
    'chinese',
    (err, response) => {
        if (err) throw new Error(err.message)

        console.log(response)
    }
)

Response:

{
    text: String,
    source: String,
    target: String,
    translations: [String, ...],
    context: {
        examples: [
            {
                source: String,
                target: String,
                source_phrases: [
                    {
                        phrase: String,
                        offset: Number,
                        length: Number
                    },
                    ...
                ],
                target_phrases: [
                    {
                        phrase: String,
                        offset: Number,
                        length: Number
                    },
                    ...
                ]
            },
            ...
        ],
        rude: Boolean
    }, // or null
    detected_language: String,
    voice: String // or null
}

Error:

{ ok: Boolean, message: String }

getConjugation

reverso.getConjugation('懈写褌懈', 'russian', (err, response) => {
    if (err) throw new Error(err.message)

    console.log(response)
})

Response:

{
    ok: Boolean,
    infinitive: String,
    verbForms: [
        {
            id: Number,
            conjugation: String,
            verbs: [String, ...],
        },
        ...
    ]
}

Error:

{ ok: Boolean, message: String }

Credits

reverso-api's People

Contributors

atipi132 avatar ddeluc avatar gustawdaniel avatar koynoyno avatar louisrli avatar mathias4833 avatar mgyucht avatar s0ftik3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

reverso-api's Issues

What is wrong from my side

Hi
What is wrong

locate reverso.js  | xargs ls -lt
-rw-r--r-- 1 vlad vlad 12569 Oct 26  1985 /home/vlad/misc/node_modules/reverso-api/src/reverso.js
-rw-r--r-- 1 vlad vlad 12569 Oct 26  1985 /home/vlad/node_modules/reverso-api/src/reverso.js
-rw-r--r-- 1 vlad vlad 12569 Oct 26  1985 /usr/local/lib/node_modules/reverso-api/src/reverso.js
cat ./r.js 


import { Reverso } from 'reverso-api'
const reverso = new Reverso()
node ./r.js 
(node:39935) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
/home/vlad/misc/r.js:3
import { Reverso } from 'reverso-api'
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at wrapSafe (internal/modules/cjs/loader.js:915:16)
    at Module._compile (internal/modules/cjs/loader.js:963:27)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47

Sorry, Im not experiencied in nodejs

ts-node-dev dynamic import

I am using this command to start my project:

npx ts-node-dev --no-notify --respawn --transpile-only src/index.ts

and after installing reveso and using by

import {Reverso} from 'reverso-api';
const reverso = new Reverso();

I see this error:

[ERROR] 14:19:07 Error: require() of ES Module /home/builduser/pro/xue/gql/node_modules/reverso-api/index.js from /home/builduser/pro/xue/gql/src/services/translator.ts not supported.
Instead change the require of index.js in /home/builduser/pro/xue/gql/src/services/translator.ts to a dynamic import() which is available in all CommonJS modules.

Arabic and Hebrew do no work properly

Hi!
I was messing around with this package when I found out that the package throws this error upon using getContext with Arabic and Hebrew. e.g.

reverso.getContext('meet me half way', 'English', 'Arabic', (response) => {
    console.log(response);
}).catch((err) => {
    console.error(err);
});

gives us the error

{
  method: 'getContext',
  error: TypeError: Cannot read property 'trimStart' of undefined
      at C:\Users\faisa\OneDrive\Desktop\TranslateServer\node_modules\reverso-api\src\reverso.js:57:43
      at processTicksAndRejections (internal/process/task_queues.js:95:5)       
}

My guess is that it has something to do with those two languages being written right to left while the other languages are written left to right.

getContext method works a bit wrong

The method sometimes returns wrong context examples. Specifically, there's a query word in list of context examples. It happens time to time but it does.

TypeScript support

Hello @s0ftik3! Could you please add TypeScript support to your library? I see an old open PR on this matter with no response from you. Now when I install your library into my project I see a TypeScript error.
Screenshot from 2024-08-01 16-15-53

Tolerate missing expected CR after header value in response from Reverso API

Connected with nodejs/node#43798, I notice a transient issue happening where around one in every 10 requests fails with the following error:

/Users/milesyucht/Dropbox/Documents/coding/nextjs-blog/scripts/dutch-simple-verbs/node_modules/reverso-api/src/reverso.js:419
            throw new Error(err.message)
                  ^

Error: Parse Error: Missing expected CR after header value
    at Reverso.request (/Users/milesyucht/Dropbox/Documents/coding/nextjs-blog/scripts/dutch-simple-verbs/node_modules/reverso-api/src/reverso.js:419:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Reverso.getContext (/Users/milesyucht/Dropbox/Documents/coding/nextjs-blog/scripts/dutch-simple-verbs/node_modules/reverso-api/src/reverso.js:75:22)
    at async main (/Users/milesyucht/Dropbox/Documents/coding/nextjs-blog/scripts/dutch-simple-verbs/index.js:77:7)

Node version: v18.6.0

It seems like we should be able to fix this by allowing clients to set insecureHTTPParser: true in the axios config: https://github.com/axios/axios#request-config. This parameter is supported only in 0.23.0, so this will also require updating axios to the latest release. I think this should be backwards compatible with older versions of node/axios.

include audio urls and transliteration?

@s0ftik3 Would it possible to add the english transliterations and audio url for translations?e.g.
讗植谞执讬 诪址谞旨执讬讞址 砖讈侄讬旨值砖讈 讚旨职讘指专执讬诐 砖讈侄讗植驻执诇旨讜旨 讗植讘讜止转 讗值讬谞指诐 讬职讻讜止诇执讬诐 诇职转址拽旨值谉.
"ani maniakh sheyesh devarim sheafilu avott eynam yekholim letaqenn." (transliteration)
Thanks!

Support for Swedish

Reverso itself has good Swedish support, but your API doesn't accept Swedish as a language option. Would it be possible to add?

New languages supported for Grammar Check, Synonyms, Translation and Context APIs

Reverso's Grammar Checker and Synonyms APIs now support new languages : italian and spanish for the Grammar Checker and arabic, hebrew, japanese, dutch, portugese and romanian for the Synonyms. It would be great to support this in a new version by updating some constants :

In reverso.js' getSpellCheck method :

     * @param source {'english' | 'french' | 'italian' | 'spanish'}
        const languages = {
            english: 'eng',
            french: 'fra',
            italian: 'ita',
            spanish: 'spa'
        }

In reverso.js' getSynonyms method :

     * @param source {'english' | 'russian' | 'german' | 'spanish' | 'french' | 'polish' | 'italian' | 'arabic' | 'hebrew' | 'japanese' | 'dutch' | 'portugese' | 'romanian'}
        const languages = {
            english: 'en',
            french: 'fr',
            german: 'de',
            russian: 'ru',
            italian: 'it',
            polish: 'pl',
            spanish: 'es',
            arabic: 'ar',
            hebrew: 'he',
            japanese: 'ja',
            dutch: 'nl',
            portugese: 'pt',
            romanian: 'ro'
        }

In available.js :

    spell: [
        'english', 
        'french',
        'italian',
        'spanish',
    ],
    synonyms: [
        'english',
        'russian',
        'german',
        'spanish',
        'french',
        'polish',
        'italian',
        'arabic',
        'hebrew',
        'japanese',
        'dutch',
        'portugese',
        'romanian',
    ],

There are also some new languages for the Translation and Context APIs but I haven't really looked at this yet. Hope at least this can be implemented into the next release.

Update : I opened a Pull Request for this issue.

no verb conjugations being returned for hebrew

I am running into a strange problem where the getConjugation method returns no conjugation for the Hebrew language.
It works for Russian though

e.g.:

 reverso.getConjugation( "诇执专职爪讜止转", 'hebrew',
        async (err, response) => {
            if (err) throw new Error(err.message)
    
            console.log(response)

           return response;

        }
    )

returns:

{
data: {
ok: true,
verbForms: [
{
id: 0,
conjugation: "Present",
verbs: [ ]
},
{
id: 1,
conjugation: "Past",
verbs: [ ]
},
{
id: 2,
conjugation: "Future",
verbs: [ ]
},
{
id: 3,
conjugation: "Passive Participle",
verbs: [ ]
}
]
}
}

I wonder if it's something to do with the language being RTL right to left

Doesn't translate a string.

String: The method returns an object that contains given text, its language, examples' language, text's translation and examples of usage. Available languages for this method: English, Russian, German, Spanish, French, Italian, Polish. (copied from README)

Expected output: translation of the entire string.
Output: error.

403 code

hi, I'm using your module but when I use the get translation method it gives me this error:
Error: reverso.net did not respond or there is no translation for the given text.
Error: Request failed with status code 403
at C:\ Users\User\ Desktop\ programming\JavaScript \GroupHelp\ node_modules\reverso-api\src \ reverso.js: 279: 23
at processTicksAndRejections (internal /process /task_queues.js: 93: 5)

500 error

I guess it's the reverso official api to blame but I'm reporting it anyway, I'm getting this on every requests

Error: Request failed with status code 500
     at #request (/root/Histbot/node_modules/reverso-api/src/reverso.js:535:19)
     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
     at async Reverso.getSpellCheck (/root/Histbot/node_modules/reverso-api/src/reverso.js:191:22)

Why using axios?

First of all, great contribution with this package! Thanks! 馃挴

Secondly, I'm using a Vercel edge function which does not have a full node.js environment. For example, axios use is not supported.

Besides adding an interceptor and setting insecureHTTPParser in the #request method inside the Reverso class, is there any other need for using axios? I'm thinking of using it, but changing it for fetch function instead, something like this.

Thanks!

Requests containing a space get redirected

I was using Wireshark to inspect traffic from reverso-api when I saw that requests containing spaces were being redirected.

Screenshot 2022-07-23 at 15 03 29

It seems like %20 should be replaced by +.

new html structure for synonym

const targetTranslations = $('#translations-content > div')

the code now does not show full context translations(at least for Dutch) . here is what i have done to list all potential translations .

       // const targetTranslations = $('.translation .display-term')
       //     .text()
       //     .trim()
       //     .split('\n')
     var targetTranslations = [];
    $('.translation .display-term').each(function () { 
        targetTranslations.push($(this).text().trim())
    });

Also i am not sure why Dutch Synonym is not available, I added it manually, it is working fine. Could you please add it ? thanks

TypeError: Cannot read properties of undefined (reading '1')

Hello, when I try to translate the following string The assignee has a duty toward the assigner and must compensate by: paying an amount equal to 5.00 Euro to turkish, I get the following error:

C:\Projects\odrl-translator\server\node_modules\.pnpm\[email protected]\node_modules\reverso-api\src\reverso.js:436
            ][0][1],
                ^
[1]
[1] TypeError: Cannot read properties of undefined (reading '1')
at C:\Projects\odrl-translator\server\node_modules\.pnpm\[email protected]\node_modules\reverso-api\src\reverso.js:436:21
at Array.map (<anonymous>)
at Reverso.getTranslation (C:\Projects\odrl-translator\server\node_modules\.pnpm\[email protected]\node_modules\reverso-api\src\reverso.js:429:52)
at processTicksAndRejections (node:internal/process/task_queues:96:5)

Any help, please?

Axios need to be updated

npm audit report

axios 0.8.1 - 0.27.2
Severity: moderate
Axios Cross-Site Request Forgery Vulnerability - GHSA-wf5p-g6vw-rhxx
No fix available
node_modules/axios
reverso-api *
Depends on vulnerable versions of axios
node_modules/reverso-api

Error 403

Hi, I tried to use your package but I've got an error : 403, I founded that the server doesn't want me to access to it. How can I resolve that ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    馃枛 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 馃搳馃搱馃帀

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google 鉂わ笍 Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.