translatinator
Version:
Automated translation management for web applications. Supports multiple translation engines (Google, DeepL, Yandex, LibreTranslate)
95 lines (90 loc) • 3.29 kB
TypeScript
type TranslationEngine = 'google' | 'yandex' | 'libre' | 'deepl';
interface TranslatinatorConfig {
/** Translation engine to use (default: 'google') */
engine?: TranslationEngine;
/** API key for the translation engine */
apiKey?: string;
/** Custom endpoint URL (for engines like LibreTranslate) */
endpointUrl?: string;
/** Source language file (default: 'en.json') */
sourceFile: string;
/** Target languages to translate to */
targetLanguages: string[];
/** Directory containing translation files (default: './locales') */
localesDir: string;
/** Enable file watching for automatic translation (default: false) */
watch?: boolean;
/** Force retranslation of all entries (default: false) */
force?: boolean;
/** Custom file naming pattern (default: '{lang}.json') */
filePattern?: string;
/** Preserve formatting and structure (default: true) */
preserveFormatting?: boolean;
/** Exclude specific keys from translation (supports dot notation) */
excludeKeys?: string[];
/** Cache directory for storing translation cache (default: '.translatinator-cache') */
cacheDir?: string;
/** Enable verbose logging (default: false) */
verbose?: boolean;
}
interface TranslationEntry {
original: string;
translated: string;
timestamp: number;
version: string;
}
interface TranslationCache {
[sourceText: string]: {
[targetLang: string]: TranslationEntry;
};
}
declare class Translatinator {
private config;
private translator;
private cache;
private logger;
private watcher?;
constructor(config: TranslatinatorConfig);
initialize(): Promise<void>;
translateAll(): Promise<void>;
private translateToLanguage;
private deepMerge;
private getMissingKeys;
startWatching(): Promise<void>;
stopWatching(): Promise<void>;
clearCache(): Promise<void>;
getUsageInfo(): Promise<any>;
}
declare class ConfigLoader {
static loadConfig(configPath?: string): Promise<TranslatinatorConfig>;
static createSampleConfig(outputPath?: string): Promise<void>;
}
declare function translate(configPath?: string): Promise<void>;
declare class TranslatinatorWebpackPlugin {
private config;
constructor(options?: any);
apply(compiler: any): void;
}
declare class TranslatinatorNextPlugin {
private config;
private translatinator?;
private watcher?;
private isInitialized;
constructor(options?: any);
apply(nextConfig?: any): any;
private setupDevModeTranslation;
private setupFileWatcher;
}
declare function withTranslatinator(options?: any): (nextConfig?: any) => any;
declare class TranslatinatorDevServer {
private config;
private translatinator?;
private watcher?;
private isRunning;
constructor(options?: any);
start(): Promise<void>;
stop(): Promise<void>;
private setupFileWatcher;
}
declare function withTranslatinatorDev(options?: any): (nextConfig?: any) => any;
export { ConfigLoader, Translatinator, type TranslatinatorConfig, TranslatinatorDevServer, TranslatinatorNextPlugin, TranslatinatorWebpackPlugin, type TranslationCache, type TranslationEngine, type TranslationEntry, translate, withTranslatinator, withTranslatinatorDev };