UNPKG

@danielmichel305/webtranslate

Version:

Wrapper Function For the WebTranslate Api built by me.

45 lines (27 loc) 859 B
import axios from 'axios'; export class WebTranslate { #ApiKey=""; constructor(){ } setApiKey(ApiKey){ this.#ApiKey = ApiKey; } async TranslatePage(HTMLContent,sourceLanguage, Targetlanguage){ try{ let page = HTMLContent; const request = { "X-API-KEY": this.#ApiKey, "q": page, "format": 'html', "source": sourceLanguage, "target": Targetlanguage } const response = await axios.post('http://localhost:8080/', request) ////Current URL is local host as this is a local Dev build return response.data; } catch(err){ console.log("Error contacting translation Endpoint"); throw err; } } }