diff --git a/apps/react/src/app/i18n/i18n.ts b/apps/react/src/app/i18n/i18n.ts new file mode 100644 index 000000000..dc512c1af --- /dev/null +++ b/apps/react/src/app/i18n/i18n.ts @@ -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 diff --git a/apps/react/src/main.tsx b/apps/react/src/main.tsx index e37672a01..b8d62e953 100644 --- a/apps/react/src/main.tsx +++ b/apps/react/src/main.tsx @@ -1,3 +1,4 @@ +import './app/i18n/i18n' import ReactDOM from 'react-dom/client' import App from './app/App' import './styles/index.scss'