UNPKG

ai-i18n-translator

Version:

AI-powered i18n auto-translation tool with pluggable extractors, translators, and organizers

56 lines (46 loc) 1.27 kB
import I18nWrapper from '../core/i18n-wrapper.js'; let globalWrapper = null; export function initWithI18next(tFunction) { globalWrapper = new I18nWrapper(tFunction); return globalWrapper; } export function t2(key, options = {}) { if (!globalWrapper) { throw new Error('Not initialized. Call initWithI18next(t) first with your i18next t function.'); } return globalWrapper.t2(key, options); } export function exportKeysForTranslation() { if (!globalWrapper) { return {}; } return globalWrapper.exportKeysForTranslation(); } export function clearExtractedKeys() { if (globalWrapper) { globalWrapper.clearExtractedKeys(); } } export function getExtractedKeys() { if (!globalWrapper) { return []; } return globalWrapper.getExtractedKeys(); } export function createWrapper(tFunction) { const wrapper = new I18nWrapper(tFunction); return { t2: (key, options = {}) => wrapper.t2(key, options), exportKeysForTranslation: () => wrapper.exportKeysForTranslation(), clearExtractedKeys: () => wrapper.clearExtractedKeys(), getExtractedKeys: () => wrapper.getExtractedKeys() }; } export default { initWithI18next, t2, exportKeysForTranslation, clearExtractedKeys, getExtractedKeys, createWrapper };