i18n-ai-translate
Version:
Use LLMs to translate your i18n JSON to any language.
96 lines (95 loc) • 4 kB
TypeScript
/**
* @param delayDuration - time (in ms) to delay
* @returns a promise that resolves after delayDuration
*/
export declare function delay(delayDuration: number): Promise<void>;
/**
* @param error - the error message
*/
export declare function printError(error: string): void;
/**
* @param warn - the warning message
*/
export declare function printWarn(warn: string): void;
/**
* @param info - the message
*/
export declare function printInfo(info: string): void;
/**
* @param job - the function to retry
* @param jobArgs - arguments to pass to job
* @param maxRetries - retries of job before throwing
* @param firstTry - whether this is the first try
* @param delayDuration - time (in ms) before attempting job retry
* @param sendError - whether to send a warning or error
* @returns the result of job
*/
export declare function retryJob<Type>(job: (...args: any) => Promise<Type>, jobArgs: Array<any>, maxRetries: number, firstTry: boolean, delayDuration?: number, sendError?: boolean): Promise<Type>;
/**
* @param filename - the filename to get the language from
* @returns the language code from the filename
*/
export declare function getLanguageCodeFromFilename(filename: string): string;
/**
* @returns all language codes
*/
export declare function getAllLanguageCodes(): string[];
/**
* @param languageCode - the language code to validate
* @returns whether the language code is valid
*/
export declare function isValidLanguageCode(languageCode: string): boolean;
/**
* @param directory - the directory to list all files for
* @returns all files with their absolute path that exist within the directory, recursively
*/
export declare function getAllFilesInPath(directory: string): Array<string>;
/**
* @param sourceFilePath - the source file's path
* @param key - the key associated with the translation
* @param inputLanguageCode - the language code of the source language
* @param outputLanguageCode - the language code of the output language
* @returns a key to use when translating a key from a directory;
* swaps the input language code with the output language code
*/
export declare function getTranslationDirectoryKey(sourceFilePath: string, key: string, inputLanguageCode: string, outputLanguageCode?: string): string;
/**
* @param response - the message from the LLM
* @returns whether the response includes NAK
*/
export declare function isNAK(response: string): boolean;
/**
* @param response - the message from the LLM
* @returns whether the response only contains ACK and not NAK
*/
export declare function isACK(response: string): boolean;
/**
* @param originalTemplateStrings - the template strings in the original text
* @param translatedTemplateStrings - the template strings in the translated text
* @returns the missing template string from the original
*/
export declare function getMissingVariables(originalTemplateStrings: string[], translatedTemplateStrings: string[]): string[];
/**
* @param templatedStringPrefix - templated String Prefix
* @param templatedStringSuffix - templated String Suffix
* @returns the regex needed to get the templated Strings
*/
export declare function getTemplatedStringRegex(templatedStringPrefix: string, templatedStringSuffix: string): RegExp;
/**
* @param startTime - the startTime
* @param prefix - the prefix of the Execution Time
*/
export declare function printExecutionTime(startTime: number, prefix?: string): void;
/**
* @param title - the title
* @param startTime - the startTime
* @param totalItems - the totalItems
* @param processedItems - the processedItems
*/
export declare function printProgress(title: string, startTime: number, totalItems: number, processedItems: number): void;
/**
* @param inputPath - the input path
* @param outputLanguageCode - the output language code
* @returns the output path based on the input path and output language code
*/
export declare function getOutputPathFromInputPath(inputPath: string, outputLanguageCode: string): string;