https://github.com/tderflinger/libretranslate-ts
TypeScript library for the LibreTranslate API. With TypeScript type definitions. Can also be used with JavaScript.
https://github.com/tderflinger/libretranslate-ts
api javascript libretranslate sdk translation typescript
Last synced: about 1 year ago
JSON representation
TypeScript library for the LibreTranslate API. With TypeScript type definitions. Can also be used with JavaScript.
- Host: GitHub
- URL: https://github.com/tderflinger/libretranslate-ts
- Owner: tderflinger
- Created: 2024-02-12T16:24:45.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-13T17:04:07.000Z (over 1 year ago)
- Last Synced: 2025-04-12T17:12:04.190Z (about 1 year ago)
- Topics: api, javascript, libretranslate, sdk, translation, typescript
- Language: TypeScript
- Homepage:
- Size: 228 KB
- Stars: 13
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README

# libretranslate-ts
[[Español]](./doc/README_es.md) [[Română]](./doc/README_ro.md)
A simple and easy to use TypeScript library for [LibreTranslate](https://libretranslate.com/).
Can also be used with JavaScript.
LibreTranslate is a free and open source translation application that also offers an API.
This library connects to the API.
If you are looking for instructions on how to deploy your own LibreTranslate instance you can find them [here](https://github.com/LibreTranslate/LibreTranslate).
## Installation
```bash
npm i libretranslate-ts --save
```
## Example Usage
In this example, I connect to a LibreTranslate instance on `localhost:5000`.
When your instance is different, you need to change this.
app.mjs
```typescript
import { libreTranslate } from "libretranslate-ts";
const LIBRETRANSLATE_ENDPOINT = "http://localhost:5000";
libreTranslate.setApiEndpoint(LIBRETRANSLATE_ENDPOINT);
libreTranslate.setApiKey("");
const resultDetect = await libreTranslate.detect("Hola, cómo estás?");
console.log("Detected language: ", resultDetect);
const result = await libreTranslate.translate(
"There is a tiger in the house nearby the barn.",
"en",
"es"
);
if (result?.status >= 400) {
console.log("Status: ", result?.status);
console.error("Error: ", result?.error);
process.exit(1);
}
console.log(result?.translatedText);
```
## Bugs
Please file any issues and enhancement ideas under the "Issues" tab.
## Roadmap
- Add possibility to translate whole files
## License
MIT License