@danielmichel305/webtranslate
Version:
Wrapper Function For the WebTranslate Api built by me.
41 lines (31 loc) • 2.08 kB
Markdown
## 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
```js
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:
```js
const translator = new WebTranslate();
```
what's left is to set your provided `API-KEY` by using the
```js
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:
```js
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](https://libretranslate.com/) Translation Engine under the hood.
### Contact
#### Got a question?
Feel free to reach out to me in regards of any question you have.
[](https://www.linkedin.com/in/daniel-michel04/) [](mailto:asterp04@gmail.com)
<p align="left">
made with ❤ by Daniel Michel