UNPKG

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.

159 lines (158 loc) 7.32 kB
/** * @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>; /** * Extract the language code from a filename like `fr.json` or * `es-ES.json`. If the full prefix (e.g. `es-ES`) is not a valid * ISO-639-1 code, fall back to the portion before the first hyphen — * BCP-47 locale tags like `es-ES` / `pt-BR` / `zh-CN` are common in * i18next projects and should be accepted. If neither form is valid, * the raw prefix is returned so the caller can surface a clear error. * @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; /** * Expand an ISO-639-1 code to its English display name (e.g. "en" → * "English"). Used in prompts because language names steer the LLM * much better than the two-letter code does. Falls back to the raw * code if the lookup fails so prompts never break. * @param languageCode - the ISO-639-1 code * @returns the English display name, or the raw code if unknown */ export declare function getLanguageName(languageCode: string): string; /** * Accept both ISO-639-1 codes ("en") and English language names * ("English", "english", "ENGLISH") and normalise to the code. Returns * the input unchanged when no match is found so the caller's existing * validation can surface a clear error. * * This covers a common footgun flagged in BUG_REPORT.md and issue #5 — * users passed `-l English` based on older docs and got a cryptic * 'Invalid input language code: English' instead of a hint. * @param raw - the user-supplied language identifier * @returns the resolved ISO-639-1 code, or the raw input if unresolved */ export declare function resolveLanguageCode(raw: string): string; /** * @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>; /** * ASCII Unit Separator (0x1F). Used to join a file path with an i18n * key into a single compound key string. Chosen because no legal file * path on any platform can contain it — unlike `:`, which is a drive * letter separator on Windows and broke directory mode on that OS. */ export declare const DIRECTORY_KEY_DELIMITER = "\u001F"; /** * Swap the input-language segment of a source file path for the output * language, normalising separators. This is the path half of * {@link getTranslationDirectoryKey}; the directory wrappers key * per-file adapter state (sidecar, chosen adapter) by it so the write * loop can recover that state after translation. Normalizing to forward * slashes keeps the language-segment match working on Windows (where * path.resolve returns backslash paths) and POSIX alike. * @param sourceFilePath - the source file's path * @param inputLanguageCode - the source language code * @param outputLanguageCode - the target language code (defaults to input) * @returns the output file path with forward slashes */ export declare function getTranslationDirectoryPath(sourceFilePath: string, inputLanguageCode: string, outputLanguageCode?: string): 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; /** * Legacy path-resolution convention: an absolute path resolves as-is, * a relative path is tried first under `./jsons/` and then under cwd. * @param input - the user-supplied path * @returns the resolved absolute path */ export declare function resolveInputPath(input: string): string; /** * For output paths — unlike input paths, the file doesn't exist yet, so * we decide based on whether the `./jsons/` directory is present. * @param output - the user-supplied output path * @returns the resolved absolute path */ export declare function resolveOutputPath(output: string): string;