i18n-ai-translate
Version:
AI-powered localization CLI, Node library, and GitHub Action. Translate i18next JSON, Gettext PO, Java .properties, and iOS .strings with ChatGPT, Claude, Gemini, or local Ollama models.
69 lines (68 loc) • 2.6 kB
TypeScript
import { Tiktoken } from "js-tiktoken";
import type TranslateOptions from "../interfaces/translate_options";
import type TranslationContext from "../interfaces/translation_context";
export default class GenerateTranslationJSON {
tikToken: Tiktoken;
templatedStringRegex: RegExp;
constructor(options: TranslateOptions);
/**
* Complete the initial translation of the input text.
* @param flatInput - The flatinput object containing the json to translate
* @param options - The options to generate the translation
* @param chats - The options to generate the translation
* @param translationStats - The translation statistics
*/
translateJSON(ctx: TranslationContext): Promise<{
[key: string]: string;
}>;
/**
* Run the verification step against a source/target pair without
* writing anything. Returns one entry per invalid key, reporting
* what the model thought was wrong and what it would have fixed
* the translation to.
*
* This deliberately does NOT go through generateVerificationJSON —
* that path is designed to *fix* failures and re-verify, so
* successfully-fixed items come back with failure="" and the check
* report would miss every issue. Instead we call the verification
* prompt once per batch, parse the raw schema output, and surface
* the `valid: false` items directly.
*/
checkJSON(ctx: {
flatSource: {
[key: string]: string;
};
flatTarget: {
[key: string]: string;
};
options: TranslateOptions;
pool: import("../chat_pool").default;
}): Promise<Array<{
key: string;
original: string;
translated: string;
issue: string;
suggestion: string;
}>>;
private generateTranslateItemsInput;
private generateVerifyItemsInput;
private generateTranslateItem;
private getBatchTranslateItemArray;
private getBatchVerifyItemArray;
private generateTranslateItemArray;
private getTranslateItemToken;
private getVerifyItemToken;
private generateTranslationJSON;
private generateVerificationJSON;
private convertTranslateItemToIndex;
private parseTranslationToJSON;
private parseVerificationToJSON;
private isValidTranslateItem;
private isValidVerificationItem;
private createTranslateItemsWithTranslation;
private createVerifyItemsWithTranslation;
private runTranslationJob;
private runVerificationJob;
private verifyGenerationAndRetry;
private generateJob;
}