deepl-node icon indicating copy to clipboard operation
deepl-node copied to clipboard

Feature Idea: Translate webpage from url

Open SleeplessOne1917 opened this issue 2 years ago • 1 comments

The contributors file said that would-be contributors should open an issue for suggested features instead of just jumping straight into making a pull request. I'm using the bug template because there is no feature template.

Describe the Feature

Generate a translated HTML document based off of the URL for a webpage. The following code snippet would translate the page for DeepL's English Wikipedia article into German and save it in the file DeepLWiki.html:

await translator.translateWebpageToDocument(
        'https://en.wikipedia.org/wiki/DeepL_Translator',
        'DeepLWiki.html',
        'en',
        'de',
        { formality: 'more' },
    );

In line with the other document related functions, there can be an uploadWebpageToDocument function that takes a URL as the first argument with the rest of its arguments being the same as uploadDocument. getDocumentStatus and downloadDocument would not need their own versions as uploadWebpageToDocument would return a DocumentHandle like uploadDocument does.

Implementation

Without writing the exact code, I think uploadWebpageToDocument would first make a request to the URL that's passed in as an argument. If the request is successful and the response has it's Content-Type header set text/html, the response HTML gets put into a buffer and passed to uploadDocument along with the rest of the parameters. If the request to the website fails or the response is not the expected mime type, the function throws an error.

SleeplessOne1917 avatar Mar 03 '23 19:03 SleeplessOne1917

Thank you for the feature suggestion, @SleeplessOne1917 ! We think it makes sense and if you open a pull request, we will certainly review it.

seekuehe avatar Apr 18 '23 12:04 seekuehe