signal-batch/frontend/src/i18n/I18nContext.tsx
htlee dd694bdcbb feat: React 19 SPA Dashboard Phase 1 + 안전 배포 시스템
## React SPA Dashboard
- React 19 + Vite 7 + Tailwind CSS 4 + Recharts 2 SPA 구축
- Dashboard (배치현황/시스템메트릭/캐시/처리량) + JobMonitor (이력조회/Step상세)
- i18n 다국어(ko/en) 시스템, Light/Dark 테마 CSS 토큰 전환
- frontend-maven-plugin 1.15.1 (mvn package 시 자동 빌드)
- WebViewController SPA forward + context-path /signal-batch
- 레거시 HTML 48개 파일 전체 삭제

## 안전 배포
- VesselBatchScheduler @PreDestroy: 신규 Job 차단 + 실행 중 Job 완료 대기
- server.shutdown=graceful, timeout-per-shutdown-phase=3m
- deploy.yml: 활성 Job 3초 연속 확인 후 stop → 교체 → start
- signal-batch.service TimeoutStopSec 60→180
- scripts/deploy.sh: 수동 배포용 안전 스크립트

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-19 17:05:38 +09:00

57 lines
1.5 KiB
TypeScript

import { createContext, useCallback, useEffect, useState, type ReactNode } from 'react'
import ko from './ko.ts'
import en from './en.ts'
export type Locale = 'ko' | 'en'
export type TranslationKey = keyof typeof ko
const TRANSLATIONS: Record<Locale, Record<string, string>> = { ko, en }
const STORAGE_KEY = 'sb-locale'
function getInitialLocale(): Locale {
const stored = localStorage.getItem(STORAGE_KEY)
if (stored === 'ko' || stored === 'en') return stored
const browserLang = navigator.language.slice(0, 2)
return browserLang === 'ko' ? 'ko' : 'en'
}
interface I18nContextValue {
locale: Locale
setLocale: (locale: Locale) => void
toggleLocale: () => void
t: (key: TranslationKey) => string
}
export const I18nContext = createContext<I18nContextValue>({
locale: 'ko',
setLocale: () => {},
toggleLocale: () => {},
t: (key) => key,
})
export function I18nProvider({ children }: { children: ReactNode }) {
const [locale, setLocaleState] = useState<Locale>(getInitialLocale)
useEffect(() => {
localStorage.setItem(STORAGE_KEY, locale)
document.documentElement.lang = locale
}, [locale])
const setLocale = useCallback((l: Locale) => setLocaleState(l), [])
const toggleLocale = useCallback(() => {
setLocaleState(prev => (prev === 'ko' ? 'en' : 'ko'))
}, [])
const t = useCallback(
(key: TranslationKey): string => TRANSLATIONS[locale][key] ?? key,
[locale],
)
return (
<I18nContext value={{ locale, setLocale, toggleLocale, t }}>
{children}
</I18nContext>
)
}