feat(i18n): replace hardcoded Chinese strings with i18n calls across frontend
Replace all user-visible hardcoded Chinese strings in Vue/TS source files
with proper i18n function calls and add corresponding translation keys
to all 4 locale files (zh-CN, en-US, ko-KR, ru-RU).
Changes:
- Replace 80+ hardcoded Chinese strings across 30+ source files
- Add ~450 new translation keys per locale file
- Cover components, views, utils, hooks, and API modules
- Remove Chinese fallback patterns (|| '中文') from existing t() calls
- Add mermaid toolbar and ollama date format translations
Intentionally preserved (backend API values / backward compatibility):
- FAQ CSV column headers and parsing constants
- RelevanceLevel type and Record key mappings
- Graph database engine status comparison ('未启用')
- Language name labels ('简体中文')
This commit is contained in:
@@ -1,4 +1,7 @@
|
||||
import { post, get, put } from '@/utils/request'
|
||||
import i18n from '@/i18n'
|
||||
|
||||
const t = (key: string) => i18n.global.t(key)
|
||||
|
||||
// 用户登录接口
|
||||
export interface LoginRequest {
|
||||
@@ -122,7 +125,7 @@ export async function login(data: LoginRequest): Promise<LoginResponse> {
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
message: error.message || '登录失败'
|
||||
message: error.message || t('error.auth.loginFailed')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,7 +140,7 @@ export async function register(data: RegisterRequest): Promise<RegisterResponse>
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
message: error.message || '注册失败'
|
||||
message: error.message || t('error.auth.registerFailed')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -152,7 +155,7 @@ export async function getCurrentUser(): Promise<{ success: boolean; data?: { use
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
message: error.message || '获取用户信息失败'
|
||||
message: error.message || t('error.auth.getUserFailed')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -167,7 +170,7 @@ export async function getCurrentTenant(): Promise<{ success: boolean; data?: Ten
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
message: error.message || '获取租户信息失败'
|
||||
message: error.message || t('error.auth.getTenantFailed')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -193,12 +196,12 @@ export async function refreshToken(refreshToken: string): Promise<{ success: boo
|
||||
// 其他情况直接返回原始消息
|
||||
return {
|
||||
success: false,
|
||||
message: response?.message || '刷新Token失败'
|
||||
message: response?.message || t('error.auth.refreshTokenFailed')
|
||||
}
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
message: error.message || '刷新Token失败'
|
||||
message: error.message || t('error.auth.refreshTokenFailed')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -215,7 +218,7 @@ export async function logout(): Promise<{ success: boolean; message?: string }>
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
message: error.message || '登出失败'
|
||||
message: error.message || t('error.auth.logoutFailed')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -231,7 +234,7 @@ export async function validateToken(): Promise<{ success: boolean; valid?: boole
|
||||
return {
|
||||
success: false,
|
||||
valid: false,
|
||||
message: error.message || 'Token验证失败'
|
||||
message: error.message || t('error.auth.validateTokenFailed')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { fetchEventSource } from '@microsoft/fetch-event-source'
|
||||
import { ref, type Ref, onUnmounted, nextTick } from 'vue'
|
||||
import { generateRandomString } from '@/utils/index';
|
||||
import i18n from '@/i18n';
|
||||
|
||||
|
||||
|
||||
@@ -41,7 +42,7 @@ export function useStream() {
|
||||
// 获取JWT Token
|
||||
const token = localStorage.getItem('weknora_token');
|
||||
if (!token) {
|
||||
error.value = "未找到登录令牌,请重新登录";
|
||||
error.value = i18n.global.t('error.tokenNotFound');
|
||||
stopStream();
|
||||
return;
|
||||
}
|
||||
@@ -143,7 +144,7 @@ export function useStream() {
|
||||
},
|
||||
|
||||
onerror: (err) => {
|
||||
throw new Error(`流式连接失败: ${err}`);
|
||||
throw new Error(`${i18n.global.t('error.streamFailed')}: ${err}`);
|
||||
},
|
||||
|
||||
onclose: () => {
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { get, post, put } from '../../utils/request';
|
||||
import i18n from '@/i18n'
|
||||
|
||||
const t = (key: string) => i18n.global.t(key)
|
||||
|
||||
// 初始化配置数据类型
|
||||
export interface InitializationConfig {
|
||||
@@ -107,14 +110,14 @@ export interface KBModelConfigRequest {
|
||||
|
||||
export function updateKBConfig(kbId: string, config: KBModelConfigRequest): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log('开始知识库配置更新(简化版)...', kbId, config);
|
||||
console.log('Starting KB config update (simplified)...', kbId, config);
|
||||
put(`/api/v1/initialization/config/${kbId}`, config)
|
||||
.then((response: any) => {
|
||||
console.log('知识库配置更新完成', response);
|
||||
console.log('KB config update completed', response);
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('知识库配置更新失败:', error);
|
||||
console.error('Failed to update KB config:', error);
|
||||
reject(error.error || error);
|
||||
});
|
||||
});
|
||||
@@ -123,14 +126,14 @@ export function updateKBConfig(kbId: string, config: KBModelConfigRequest): Prom
|
||||
// 根据知识库ID执行配置更新(旧版,保留兼容性)
|
||||
export function initializeSystemByKB(kbId: string, config: InitializationConfig): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.log('开始知识库配置更新...', kbId, config);
|
||||
console.log('Starting KB config update...', kbId, config);
|
||||
post(`/api/v1/initialization/initialize/${kbId}`, config)
|
||||
.then((response: any) => {
|
||||
console.log('知识库配置更新完成', response);
|
||||
console.log('KB config update completed', response);
|
||||
resolve(response);
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('知识库配置更新失败:', error);
|
||||
console.error('Failed to update KB config:', error);
|
||||
reject(error.error || error);
|
||||
});
|
||||
});
|
||||
@@ -144,8 +147,8 @@ export function checkOllamaStatus(): Promise<{ available: boolean; version?: str
|
||||
resolve(response.data || { available: false });
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('检查Ollama状态失败:', error);
|
||||
resolve({ available: false, error: error.message || '检查失败' });
|
||||
console.error('Failed to check Ollama status:', error);
|
||||
resolve({ available: false, error: error.message || t('error.initialization.checkFailed') });
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -166,7 +169,7 @@ export function listOllamaModels(): Promise<OllamaModelInfo[]> {
|
||||
resolve((response.data && response.data.models) || []);
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('获取 Ollama 模型列表失败:', error);
|
||||
console.error('Failed to list Ollama models:', error);
|
||||
resolve([]);
|
||||
});
|
||||
});
|
||||
@@ -180,7 +183,7 @@ export function checkOllamaModels(models: string[]): Promise<{ models: Record<st
|
||||
resolve(response.data || { models: {} });
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('检查Ollama模型状态失败:', error);
|
||||
console.error('Failed to check Ollama models:', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
@@ -194,7 +197,7 @@ export function downloadOllamaModel(modelName: string): Promise<{ taskId: string
|
||||
resolve(response.data || { taskId: '', modelName, status: 'failed', progress: 0 });
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('启动Ollama模型下载失败:', error);
|
||||
console.error('Failed to start Ollama model download:', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
@@ -208,7 +211,7 @@ export function getDownloadProgress(taskId: string): Promise<DownloadTask> {
|
||||
resolve(response.data);
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('查询下载进度失败:', error);
|
||||
console.error('Failed to get download progress:', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
@@ -222,7 +225,7 @@ export function listDownloadTasks(): Promise<DownloadTask[]> {
|
||||
resolve(response.data || []);
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('获取下载任务列表失败:', error);
|
||||
console.error('Failed to list download tasks:', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
@@ -236,7 +239,7 @@ export function getCurrentConfigByKB(kbId: string): Promise<InitializationConfig
|
||||
resolve(response.data || {});
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('获取知识库配置失败:', error);
|
||||
console.error('Failed to get KB config:', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
@@ -257,7 +260,7 @@ export function checkRemoteModel(modelConfig: {
|
||||
resolve(response.data || {});
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('检查远程模型失败:', error);
|
||||
console.error('Failed to check remote model:', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
@@ -278,7 +281,7 @@ export function testEmbeddingModel(modelConfig: {
|
||||
resolve(response.data || {});
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('测试Embedding模型失败:', error);
|
||||
console.error('Failed to test Embedding model:', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
@@ -299,7 +302,7 @@ export function checkRerankModel(modelConfig: {
|
||||
resolve(response.data || {});
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('检查Rerank模型失败:', error);
|
||||
console.error('Failed to check Rerank model:', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
@@ -395,11 +398,11 @@ export function testMultimodalFunction(testData: {
|
||||
if (data.success) {
|
||||
resolve(data.data || {});
|
||||
} else {
|
||||
resolve({ success: false, message: data.message || '测试失败' });
|
||||
resolve({ success: false, message: data.message || t('error.initialization.testFailed') });
|
||||
}
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('多模态测试失败:', error);
|
||||
console.error('Failed multimodal test:', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
@@ -443,7 +446,7 @@ export function extractTextRelations(request: TextRelationExtractionRequest): Pr
|
||||
resolve(response.data || { nodes: [], relations: [] });
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('文本内容关系提取失败:', error);
|
||||
console.error('Failed to extract text relations:', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
@@ -466,7 +469,7 @@ export function fabriText(request: FabriTextRequest): Promise<FabriTextResponse>
|
||||
resolve(response.data || { text: '' });
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('文本内容生成失败:', error);
|
||||
console.error('Failed to generate text:', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
@@ -488,7 +491,7 @@ export function fabriTag(request: FabriTagRequest): Promise<FabriTagResponse> {
|
||||
resolve(response.data || { tags: [] as string[] });
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('标签生成失败:', error);
|
||||
console.error('Failed to generate tags:', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
@@ -514,7 +517,7 @@ export function listModelProviders(modelType?: string): Promise<ModelProviderOpt
|
||||
resolve(response.data || []);
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('获取模型厂商列表失败:', error);
|
||||
console.error('Failed to list model providers:', error);
|
||||
resolve([]); // 失败时返回空数组,前端可以回退到默认值
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { get, post, put, del } from '../../utils/request';
|
||||
import i18n from '@/i18n'
|
||||
|
||||
const t = (key: string) => i18n.global.t(key)
|
||||
|
||||
// 模型类型定义
|
||||
export interface ModelConfig {
|
||||
@@ -36,11 +39,11 @@ export function createModel(data: ModelConfig): Promise<ModelConfig> {
|
||||
if (response.success && response.data) {
|
||||
resolve(response.data);
|
||||
} else {
|
||||
reject(new Error(response.message || '创建模型失败'));
|
||||
reject(new Error(response.message || t('error.model.createFailed')));
|
||||
}
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('创建模型失败:', error);
|
||||
console.error('Failed to create model:', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
@@ -62,7 +65,7 @@ export function listModels(type?: string): Promise<ModelConfig[]> {
|
||||
}
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('获取模型列表失败:', error);
|
||||
console.error('Failed to list models:', error);
|
||||
resolve([]);
|
||||
});
|
||||
});
|
||||
@@ -76,11 +79,11 @@ export function getModel(id: string): Promise<ModelConfig> {
|
||||
if (response.success && response.data) {
|
||||
resolve(response.data);
|
||||
} else {
|
||||
reject(new Error(response.message || '获取模型失败'));
|
||||
reject(new Error(response.message || t('error.model.getFailed')));
|
||||
}
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('获取模型失败:', error);
|
||||
console.error('Failed to get model:', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
@@ -94,11 +97,11 @@ export function updateModel(id: string, data: Partial<ModelConfig>): Promise<Mod
|
||||
if (response.success && response.data) {
|
||||
resolve(response.data);
|
||||
} else {
|
||||
reject(new Error(response.message || '更新模型失败'));
|
||||
reject(new Error(response.message || t('error.model.updateFailed')));
|
||||
}
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('更新模型失败:', error);
|
||||
console.error('Failed to update model:', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
@@ -112,11 +115,11 @@ export function deleteModel(id: string): Promise<void> {
|
||||
if (response.success) {
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Error(response.message || '删除模型失败'));
|
||||
reject(new Error(response.message || t('error.model.deleteFailed')));
|
||||
}
|
||||
})
|
||||
.catch((error: any) => {
|
||||
console.error('删除模型失败:', error);
|
||||
console.error('Failed to delete model:', error);
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { get } from '@/utils/request'
|
||||
import i18n from '@/i18n'
|
||||
|
||||
const t = (key: string) => i18n.global.t(key)
|
||||
|
||||
// 租户信息接口
|
||||
export interface TenantInfo {
|
||||
@@ -45,7 +48,7 @@ export async function listAllTenants(): Promise<{ success: boolean; data?: { ite
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
message: error.message || '获取租户列表失败'
|
||||
message: error.message || t('error.tenant.listFailed')
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -76,7 +79,7 @@ export async function searchTenants(params: SearchTenantsParams = {}): Promise<S
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
message: error.message || '搜索租户失败'
|
||||
message: error.message || t('error.tenant.searchFailed')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user