Files
homaroma/apps/website/src/lib/i18n.ts
T
2026-06-17 08:34:58 -04:00

36 lines
1.2 KiB
TypeScript

import i18n from 'i18next'
import { initReactI18next } from 'react-i18next'
import enTranslation from '../locales/en/translation.json'
import thTranslation from '../locales/th/translation.json'
import jaTranslation from '../locales/ja/translation.json'
import zhTranslation from '../locales/zh/translation.json'
import viTranslation from '../locales/vi/translation.json'
import koTranslation from '../locales/ko/translation.json'
// Ensure we only access localStorage on the client side
const savedLang = typeof window !== 'undefined' ? (localStorage.getItem('homaroma_lang') || 'th') : 'th'
// Check if it's already initialized to prevent re-initialization on HMR
if (!i18n.isInitialized) {
i18n
.use(initReactI18next)
.init({
resources: {
en: { translation: enTranslation },
th: { translation: thTranslation },
ja: { translation: jaTranslation },
zh: { translation: zhTranslation },
vi: { translation: viTranslation },
ko: { translation: koTranslation },
},
lng: savedLang, // default language
fallbackLng: 'en',
interpolation: {
escapeValue: false, // react already safes from xss
},
})
}
export default i18n