update for 1. 优化 2.中英切换
This commit is contained in:
36
frontend/src/contexts/LanguageContext.tsx
Normal file
36
frontend/src/contexts/LanguageContext.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
import React, { createContext, useContext, useState } from 'react';
|
||||
import { en } from '../locales/en';
|
||||
import type { Translations } from '../locales/en';
|
||||
import { zh } from '../locales/zh';
|
||||
|
||||
export type Lang = 'en' | 'zh';
|
||||
|
||||
interface LanguageContextValue {
|
||||
lang: Lang;
|
||||
t: Translations;
|
||||
toggleLang: () => void;
|
||||
}
|
||||
|
||||
const LanguageContext = createContext<LanguageContextValue>({
|
||||
lang: 'en',
|
||||
t: en,
|
||||
toggleLang: () => {},
|
||||
});
|
||||
|
||||
export function LanguageProvider({ children }: { children: React.ReactNode }) {
|
||||
const [lang, setLang] = useState<Lang>('en');
|
||||
|
||||
const toggleLang = () => setLang(l => (l === 'en' ? 'zh' : 'en'));
|
||||
|
||||
const t = lang === 'en' ? en : zh;
|
||||
|
||||
return (
|
||||
<LanguageContext.Provider value={{ lang, t, toggleLang }}>
|
||||
{children}
|
||||
</LanguageContext.Provider>
|
||||
);
|
||||
}
|
||||
|
||||
export function useLanguage() {
|
||||
return useContext(LanguageContext);
|
||||
}
|
||||
@@ -99,6 +99,10 @@ export interface ComplianceState {
|
||||
findings: ComplianceFindingEvent[];
|
||||
done: ComplianceDonePayload | null;
|
||||
errorText: string;
|
||||
// Direction B additions:
|
||||
analysisId: string | null;
|
||||
isReadOnly: boolean;
|
||||
activeFindingId: string | null;
|
||||
}
|
||||
|
||||
const COMPLIANCE_INIT: ComplianceState = {
|
||||
@@ -110,6 +114,9 @@ const COMPLIANCE_INIT: ComplianceState = {
|
||||
findings: [],
|
||||
done: null,
|
||||
errorText: '',
|
||||
analysisId: null,
|
||||
isReadOnly: false,
|
||||
activeFindingId: null,
|
||||
};
|
||||
|
||||
// ── Perception types ──────────────────────────────────────────────────────────
|
||||
|
||||
@@ -2,6 +2,8 @@ export { ThemeProvider, useTheme } from './ThemeContext';
|
||||
export { AuthProvider, useAuth } from './AuthContext';
|
||||
export type { AuthUser } from './AuthContext';
|
||||
export { PageStateProvider, usePageState } from './PageStateContext';
|
||||
export { LanguageProvider, useLanguage } from './LanguageContext';
|
||||
export type { Lang } from './LanguageContext';
|
||||
export type {
|
||||
RagChatState,
|
||||
RagMessage,
|
||||
|
||||
Reference in New Issue
Block a user