Files
An instance can translate whole documents: plain text, office documents, subtitles, e-books and more. The formats it
accepts are in settings().supportedFilesFormat (e.g. .txt, .docx, .pptx, .odt, .epub, .srt, .pdf), and
settings().filesTranslation says whether it is enabled at all.
Upload and download
import { readFile, writeFile } from "node:fs/promises";
const data = await readFile("report.docx");
const { translatedFileUrl } = await lt.translateFile({
file: new Blob([data]),
filename: "report.docx",
source: "en",
target: "pt",
});
const translated = await lt.downloadFile(translatedFileUrl);
await writeFile(translated.filename, translated.data);
fileis aBlobor aFile. AFilebrings its own name; aBlobneedsfilename, because the instance picks the format by the extension.sourcedefaults toauto.translateFileanswers the URL the instance serves the result from.downloadFilefetches it as{ data: Uint8Array, filename, contentType },filenamecoming from the server'sContent-Disposition.
An unsupported extension or a disabled feature answers 400 (LibreTranslateApiError).
From an AI agent, libretranslate_translate_file does all of this from a local path and saves the result beside it
(see Tools).