README.md

@cutticat/libretranslate

Library for working with the LibreTranslate API.

Table of Contents

Overview

The library provides the translate function for translating text via the LibreTranslate API. Supports language auto-detection, alternative translations, custom baseUrl and API key. Uses Zod for response validation and types from @cutticat/types.

Installation

pnpm i @cutticat/libretranslate

Quick Start

import { translate } from "@cutticat/libretranslate"

const result = await translate({
  text: "Hello, world!",
  source: "en",
  target: "ru",
})
console.log(result.translatedText) // "Привет, мир!"

With language auto-detection:

const result = await translate({
  text: "Bonjour",
  source: "auto",
  target: "en",
})
console.log(result.translatedText) // "Hello"
console.log(result.detectedLanguage) // { code: "fr", confidence: 0.95 }

API

Functions

  • translate(options) — translates text via the LibreTranslate API; returns Promise<TranslateResponse>; throws Error on request failure

Types

  • TranslationOptions — translation parameters (text, source, target, format?, alternatives?, baseUrl?, apiKey?, fetch?)
  • TranslationFormat"text" | "html"
  • TranslateResponse — response (translatedText, detectedLanguage?, alternatives?)
  • DetectedLanguage — detected language info (code, confidence)

Constants

  • defaultBaseUrl — default URL (https://libretranslate.com)

Documentation

Detailed documentation:

Full API documentation is available in JSDoc comments. Use IDE autocomplete to browse it.

Requirements

  • Node.js >= 22.0.0
  • pnpm >= 10.17.0
  • TypeScript >= 5.9.0
Описание
Library for working with LibreTranslate
Конвейеры
6 успешных
4 с ошибкой
Разработчики