48 lines
1.3 KiB
TypeScript
48 lines
1.3 KiB
TypeScript
import i18n from 'i18next';
|
|
import { initReactI18next } from 'react-i18next';
|
|
import {
|
|
SUPPORTED_LANGUAGE_CODES,
|
|
resolveSupportedLanguage,
|
|
type LanguageCode,
|
|
} from '../../shared/language';
|
|
|
|
// ZH
|
|
import zhCommon from './locales/zh/common.json';
|
|
import zhSettings from './locales/zh/settings.json';
|
|
import zhChat from './locales/zh/chat.json';
|
|
import zhSetup from './locales/zh/setup.json';
|
|
import zhDashboard from './locales/zh/dashboard.json';
|
|
|
|
export const SUPPORTED_LANGUAGES = [
|
|
{ code: 'zh', label: '中文' },
|
|
] as const satisfies ReadonlyArray<{ code: LanguageCode; label: string }>;
|
|
|
|
const resources = {
|
|
zh: {
|
|
common: zhCommon,
|
|
settings: zhSettings,
|
|
chat: zhChat,
|
|
setup: zhSetup,
|
|
dashboard: zhDashboard,
|
|
},
|
|
};
|
|
|
|
i18n
|
|
.use(initReactI18next)
|
|
.init({
|
|
resources,
|
|
lng: resolveSupportedLanguage(typeof navigator !== 'undefined' ? navigator.language : undefined),
|
|
fallbackLng: 'zh',
|
|
supportedLngs: [...SUPPORTED_LANGUAGE_CODES],
|
|
defaultNS: 'common',
|
|
ns: ['common', 'settings', 'chat', 'setup', 'dashboard'],
|
|
interpolation: {
|
|
escapeValue: false, // React already escapes
|
|
},
|
|
react: {
|
|
useSuspense: false,
|
|
},
|
|
});
|
|
|
|
export default i18n;
|