Coder Social home page Coder Social logo

tderflinger / libretranslate-ts Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 0.0 191 KB

TypeScript library for the LibreTranslate API. With TypeScript type definitions. Can also be used with JavaScript.

JavaScript 14.89% TypeScript 85.11%
api libretranslate sdk translation javascript typescript

libretranslate-ts's Introduction

libretranslate-ts

A simple and easy to use TypeScript library for LibreTranslate. 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.

Installation

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

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

libretranslate-ts's People

Contributors

tderflinger avatar danublue avatar

Stargazers

Stephen Griffiths avatar Argos Open Tech avatar P.J. Finlay avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.