libretranslate-extended
Version:
Extended API wrapper for LibreTranslate with built-in language detection and improvements.
79 lines (48 loc) • 2.09 kB
Markdown
[](https://libretranslate.com/)
Extended API wrapper for LibreTranslate, an open-source alternative to Google Translate.
Supports the official API as well as self-hosted instances, with **built-in language detection**.
[](https://www.npmjs.com/package/libretranslate-extended)
[](https://www.gnu.org/licenses/agpl-3.0)
[](https://nodejs.org/)
**Node.js v17.5.0 or newer with fetch is required.**
```bash
npm install libretranslate-extended
yarn add libretranslate-extended
```
```js
// CommonJS
const { translate, detectLanguage } = require("libretranslate-extended");
// ES Modules (ESM) or Typescript
import { translate, detectLanguage } from "libretranslate-extended";
```
Using `translate()` function.
```js
import { translate } from "libretranslate-extended";
const text = await translate({
query: "Hello world",
source: "en", // Optional (default: auto-detect)
target: "es",
});
console.log(text); // "Hola mundo"
```
Using `detectLanguage()` function.
```js
import { detectLanguage } from "libretranslate-extended";
const lang = await detectLanguage("Bonjour tout le monde");
console.log(lang); // "fr"
```
- `translate(options: TranslateOptions): Promise<string>` - Translates text.
- `detectLanguage(text: string): Promise<string>` - Detects the language of the given text.
This package is based on the [`libretranslate`](https://www.npmjs.com/package/libretranslate) package,
retrieved and extended from its last available version on npm.
The original project is no longer publicly maintained or hosted.
This fork continues its development and is licensed under **AGPL-3.0-or-later**.
Modified and maintained by **Sebastián Martínez (sebamar88)**, 2025.
See [LICENSE](./LICENSE) for details.