@danielmichel305/webtranslate
v1.0.5-a-dev
Published
Wrapper Function For the WebTranslate Api built by me.
Downloads
72
Readme
WebTranslate API
This npm package is the official package that allows easy interaction between any website you build and the WebTranslate API built by me (Daniel Michel) that allows easy localization support with low overhead in your codebase.
Using the package
pre-requisites:
- Vite (prefered) or any modern bundler.
- WebTranslate API npm package installed in your project.
Crash course:
After setting your dev enviroment using any modern bundler (e.g: Vite, webpack, etc..) and installing the package npm i @danielmichel305/webtranslate
you can include the WebTranslate package using
import {WebTranslate} from '@danielmichel305/webtranslate'
Then to start translating any of your webpages you can create an instance of the WebTranslate class which handles translation for you as follows:
const translator = new WebTranslate();
what's left is to set your provided API-KEY
by using the
translator.setApiKey("YOUR-API-KEY");
And Finally to translate any page or section of your page you can use the following 2 lines of code to do so:
const htmlPage = document.getElementById("HTML-to-translate").outerHTML ;
const htmlPage= await translator.TranslatePage(htmlPage.outerHTML,"Source-lang","target-lang");
The previous code would send whatever HTML you have from a div to an entire page to the WebTranslate API which uses LibreTranslate's Translation Engine under the hood.
Contact
Got a question?
Feel free to reach out to me in regards of any question you have.
made with ❤ by Daniel Michel