68 lines
2.2 KiB
TypeScript
68 lines
2.2 KiB
TypeScript
'use client';
|
||
|
||
import i18n from 'i18next';
|
||
import { initReactI18next } from 'react-i18next';
|
||
|
||
// 导入翻译文件
|
||
import commonZhCN from '@/translations/common/zh-CN.json';
|
||
import commonZhTW from '@/translations/common/zh-TW.json';
|
||
import commonEn from '@/translations/common/en.json';
|
||
|
||
import newsZhCN from '@/translations/news/zh-CN.json';
|
||
import newsZhTW from '@/translations/news/zh-TW.json';
|
||
import newsEn from '@/translations/news/en.json';
|
||
|
||
import articleZhCN from '@/translations/article/zh-CN.json';
|
||
import articleZhTW from '@/translations/article/zh-TW.json';
|
||
import articleEn from '@/translations/article/en.json';
|
||
|
||
import consultationZhCN from '@/translations/consultation/zh-CN.json';
|
||
import consultationZhTW from '@/translations/consultation/zh-TW.json';
|
||
import consultationEn from '@/translations/consultation/en.json';
|
||
|
||
import contactZhCN from '@/translations/contact/zh-CN.json';
|
||
import contactZhTW from '@/translations/contact/zh-TW.json';
|
||
import contactEn from '@/translations/contact/en.json';
|
||
|
||
// 配置 i18next
|
||
const i18nInstance = i18n.createInstance();
|
||
|
||
i18nInstance
|
||
.use(initReactI18next)
|
||
.init({
|
||
resources: {
|
||
'zh-CN': {
|
||
common: commonZhCN,
|
||
news: newsZhCN,
|
||
article: articleZhCN,
|
||
consultation: consultationZhCN,
|
||
contact: contactZhCN,
|
||
},
|
||
'zh-TW': {
|
||
common: commonZhTW,
|
||
news: newsZhTW,
|
||
article: articleZhTW,
|
||
consultation: consultationZhTW,
|
||
contact: contactZhTW,
|
||
},
|
||
'en': {
|
||
common: commonEn,
|
||
news: newsEn,
|
||
article: articleEn,
|
||
consultation: consultationEn,
|
||
contact: contactEn,
|
||
},
|
||
},
|
||
lng: 'zh-CN', // 默认语言
|
||
fallbackLng: 'zh-CN', // 回退语言
|
||
ns: ['common', 'news', 'article', 'consultation', 'contact'], // 命名空间
|
||
defaultNS: 'common',
|
||
interpolation: {
|
||
escapeValue: false, // React 已经处理了 XSS
|
||
},
|
||
react: {
|
||
useSuspense: false, // 禁用 Suspense,避免客户端水合问题
|
||
},
|
||
});
|
||
|
||
export default i18nInstance;
|