/** * i18next Configuration for Gating System * * Supports all 32 Tavus languages with ISO 639-1 codes. * Default translations provided, customers can override specific keys. */ import i18next from 'i18next'; import type { GatingLanguage } from '../types/gating'; import { translations } from './translations'; /** * Initialize i18next with gating translations * * @param language - ISO 639-1 language code * @param customTranslations - Optional custom translation overrides */ export async function initGatingI18n( language: GatingLanguage = 'en', customTranslations?: Record> ): Promise { await i18next.init({ lng: language, fallbackLng: 'en', debug: false, resources: translations, interpolation: { escapeValue: false, // React already escapes values }, }); // Apply custom translation overrides if provided if (customTranslations) { Object.entries(customTranslations).forEach(([key, value]) => { i18next.addResource(language, 'translation', key, value); }); } } /** * Get translated string for current language * * @param key - Translation key (e.g., 'form.title') * @param options - Interpolation options * @returns Translated string * * @example * ```typescript * t('form.title'); // "Get Started" * t('form.errors.required', { field: 'Email' }); // "Email is required" * ``` */ export function t(key: string, options?: Record): string { return i18next.t(key, options); } /** * Change language at runtime * * @param language - ISO 639-1 language code */ export async function changeLanguage(language: GatingLanguage): Promise { await i18next.changeLanguage(language); } /** * Get current language */ export function getCurrentLanguage(): string { return i18next.language; }