403dc01708
- Update i18n language detection to extract language code from URL (/ru-ru/ → 'ru') - Move public assets to src/public/ to match Vite root directory - Add missing translation keys: SHARED.DATE, SHARED.FROM, SHARED.TO, SHARED.DEPARTURE, SHARED.ROUTE - Fix router configuration to use relative paths for language-prefixed routes - App now loads at /ru-ru/onlineboard with full Russian translations
67 lines
1.7 KiB
TypeScript
67 lines
1.7 KiB
TypeScript
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 URL path (:lang parameter)
|
|
const pathLang = window.location.pathname.split('/')[1]
|
|
const supportedLanguages = ['ru', 'en', 'es', 'fr', 'it', 'ja', 'ko', 'de', 'zh']
|
|
|
|
// Handle locale codes like ru-ru, en-us, etc.
|
|
const langCode = pathLang?.split('-')[0]
|
|
if (supportedLanguages.includes(langCode)) {
|
|
return langCode
|
|
}
|
|
|
|
if (supportedLanguages.includes(pathLang)) {
|
|
return pathLang
|
|
}
|
|
|
|
// Try to get from navigator
|
|
const nav = navigator.language || (navigator as any).userLanguage
|
|
const userLang = nav.split('-')[0]
|
|
|
|
// Check if user language is supported
|
|
if (supportedLanguages.includes(userLang)) {
|
|
return userLang
|
|
}
|
|
|
|
// Default to Russian
|
|
return 'ru'
|
|
}
|
|
|
|
i18n
|
|
.use(HttpBackend)
|
|
.use(initReactI18next)
|
|
.init({
|
|
fallbackLng: 'ru',
|
|
lng: getInitialLanguage(),
|
|
defaultNS: 'translation',
|
|
ns: ['translation'],
|
|
detection: {
|
|
order: ['localStorage', 'navigator'],
|
|
caches: ['localStorage'],
|
|
},
|
|
backend: {
|
|
loadPath: '/assets/i18n/{{lng}}.json',
|
|
},
|
|
interpolation: {
|
|
escapeValue: false,
|
|
},
|
|
react: {
|
|
useSuspense: false,
|
|
bindI18n: 'languageChanged loaded',
|
|
bindI18nStore: 'added removed',
|
|
transEmptyNodeValue: '',
|
|
transSupportBasicHtmlNodes: true,
|
|
},
|
|
nonExplicitSupportedLngs: true,
|
|
})
|
|
|
|
export default i18n
|