UNPKG

@scoutello/i18n-magic

Version:

Intelligent CLI toolkit that automates internationalization workflows for JavaScript/TypeScript projects and auto-translates new string keys to other languages

109 lines 4.7 kB
import type OpenAI from "openai"; import type { Configuration, GlobPatternConfig } from "./types.js"; export declare const loadConfig: ({ configPath, }?: { configPath?: string; }) => Promise<any>; export declare function removeDuplicatesFromArray<T>(arr: T[]): T[]; export declare const translateKey: ({ inputLanguage, context, object, openai, outputLanguage, model, onProgress, }: { object: Record<string, string>; context: string; inputLanguage: string; outputLanguage: string; model: string; openai: OpenAI; onProgress?: (completed: number, total: number) => void; }) => Promise<Record<string, string>>; export declare const loadLocalesFile: (loadPath: string | ((locale: string, namespace: string) => Promise<Record<string, string>>), locale: string, namespace: string, options?: { silent?: boolean; }) => Promise<Record<string, string>>; export declare const writeLocalesFile: (savePath: string | ((locale: string, namespace: string, data: Record<string, string>) => Promise<void>), locale: string, namespace: string, data: Record<string, string>) => Promise<void>; export declare const getPureKey: (key: string, namespace?: string, isDefault?: boolean) => string; /** * Extracts all glob patterns from the configuration, handling both string and object formats */ export declare const extractGlobPatterns: (globPatterns: (string | GlobPatternConfig)[]) => string[]; /** * Gets the namespaces associated with a specific file path based on glob pattern configuration */ export declare const getNamespacesForFile: (filePath: string, globPatterns: (string | { pattern: string; namespaces: string[]; })[], defaultNamespace: string) => string[]; /** * Gets all glob patterns that should be used for a specific namespace */ export declare const getGlobPatternsForNamespace: (namespace: string, globPatterns: (string | { pattern: string; namespaces: string[]; })[]) => string[]; /** * Extracts keys with their associated namespaces based on the files they're found in */ export declare const getKeysWithNamespaces: ({ globPatterns, defaultNamespace, }: Pick<Configuration, "globPatterns" | "defaultNamespace">) => Promise<{ key: string; namespaces: string[]; file: string; }[]>; export declare const getMissingKeys: ({ globPatterns, namespaces, defaultNamespace, defaultLocale, loadPath, }: Configuration) => Promise<any[]>; /** * Find existing translation for a key across all namespaces */ export declare const findExistingTranslation: (key: string, namespaces: string[], locale: string, loadPath: string | ((locale: string, namespace: string) => Promise<Record<string, string>>)) => Promise<string | null>; /** * Find existing translations for multiple keys in parallel */ export declare const findExistingTranslations: (keys: string[], namespaces: string[], locale: string, loadPath: string | ((locale: string, namespace: string) => Promise<Record<string, string>>), options?: { silent?: boolean; }) => Promise<Record<string, string | null>>; export declare const getTextInput: (key: string, namespaces?: string[]) => Promise<string>; export declare const checkAllKeysExist: ({ namespaces, defaultLocale, loadPath, locales, context, openai, savePath, disableTranslationDuringScan, model, }: Configuration) => Promise<void>; export declare class TranslationError extends Error { locale?: string; namespace?: string; cause?: Error; constructor(message: string, locale?: string, namespace?: string, cause?: Error); } /** * Add a translation key with a value in a specific language to the locale files. * This function adds to the specified language locale, and will also translate * and save to other locales if OpenAI is configured. */ /** * Add multiple translation keys in batch. This is optimized for performance: * - Single codebase scan for all keys * - Batched file I/O operations * - Batched translations per locale */ export declare const addTranslationKeys: ({ keys, config, }: { keys: Array<{ key: string; value: string; language?: string; }>; config: Configuration; }) => Promise<{ results: { key: string; value: string; namespace: string; locale: string; }[]; performance: { totalTime: number; scanTime: number; translationTime: number; fileIOTime: number; }; }>; export declare const addTranslationKey: ({ key, value, language, config, }: { key: string; value: string; language?: string; config: Configuration; }) => Promise<{ key: string; value: string; namespace: string; locale: string; }>; //# sourceMappingURL=utils.d.ts.map