revert to http backend for i18n loading; static imports not working properly

This commit is contained in:
gnezim
2026-04-06 09:58:45 +03:00
parent e12c93922b
commit d0a0db5c75
+5 -23
View File
@@ -1,6 +1,6 @@
import i18n from 'i18next'
import HttpBackend from 'i18next-http-backend'
import { initReactI18next } from 'react-i18next'
import { translations } from './translations'
// Language detection logic
const getInitialLanguage = (): string => {
@@ -29,37 +29,19 @@ const getInitialLanguage = (): string => {
return 'ru'
}
// Flatten nested JSON structure
const flattenTranslations = (obj: any, prefix = ''): any => {
const result: any = {}
for (const [key, value] of Object.entries(obj)) {
const fullKey = prefix ? `${prefix}.${key}` : key
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
Object.assign(result, flattenTranslations(value, fullKey))
} else {
result[fullKey] = value
}
}
return result
}
const lng = getInitialLanguage()
// Build resources object with static translations
const resources: Record<string, any> = {}
for (const [lang, translationData] of Object.entries(translations)) {
resources[lang] = { translation: flattenTranslations(translationData as any) }
}
// Initialize i18next with bundled translations
i18n
.use(HttpBackend)
.use(initReactI18next)
.init({
fallbackLng: 'ru',
lng,
defaultNS: 'translation',
ns: ['translation'],
resources,
backend: {
loadPath: '/assets/i18n/{{lng}}.json',
},
interpolation: {
escapeValue: false,
},