Merge pull request #1152 from danielaskdd/i18n-france-arabic

Add Arabic and French selection to app settings
This commit is contained in:
Daniel.y
2025-03-22 00:44:51 +08:00
committed by GitHub
10 changed files with 263 additions and 160 deletions

File diff suppressed because one or more lines are too long

View File

@@ -8,7 +8,7 @@
<link rel="icon" type="image/svg+xml" href="logo.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Lightrag</title>
<script type="module" crossorigin src="/webui/assets/index-C-CHRwmZ.js"></script>
<script type="module" crossorigin src="/webui/assets/index-BItOVH8B.js"></script>
<link rel="stylesheet" crossorigin href="/webui/assets/index-BViPRMGA.css">
</head>
<body>

View File

@@ -38,11 +38,14 @@ from lightrag.utils import (
)
from lightrag.api import __api_version__
# Custom exception for retry mechanism
class InvalidResponseError(Exception):
"""Custom exception class for triggering retry mechanism"""
pass
# Core Anthropic completion function with retry
@retry(
stop=stop_after_attempt(3),
@@ -96,10 +99,7 @@ async def anthropic_complete_if_cache(
try:
response = await anthropic_async_client.messages.create(
model=model,
messages=messages,
stream=True,
**kwargs
model=model, messages=messages, stream=True, **kwargs
)
except APIConnectionError as e:
logger.error(f"Anthropic API Connection Error: {e}")
@@ -119,7 +119,11 @@ async def anthropic_complete_if_cache(
async def stream_response():
try:
async for event in response:
content = event.delta.text if hasattr(event, "delta") and event.delta.text else None
content = (
event.delta.text
if hasattr(event, "delta") and event.delta.text
else None
)
if content is None:
continue
if r"\u" in content:
@@ -131,6 +135,7 @@ async def anthropic_complete_if_cache(
return stream_response()
# Generic Anthropic completion function
async def anthropic_complete(
prompt: str,
@@ -149,6 +154,7 @@ async def anthropic_complete(
**kwargs,
)
# Claude 3 Opus specific completion
async def claude_3_opus_complete(
prompt: str,
@@ -166,6 +172,7 @@ async def claude_3_opus_complete(
**kwargs,
)
# Claude 3 Sonnet specific completion
async def claude_3_sonnet_complete(
prompt: str,
@@ -183,6 +190,7 @@ async def claude_3_sonnet_complete(
**kwargs,
)
# Claude 3 Haiku specific completion
async def claude_3_haiku_complete(
prompt: str,
@@ -200,6 +208,7 @@ async def claude_3_haiku_complete(
**kwargs,
)
# Embedding function (placeholder, as Anthropic does not provide embeddings)
@retry(
stop=stop_after_attempt(3),
@@ -230,7 +239,9 @@ async def anthropic_embed(
api_key = os.environ.get("VOYAGE_API_KEY")
if not api_key:
logger.error("VOYAGE_API_KEY environment variable not set")
raise ValueError("VOYAGE_API_KEY environment variable is required for embeddings")
raise ValueError(
"VOYAGE_API_KEY environment variable is required for embeddings"
)
try:
# Initialize Voyage AI client
@@ -240,7 +251,7 @@ async def anthropic_embed(
result = voyage_client.embed(
texts,
model=model,
input_type="document" # Assuming document context; could be made configurable
input_type="document", # Assuming document context; could be made configurable
)
# Convert list of embeddings to numpy array
@@ -255,17 +266,46 @@ async def anthropic_embed(
logger.error(f"Voyage AI embedding failed: {str(e)}")
raise
# Optional: a helper function to get available embedding models
def get_available_embedding_models() -> dict[str, dict]:
"""
Returns a dictionary of available Voyage AI embedding models and their properties.
"""
return {
"voyage-3-large": {"context_length": 32000, "dimension": 1024, "description": "Best general-purpose and multilingual"},
"voyage-3": {"context_length": 32000, "dimension": 1024, "description": "General-purpose and multilingual"},
"voyage-3-lite": {"context_length": 32000, "dimension": 512, "description": "Optimized for latency and cost"},
"voyage-code-3": {"context_length": 32000, "dimension": 1024, "description": "Optimized for code"},
"voyage-finance-2": {"context_length": 32000, "dimension": 1024, "description": "Optimized for finance"},
"voyage-law-2": {"context_length": 16000, "dimension": 1024, "description": "Optimized for legal"},
"voyage-multimodal-3": {"context_length": 32000, "dimension": 1024, "description": "Multimodal text and images"},
"voyage-3-large": {
"context_length": 32000,
"dimension": 1024,
"description": "Best general-purpose and multilingual",
},
"voyage-3": {
"context_length": 32000,
"dimension": 1024,
"description": "General-purpose and multilingual",
},
"voyage-3-lite": {
"context_length": 32000,
"dimension": 512,
"description": "Optimized for latency and cost",
},
"voyage-code-3": {
"context_length": 32000,
"dimension": 1024,
"description": "Optimized for code",
},
"voyage-finance-2": {
"context_length": 32000,
"dimension": 1024,
"description": "Optimized for finance",
},
"voyage-law-2": {
"context_length": 16000,
"dimension": 1024,
"description": "Optimized for legal",
},
"voyage-multimodal-3": {
"context_length": 32000,
"dimension": 1024,
"description": "Multimodal text and images",
},
}

View File

@@ -22,7 +22,7 @@ export default function AppSettings({ className }: AppSettingsProps) {
const setTheme = useSettingsStore.use.setTheme()
const handleLanguageChange = useCallback((value: string) => {
setLanguage(value as 'en' | 'zh')
setLanguage(value as 'en' | 'zh' | 'fr' | 'ar')
}, [setLanguage])
const handleThemeChange = useCallback((value: string) => {
@@ -47,6 +47,8 @@ export default function AppSettings({ className }: AppSettingsProps) {
<SelectContent>
<SelectItem value="en">English</SelectItem>
<SelectItem value="zh"></SelectItem>
<SelectItem value="fr">Français</SelectItem>
<SelectItem value="ar">العربية</SelectItem>
</SelectContent>
</Select>
</div>

View File

@@ -1,35 +0,0 @@
import i18n from "i18next";
import { initReactI18next } from "react-i18next";
import { useSettingsStore } from "./stores/settings";
import en from "./locales/en.json";
import zh from "./locales/zh.json";
const getStoredLanguage = () => {
try {
const settingsString = localStorage.getItem('settings-storage');
if (settingsString) {
const settings = JSON.parse(settingsString);
return settings.state?.language || 'en';
}
} catch (e) {
console.error('Failed to get stored language:', e);
}
return 'en';
};
i18n
.use(initReactI18next)
.init({
resources: {
en: { translation: en },
zh: { translation: zh }
},
lng: getStoredLanguage(), // 使用存储的语言设置
fallbackLng: "en",
interpolation: {
escapeValue: false
}
});
export default i18n;

View File

@@ -4,34 +4,44 @@ import { useSettingsStore } from '@/stores/settings'
import en from './locales/en.json'
import zh from './locales/zh.json'
import fr from './locales/fr.json'
import ar from './locales/ar.json'
// Function to sync i18n with store state
export const initializeI18n = async (): Promise<typeof i18n> => {
// Get initial language from store
const initialLanguage = useSettingsStore.getState().language
const getStoredLanguage = () => {
try {
const settingsString = localStorage.getItem('settings-storage')
if (settingsString) {
const settings = JSON.parse(settingsString)
return settings.state?.language || 'en'
}
} catch (e) {
console.error('Failed to get stored language:', e)
}
return 'en'
}
// Initialize with store language
await i18n.use(initReactI18next).init({
i18n
.use(initReactI18next)
.init({
resources: {
en: { translation: en },
zh: { translation: zh }
zh: { translation: zh },
fr: { translation: fr },
ar: { translation: ar }
},
lng: initialLanguage,
lng: getStoredLanguage(), // 使用存储的语言设置
fallbackLng: 'en',
interpolation: {
escapeValue: false
}
})
// Subscribe to language changes
useSettingsStore.subscribe((state) => {
const currentLanguage = state.language
if (i18n.language !== currentLanguage) {
i18n.changeLanguage(currentLanguage)
}
})
return i18n
}
// Subscribe to language changes
useSettingsStore.subscribe((state) => {
const currentLanguage = state.language
if (i18n.language !== currentLanguage) {
i18n.changeLanguage(currentLanguage)
}
})
export default i18n

View File

@@ -12,11 +12,26 @@
"retrieval": "الاسترجاع",
"api": "واجهة برمجة التطبيقات",
"projectRepository": "مستودع المشروع",
"logout": "تسجيل الخروج",
"themeToggle": {
"switchToLight": "التحويل إلى السمة الفاتحة",
"switchToDark": "التحويل إلى السمة الداكنة"
}
},
"login": {
"description": "الرجاء إدخال حسابك وكلمة المرور لتسجيل الدخول إلى النظام",
"username": "اسم المستخدم",
"usernamePlaceholder": "الرجاء إدخال اسم المستخدم",
"password": "كلمة المرور",
"passwordPlaceholder": "الرجاء إدخال كلمة المرور",
"loginButton": "تسجيل الدخول",
"loggingIn": "جاري تسجيل الدخول...",
"successMessage": "تم تسجيل الدخول بنجاح",
"errorEmptyFields": "الرجاء إدخال اسم المستخدم وكلمة المرور",
"errorInvalidCredentials": "فشل تسجيل الدخول، يرجى التحقق من اسم المستخدم وكلمة المرور",
"authDisabled": "تم تعطيل المصادقة. استخدام وضع بدون تسجيل دخول.",
"guestMode": "وضع بدون تسجيل دخول"
},
"documentPanel": {
"clearDocuments": {
"button": "مسح",
@@ -96,7 +111,9 @@
"zoomControl": {
"zoomIn": "تكبير",
"zoomOut": "تصغير",
"resetZoom": "إعادة تعيين التكبير"
"resetZoom": "إعادة تعيين التكبير",
"rotateCamera": "تدوير في اتجاه عقارب الساعة",
"rotateCameraCounterClockwise": "تدوير عكس اتجاه عقارب الساعة"
},
"layoutsControl": {
"startAnimation": "بدء حركة التخطيط",
@@ -148,6 +165,11 @@
"degree": "الدرجة",
"properties": "الخصائص",
"relationships": "العلاقات",
"expandNode": "توسيع العقدة",
"pruneNode": "تقليم العقدة",
"deleteAllNodesError": "رفض حذف جميع العقد في الرسم البياني",
"nodesRemoved": "تم إزالة {{count}} عقدة، بما في ذلك العقد اليتيمة",
"noNewNodes": "لم يتم العثور على عقد قابلة للتوسيع",
"propertyNames": {
"description": "الوصف",
"entity_id": "الاسم",
@@ -174,8 +196,10 @@
"noLabels": "لم يتم العثور على تسميات",
"label": "التسمية",
"placeholder": "ابحث في التسميات...",
"andOthers": "و {{count}} آخرون"
}
"andOthers": "و {{count}} آخرون",
"refreshTooltip": "إعادة تحميل بيانات الرسم البياني"
},
"emptyGraph": "الرسم البياني فارغ"
},
"retrievePanel": {
"chatMessage": {

View File

@@ -12,11 +12,26 @@
"retrieval": "Récupération",
"api": "API",
"projectRepository": "Référentiel du projet",
"logout": "Déconnexion",
"themeToggle": {
"switchToLight": "Passer au thème clair",
"switchToDark": "Passer au thème sombre"
}
},
"login": {
"description": "Veuillez entrer votre compte et mot de passe pour vous connecter au système",
"username": "Nom d'utilisateur",
"usernamePlaceholder": "Veuillez saisir un nom d'utilisateur",
"password": "Mot de passe",
"passwordPlaceholder": "Veuillez saisir un mot de passe",
"loginButton": "Connexion",
"loggingIn": "Connexion en cours...",
"successMessage": "Connexion réussie",
"errorEmptyFields": "Veuillez saisir votre nom d'utilisateur et mot de passe",
"errorInvalidCredentials": "Échec de la connexion, veuillez vérifier le nom d'utilisateur et le mot de passe",
"authDisabled": "L'authentification est désactivée. Utilisation du mode sans connexion.",
"guestMode": "Mode sans connexion"
},
"documentPanel": {
"clearDocuments": {
"button": "Effacer",
@@ -96,7 +111,9 @@
"zoomControl": {
"zoomIn": "Zoom avant",
"zoomOut": "Zoom arrière",
"resetZoom": "Réinitialiser le zoom"
"resetZoom": "Réinitialiser le zoom",
"rotateCamera": "Rotation horaire",
"rotateCameraCounterClockwise": "Rotation antihoraire"
},
"layoutsControl": {
"startAnimation": "Démarrer l'animation de mise en page",
@@ -148,6 +165,11 @@
"degree": "Degré",
"properties": "Propriétés",
"relationships": "Relations",
"expandNode": "Développer le nœud",
"pruneNode": "Élaguer le nœud",
"deleteAllNodesError": "Refus de supprimer tous les nœuds du graphe",
"nodesRemoved": "{{count}} nœuds supprimés, y compris les nœuds orphelins",
"noNewNodes": "Aucun nœud développable trouvé",
"propertyNames": {
"description": "Description",
"entity_id": "Nom",
@@ -174,8 +196,10 @@
"noLabels": "Aucune étiquette trouvée",
"label": "Étiquette",
"placeholder": "Rechercher des étiquettes...",
"andOthers": "Et {{count}} autres"
}
"andOthers": "Et {{count}} autres",
"refreshTooltip": "Recharger les données du graphe"
},
"emptyGraph": "Le graphe est vide"
},
"retrievePanel": {
"chatMessage": {

View File

@@ -2,7 +2,7 @@ import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import AppRouter from './AppRouter'
import './i18n';
import './i18n.ts';

View File

@@ -5,7 +5,7 @@ import { defaultQueryLabel } from '@/lib/constants'
import { Message, QueryRequest } from '@/api/lightrag'
type Theme = 'dark' | 'light' | 'system'
type Language = 'en' | 'zh'
type Language = 'en' | 'zh' | 'fr' | 'ar'
type Tab = 'documents' | 'knowledge-graph' | 'retrieval' | 'api'
interface SettingsState {