@translated/lara
Version:
Official Lara SDK for JavaScript and Node.js
81 lines (80 loc) • 4.17 kB
TypeScript
import type { LaraClient } from "./net/lara";
import type { MultiPartFile } from "./net/lara/client";
import type { LaraStream } from "./net/s3/laraStream";
import type { NGGlossaryMatch, NGMemoryMatch, TranslationStyle } from "./translator";
type ClassicModels = "overlay" | "inpainting";
type GenerativeModels = "generative" | "generative_fast";
export type ImageTranslationModel = ClassicModels | GenerativeModels;
/**
* Shared options for image translation and text extraction.
*/
type ImageBaseTranslationOptions = {
adaptTo?: string[];
glossaries?: string[];
style?: TranslationStyle;
noTrace?: boolean;
};
export type ImageTextTranslationOptions = ImageBaseTranslationOptions & {
/** Include memory and glossary matches in each paragraph. */
verbose?: boolean;
/** Include layout metadata for rendering in every returned paragraph. */
includeLayout?: boolean;
};
export type ImageTranslationOptions = ImageBaseTranslationOptions & {
/** @deprecated Use `model` instead. */
textRemoval?: ClassicModels;
model?: ImageTranslationModel;
};
/** Text fields present in every translated image paragraph. */
export type ImageParagraphContent = {
readonly text: string;
readonly translation: string;
};
export type ImageParagraph = ImageParagraphContent & {
readonly adaptedToMatches?: NGMemoryMatch[];
readonly glossariesMatches?: NGGlossaryMatch[];
};
export type ImageBBox = {
readonly topLeft: [number, number];
readonly topRight: [number, number];
readonly bottomRight: [number, number];
readonly bottomLeft: [number, number];
};
export type ImageTextInfo = {
readonly direction: "ltr" | "rtl" | "ttb";
readonly textColor: string;
readonly backgroundColor: string;
};
/** Layout metadata required by the overlay and inpainting models. */
export type ImageParagraphLayout = {
readonly bbox: ImageBBox;
readonly linesBboxes: ImageBBox[];
readonly textInfo: ImageTextInfo;
readonly alignment: "left" | "center" | "right";
};
export type ImageLayoutParagraph = ImageParagraph & ImageParagraphLayout;
/** Including layout returns complete rendering metadata for every paragraph. */
type ImageParagraphForOptions<Options extends ImageTextTranslationOptions | undefined, IncludeLayout = Options extends ImageTextTranslationOptions ? Options["includeLayout"] : undefined> = IncludeLayout extends true ? ImageLayoutParagraph : ImageParagraph;
/** Defaults to the legacy response; specialized results remain assignable to it. */
export type ImageTextResult<Paragraph extends ImageParagraph = ImageParagraph> = {
readonly sourceLanguage: string;
readonly adaptedTo?: string[];
readonly glossaries?: string[];
readonly paragraphs: Paragraph[];
};
export declare class ImageTranslator {
private readonly client;
constructor(client: LaraClient);
translate(file: MultiPartFile, source: string | null, target: string, options?: ImageTranslationOptions): Promise<LaraStream>;
translateText<Options extends ImageTextTranslationOptions | undefined>(file: MultiPartFile, source: string | null, target: string, options: Options): Promise<ImageTextResult<ImageParagraphForOptions<Options>>>;
translateText(file: MultiPartFile, source: string | null, target: string, options?: ImageTextTranslationOptions): Promise<ImageTextResult>;
/**
* Render supplied translations onto the original image.
* Pass null for source to omit it. Omitting model uses the API default, generative_fast.
* Overlay and inpainting require complete layout metadata on every paragraph.
* Generative models also accept text-only paragraphs. The API validates layout completeness.
*/
renderTranslated(file: MultiPartFile, source: string | null, target: string, paragraphs: (ImageParagraphContent & ImageParagraphLayout)[], model?: ImageTranslationModel, noTrace?: boolean): Promise<LaraStream>;
renderTranslated(file: MultiPartFile, source: string | null, target: string, paragraphs: (ImageParagraphContent | (ImageParagraphContent & ImageParagraphLayout))[], model?: GenerativeModels, noTrace?: boolean): Promise<LaraStream>;
}
export {};