libretranslate
Version:
Simple API wrapper for LibreTranslate
41 lines (29 loc) • 876 B
Markdown
[](https://libretranslate.com/)
Simple API wrapper for LibreTranslate, an open-source alternative to Google Translate, also supports self-hosted versions
**Node.js v17.5.0 or newer with fetch is required.**
```bash
npm install libretranslate
yarn add libretranslate
```
```js
// CommonJS
const { translate } = require('libretranslate');
// ES Modules (ESM) or Typescript
import { translate } from 'libretranslate';
```
Using `translate()` function.
```js
await translate({
query: 'text', // Text to be translated.
source: 'lang', // The original language. (auto by default)
target: 'lang', // The language to translate.
format: 'text', // The format of the translated text (HTML or Text) Optional
apiurl: 'URL', // Custom API url, if self-hosted
apikey: 'key', // API Key
});
```