@cutticat/libretranslate
v1.0.3
Published
CuttiCat library for working with LibreTranslate
Maintainers
Readme
@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/libretranslateQuick 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; returnsPromise<TranslateResponse>; throwsErroron 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
