diff --git a/lightrag_webui/src/App.tsx b/lightrag_webui/src/App.tsx index 0a2ec50f..80dd57a5 100644 --- a/lightrag_webui/src/App.tsx +++ b/lightrag_webui/src/App.tsx @@ -1,5 +1,4 @@ import { useState, useCallback } from 'react' -import ThemeProvider from '@/components/ThemeProvider' import MessageAlert from '@/components/MessageAlert' import ApiKeyAlert from '@/components/ApiKeyAlert' import StatusIndicator from '@/components/graph/StatusIndicator' @@ -52,7 +51,6 @@ function App() { }, [message, setApiKeyInvalid]) return ( -
} {apiKeyInvalid && }
-
) } diff --git a/lightrag_webui/src/AppRouter.tsx b/lightrag_webui/src/AppRouter.tsx index a28b57c9..0dfc9918 100644 --- a/lightrag_webui/src/AppRouter.tsx +++ b/lightrag_webui/src/AppRouter.tsx @@ -3,6 +3,7 @@ import { BrowserRouter, Routes, Route, Navigate } from 'react-router-dom' import { Toaster } from 'sonner' import App from './App' import LoginPage from '@/features/LoginPage' +import ThemeProvider from '@/components/ThemeProvider' interface ProtectedRouteProps { children: React.ReactNode @@ -20,20 +21,22 @@ const ProtectedRoute = ({ children }: ProtectedRouteProps) => { const AppRouter = () => { return ( - - - } /> - - - - } - /> - - - + + + + } /> + + + + } + /> + + + + ) } diff --git a/lightrag_webui/src/components/LanguageToggle.tsx b/lightrag_webui/src/components/LanguageToggle.tsx new file mode 100644 index 00000000..0eab780e --- /dev/null +++ b/lightrag_webui/src/components/LanguageToggle.tsx @@ -0,0 +1,49 @@ +import Button from '@/components/ui/Button' +import { useCallback } from 'react' +import { controlButtonVariant } from '@/lib/constants' +import { useTranslation } from 'react-i18next' +import { useSettingsStore } from '@/stores/settings' + +/** + * Component that toggles the language between English and Chinese. + */ +export default function LanguageToggle() { + const { i18n } = useTranslation() + const currentLanguage = i18n.language + const setLanguage = useSettingsStore.use.setLanguage() + + const setEnglish = useCallback(() => { + i18n.changeLanguage('en') + setLanguage('en') + }, [i18n, setLanguage]) + + const setChinese = useCallback(() => { + i18n.changeLanguage('zh') + setLanguage('zh') + }, [i18n, setLanguage]) + + if (currentLanguage === 'zh') { + return ( + + ) + } + return ( + + ) +} diff --git a/lightrag_webui/src/features/LoginPage.tsx b/lightrag_webui/src/features/LoginPage.tsx index ad0e6227..f72bafd2 100644 --- a/lightrag_webui/src/features/LoginPage.tsx +++ b/lightrag_webui/src/features/LoginPage.tsx @@ -3,15 +3,19 @@ import { useNavigate } from 'react-router-dom' import { useAuthStore } from '@/stores/state' import { loginToServer } from '@/api/lightrag' import { toast } from 'sonner' +import { useTranslation } from 'react-i18next' import { Card, CardContent, CardHeader } from '@/components/ui/Card' import Input from '@/components/ui/Input' import Button from '@/components/ui/Button' import { ZapIcon } from 'lucide-react' +import ThemeToggle from '@/components/ThemeToggle' +import LanguageToggle from '@/components/LanguageToggle' const LoginPage = () => { const navigate = useNavigate() const { login } = useAuthStore() + const { t } = useTranslation() const [loading, setLoading] = useState(false) const [username, setUsername] = useState('') const [password, setPassword] = useState('') @@ -19,7 +23,7 @@ const LoginPage = () => { const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() if (!username || !password) { - toast.error('Please enter your username and password') + toast.error(t('login.errorEmptyFields')) return } @@ -28,10 +32,10 @@ const LoginPage = () => { const response = await loginToServer(username, password) login(response.access_token) navigate('/') - toast.success('Login succeeded') + toast.success(t('login.successMessage')) } catch (error) { console.error('Login failed...', error) - toast.error('Login failed, please check username and password') + toast.error(t('login.errorInvalidCredentials')) } finally { setLoading(false) } @@ -39,6 +43,10 @@ const LoginPage = () => { return (
+
+ + +
@@ -49,7 +57,7 @@ const LoginPage = () => {

LightRAG

- Please enter your account and password to log in to the system + {t('login.description')}

@@ -58,11 +66,11 @@ const LoginPage = () => {
setUsername(e.target.value)} required @@ -71,12 +79,12 @@ const LoginPage = () => {
setPassword(e.target.value)} required @@ -88,7 +96,7 @@ const LoginPage = () => { className="w-full h-11 text-base font-medium mt-2" disabled={loading} > - {loading ? 'Logging in...' : 'Login'} + {loading ? t('login.loggingIn') : t('login.loginButton')} diff --git a/lightrag_webui/src/features/SiteHeader.tsx b/lightrag_webui/src/features/SiteHeader.tsx index f85d6251..121c43af 100644 --- a/lightrag_webui/src/features/SiteHeader.tsx +++ b/lightrag_webui/src/features/SiteHeader.tsx @@ -1,6 +1,7 @@ import Button from '@/components/ui/Button' import { SiteInfo } from '@/lib/constants' import ThemeToggle from '@/components/ThemeToggle' +import LanguageToggle from '@/components/LanguageToggle' import { TabsList, TabsTrigger } from '@/components/ui/Tabs' import { useSettingsStore } from '@/stores/settings' import { useAuthStore } from '@/stores/state' @@ -82,6 +83,7 @@ export default function SiteHeader() {