chore: setup i18next configuration with 9 language support
This commit is contained in:
@@ -0,0 +1,43 @@
|
|||||||
|
import i18n from 'i18next'
|
||||||
|
import HttpBackend from 'i18next-http-backend'
|
||||||
|
import { initReactI18next } from 'react-i18next'
|
||||||
|
|
||||||
|
// Language detection logic (simplified without additional dependency)
|
||||||
|
const getInitialLanguage = (): string => {
|
||||||
|
// Try to get from localStorage
|
||||||
|
const stored = localStorage.getItem('i18nextLng')
|
||||||
|
if (stored) return stored
|
||||||
|
|
||||||
|
// Try to get from navigator
|
||||||
|
const nav = navigator.language || (navigator as any).userLanguage
|
||||||
|
const userLang = nav.split('-')[0]
|
||||||
|
|
||||||
|
// Check if user language is supported
|
||||||
|
const supportedLanguages = ['ru', 'en', 'es', 'fr', 'it', 'ja', 'ko', 'de', 'zh']
|
||||||
|
if (supportedLanguages.includes(userLang)) {
|
||||||
|
return userLang
|
||||||
|
}
|
||||||
|
|
||||||
|
// Default to Russian
|
||||||
|
return 'ru'
|
||||||
|
}
|
||||||
|
|
||||||
|
i18n
|
||||||
|
.use(HttpBackend)
|
||||||
|
.use(initReactI18next)
|
||||||
|
.init({
|
||||||
|
fallbackLng: 'ru',
|
||||||
|
lng: getInitialLanguage(),
|
||||||
|
detection: {
|
||||||
|
order: ['localStorage', 'navigator'],
|
||||||
|
caches: ['localStorage'],
|
||||||
|
},
|
||||||
|
backend: {
|
||||||
|
loadPath: '/assets/i18n/{{lng}}.json',
|
||||||
|
},
|
||||||
|
interpolation: {
|
||||||
|
escapeValue: false,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export default i18n
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import './app/i18n/i18n'
|
||||||
import ReactDOM from 'react-dom/client'
|
import ReactDOM from 'react-dom/client'
|
||||||
import App from './app/App'
|
import App from './app/App'
|
||||||
import './styles/index.scss'
|
import './styles/index.scss'
|
||||||
|
|||||||
Reference in New Issue
Block a user