import i18n from 'i18next'; import { initReactI18next } from 'react-i18next'; import LanguageDetector from 'i18next-browser-languagedetector'; // 导入翻译文件 import zhHansTranslation from '../../data/zh-Hans/index.json'; import zhHantTranslation from '../../data/zh-Hant/index.json'; import enTranslation from '../../data/en/index.json'; // 导入数据文件 import zhHansAbout from '../../data/zh-Hans/about.json'; import zhHansProjects from '../../data/zh-Hans/projects.json'; import zhHansContributors from '../../data/zh-Hans/contributors.json'; import zhHansUpdates from '../../data/zh-Hans/updates.json'; import zhHantAbout from '../../data/zh-Hant/about.json'; import zhHantProjects from '../../data/zh-Hant/projects.json'; import zhHantContributors from '../../data/zh-Hant/contributors.json'; import zhHantUpdates from '../../data/zh-Hant/updates.json'; import enAbout from '../../data/en/about.json'; import enProjects from '../../data/en/projects.json'; import enContributors from '../../data/en/contributors.json'; import enUpdates from '../../data/en/updates.json'; i18n .use(LanguageDetector) .use(initReactI18next) .init({ resources: { 'zh-Hans': { translation: zhHansTranslation.translation }, 'zh-Hant': { translation: zhHantTranslation.translation }, 'en': { translation: enTranslation.translation } }, fallbackLng: 'zh-Hans', interpolation: { escapeValue: false, }, react: { useSuspense: false } }); // 添加数据命名空间 i18n.addResourceBundle('zh-Hans', 'translation', { data: { about: zhHansAbout, projects: zhHansProjects, contributors: zhHansContributors, updates: zhHansUpdates } }, true, true); i18n.addResourceBundle('zh-Hant', 'translation', { data: { about: zhHantAbout, projects: zhHantProjects, contributors: zhHantContributors, updates: zhHantUpdates } }, true, true); i18n.addResourceBundle('en', 'translation', { data: { about: enAbout, projects: enProjects, contributors: enContributors, updates: enUpdates } }, true, true); export default i18n;