LoVisual/frontend/src/app/i18n.ts
loki5512344 fd2e29cede
feat(frontend): avatar upload QOL — feedback, re-crop, drop, progress, history
Task 12 batch around the existing crop/preview flow:
- Success Notice (auto-dismiss ~2.5s) after an avatar upload.
- "Reposition" re-crops the current avatar without re-picking a file.
- Drag & drop an image straight onto the profile avatar circle.
- Real upload progress via a new XHR-backed api.upload (fetch has none);
  refreshOnce now also stores the renewed token (reload-restore fix).
- Local avatar history (last 5, IndexedDB, this-device-only) strip that
  re-uploads a stored crop. Stored as ArrayBuffer (Blob is not cloneable
  under structuredClone); label makes the per-device scope explicit.
- Added a "success" tone to Notice.

Infra (same session): registered @shared/@features/@pages/@app/@test path
aliases in vite.config + tsconfigs and rewrote deep ../../../ imports;
moved avatar components into components/avatar/ to keep folders at <=4 files.

Tests: avatarHistory cap/order, recrop visibility, drop-opens-cropper,
client upload/progress/401-retry. bun test 103 pass, lint 0 errors, build ok.
2026-09-28 22:56:01 +02:00

79 lines
3 KiB
TypeScript

import i18next, { type i18n } from 'i18next'
import LanguageDetector from 'i18next-browser-languagedetector'
import { initReactI18next } from 'react-i18next'
import { accountEn } from '@features/account/i18n/en'
import { accountRu } from '@features/account/i18n/ru'
import { authEn } from '@features/auth/i18n/en'
import { authRu } from '@features/auth/i18n/ru'
import { clickguiEn } from '@features/clickgui/i18n/en'
import { configsEn } from '@features/configs/i18n/en'
import { clickguiRu } from '@features/clickgui/i18n/ru'
import { configsRu } from '@features/configs/i18n/ru'
import { deviceLinkEn } from '@features/device-link/i18n/en'
import { deviceLinkRu } from '@features/device-link/i18n/ru'
import { downloadEn } from '@features/download/i18n/en'
import { profileEn } from '@features/profile/i18n/en'
import { profileRu } from '@features/profile/i18n/ru'
import { showcaseEn } from '@features/showcase/i18n/en'
import { downloadRu } from '@features/download/i18n/ru'
import { showcaseRu } from '@features/showcase/i18n/ru'
import { landingEn } from '@features/landing/i18n/en'
import { landingRu } from '@features/landing/i18n/ru'
import { themesEn } from '@features/themes/i18n/en'
import { themesRu } from '@features/themes/i18n/ru'
import { commonEn } from '@shared/i18n/common.en'
import { commonRu } from '@shared/i18n/common.ru'
/** Creates and initializes an i18next instance. Each call is independent, so tests can run in isolation. */
export function initI18n(lng?: 'ru' | 'en'): i18n {
const instance = i18next.createInstance()
instance
.use(LanguageDetector)
.use(initReactI18next)
.init({
lng,
resources: {
ru: {
common: commonRu,
auth: authRu,
landing: landingRu,
themes: themesRu,
clickgui: clickguiRu,
download: downloadRu,
deviceLink: deviceLinkRu,
account: accountRu,
configs: configsRu,
showcase: showcaseRu,
profile: profileRu,
},
en: {
common: commonEn,
auth: authEn,
landing: landingEn,
themes: themesEn,
clickgui: clickguiEn,
download: downloadEn,
deviceLink: deviceLinkEn,
account: accountEn,
configs: configsEn,
showcase: showcaseEn,
profile: profileEn,
},
},
// Browser language decides the default: only an actual `ru` locale gets Russian,
// every other system language falls back to English.
fallbackLng: 'en',
supportedLngs: ['ru', 'en'],
ns: ['common', 'auth', 'landing', 'themes', 'clickgui', 'download', 'deviceLink', 'account', 'configs', 'showcase', 'profile'],
defaultNS: 'common',
interpolation: { escapeValue: false },
detection: { order: ['localStorage', 'navigator'], caches: ['localStorage'], lookupLocalStorage: 'lv_lang' },
})
document.documentElement.lang = instance.language
instance.on('languageChanged', (next) => {
document.documentElement.lang = next
})
return instance
}