47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import i18n from 'i18next';
|
|
import { initReactI18next } from 'react-i18next';
|
|
|
|
import enTranslations from '@/locales/en.json';
|
|
import esTranslations from '@/locales/es.json';
|
|
import frTranslations from '@/locales/fr.json';
|
|
import deTranslations from '@/locales/de.json';
|
|
import zhTranslations from '@/locales/zh.json';
|
|
import jaTranslations from '@/locales/ja.json';
|
|
|
|
export const languages = {
|
|
en: { name: 'English', flag: '🇬🇧' },
|
|
es: { name: 'Español', flag: '🇪🇸' },
|
|
fr: { name: 'Français', flag: '🇫🇷' },
|
|
de: { name: 'Deutsch', flag: '🇩🇪' },
|
|
zh: { name: '中文', flag: '🇨🇳' },
|
|
ja: { name: '日本語', flag: '🇯🇵' },
|
|
} as const;
|
|
|
|
export type Language = keyof typeof languages;
|
|
|
|
const resources = {
|
|
en: { translation: enTranslations },
|
|
es: { translation: esTranslations },
|
|
fr: { translation: frTranslations },
|
|
de: { translation: deTranslations },
|
|
zh: { translation: zhTranslations },
|
|
ja: { translation: jaTranslations },
|
|
};
|
|
|
|
// Initialize i18next
|
|
i18n
|
|
.use(initReactI18next)
|
|
.init({
|
|
resources,
|
|
lng: typeof window !== 'undefined' ? localStorage.getItem('language') || 'en' : 'en',
|
|
fallbackLng: 'en',
|
|
interpolation: {
|
|
escapeValue: false, // React already escapes values
|
|
},
|
|
react: {
|
|
useSuspense: false, // Disable suspense for client-side only
|
|
},
|
|
});
|
|
|
|
export default i18n;
|