import React, { createContext, useContext, ReactNode } from 'react'; import { Language, Translation } from './types'; import { en } from './locales/en'; import { zh } from './locales/zh'; interface I18nContextType { language: Language; t: Translation; setLanguage: (lang: Language) => void; } const I18nContext = createContext(undefined); const translations: Record = { en, zh, }; interface I18nProviderProps { children: ReactNode; language: Language; onLanguageChange: (lang: Language) => void; } export const I18nProvider: React.FC = ({ children, language, onLanguageChange }) => { const t = translations[language]; return ( {children} ); }; export const useTranslation = () => { const context = useContext(I18nContext); if (!context) { throw new Error('useTranslation must be used within an I18nProvider'); } return context; };