Skip to content

Commit db7cef5

Browse files
ochanismlyingbug
authored andcommitted
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 ('简体中文')
1 parent 65743da commit db7cef5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+2366
-637
lines changed

frontend/src/api/auth/index.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import { post, get, put } from '@/utils/request'
2+
import i18n from '@/i18n'
3+
4+
const t = (key: string) => i18n.global.t(key)
25

36
// 用户登录接口
47
export interface LoginRequest {
@@ -122,7 +125,7 @@ export async function login(data: LoginRequest): Promise<LoginResponse> {
122125
} catch (error: any) {
123126
return {
124127
success: false,
125-
message: error.message || '登录失败'
128+
message: error.message || t('error.auth.loginFailed')
126129
}
127130
}
128131
}
@@ -137,7 +140,7 @@ export async function register(data: RegisterRequest): Promise<RegisterResponse>
137140
} catch (error: any) {
138141
return {
139142
success: false,
140-
message: error.message || '注册失败'
143+
message: error.message || t('error.auth.registerFailed')
141144
}
142145
}
143146
}
@@ -152,7 +155,7 @@ export async function getCurrentUser(): Promise<{ success: boolean; data?: { use
152155
} catch (error: any) {
153156
return {
154157
success: false,
155-
message: error.message || '获取用户信息失败'
158+
message: error.message || t('error.auth.getUserFailed')
156159
}
157160
}
158161
}
@@ -167,7 +170,7 @@ export async function getCurrentTenant(): Promise<{ success: boolean; data?: Ten
167170
} catch (error: any) {
168171
return {
169172
success: false,
170-
message: error.message || '获取租户信息失败'
173+
message: error.message || t('error.auth.getTenantFailed')
171174
}
172175
}
173176
}
@@ -193,12 +196,12 @@ export async function refreshToken(refreshToken: string): Promise<{ success: boo
193196
// 其他情况直接返回原始消息
194197
return {
195198
success: false,
196-
message: response?.message || '刷新Token失败'
199+
message: response?.message || t('error.auth.refreshTokenFailed')
197200
}
198201
} catch (error: any) {
199202
return {
200203
success: false,
201-
message: error.message || '刷新Token失败'
204+
message: error.message || t('error.auth.refreshTokenFailed')
202205
}
203206
}
204207
}
@@ -215,7 +218,7 @@ export async function logout(): Promise<{ success: boolean; message?: string }>
215218
} catch (error: any) {
216219
return {
217220
success: false,
218-
message: error.message || '登出失败'
221+
message: error.message || t('error.auth.logoutFailed')
219222
}
220223
}
221224
}
@@ -231,7 +234,7 @@ export async function validateToken(): Promise<{ success: boolean; valid?: boole
231234
return {
232235
success: false,
233236
valid: false,
234-
message: error.message || 'Token验证失败'
237+
message: error.message || t('error.auth.validateTokenFailed')
235238
}
236239
}
237240
}

frontend/src/api/chat/streame.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { fetchEventSource } from '@microsoft/fetch-event-source'
22
import { ref, type Ref, onUnmounted, nextTick } from 'vue'
33
import { generateRandomString } from '@/utils/index';
4+
import i18n from '@/i18n';
45

56

67

@@ -41,7 +42,7 @@ export function useStream() {
4142
// 获取JWT Token
4243
const token = localStorage.getItem('weknora_token');
4344
if (!token) {
44-
error.value = "未找到登录令牌,请重新登录";
45+
error.value = i18n.global.t('error.tokenNotFound');
4546
stopStream();
4647
return;
4748
}
@@ -143,7 +144,7 @@ export function useStream() {
143144
},
144145

145146
onerror: (err) => {
146-
throw new Error(`流式连接失败: ${err}`);
147+
throw new Error(`${i18n.global.t('error.streamFailed')}: ${err}`);
147148
},
148149

149150
onclose: () => {

frontend/src/api/initialization/index.ts

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import { get, post, put } from '../../utils/request';
2+
import i18n from '@/i18n'
3+
4+
const t = (key: string) => i18n.global.t(key)
25

36
// 初始化配置数据类型
47
export interface InitializationConfig {
@@ -107,14 +110,14 @@ export interface KBModelConfigRequest {
107110

108111
export function updateKBConfig(kbId: string, config: KBModelConfigRequest): Promise<any> {
109112
return new Promise((resolve, reject) => {
110-
console.log('开始知识库配置更新(简化版)...', kbId, config);
113+
console.log('Starting KB config update (simplified)...', kbId, config);
111114
put(`/api/v1/initialization/config/${kbId}`, config)
112115
.then((response: any) => {
113-
console.log('知识库配置更新完成', response);
116+
console.log('KB config update completed', response);
114117
resolve(response);
115118
})
116119
.catch((error: any) => {
117-
console.error('知识库配置更新失败:', error);
120+
console.error('Failed to update KB config:', error);
118121
reject(error.error || error);
119122
});
120123
});
@@ -123,14 +126,14 @@ export function updateKBConfig(kbId: string, config: KBModelConfigRequest): Prom
123126
// 根据知识库ID执行配置更新(旧版,保留兼容性)
124127
export function initializeSystemByKB(kbId: string, config: InitializationConfig): Promise<any> {
125128
return new Promise((resolve, reject) => {
126-
console.log('开始知识库配置更新...', kbId, config);
129+
console.log('Starting KB config update...', kbId, config);
127130
post(`/api/v1/initialization/initialize/${kbId}`, config)
128131
.then((response: any) => {
129-
console.log('知识库配置更新完成', response);
132+
console.log('KB config update completed', response);
130133
resolve(response);
131134
})
132135
.catch((error: any) => {
133-
console.error('知识库配置更新失败:', error);
136+
console.error('Failed to update KB config:', error);
134137
reject(error.error || error);
135138
});
136139
});
@@ -144,8 +147,8 @@ export function checkOllamaStatus(): Promise<{ available: boolean; version?: str
144147
resolve(response.data || { available: false });
145148
})
146149
.catch((error: any) => {
147-
console.error('检查Ollama状态失败:', error);
148-
resolve({ available: false, error: error.message || '检查失败' });
150+
console.error('Failed to check Ollama status:', error);
151+
resolve({ available: false, error: error.message || t('error.initialization.checkFailed') });
149152
});
150153
});
151154
}
@@ -166,7 +169,7 @@ export function listOllamaModels(): Promise<OllamaModelInfo[]> {
166169
resolve((response.data && response.data.models) || []);
167170
})
168171
.catch((error: any) => {
169-
console.error('获取 Ollama 模型列表失败:', error);
172+
console.error('Failed to list Ollama models:', error);
170173
resolve([]);
171174
});
172175
});
@@ -180,7 +183,7 @@ export function checkOllamaModels(models: string[]): Promise<{ models: Record<st
180183
resolve(response.data || { models: {} });
181184
})
182185
.catch((error: any) => {
183-
console.error('检查Ollama模型状态失败:', error);
186+
console.error('Failed to check Ollama models:', error);
184187
reject(error);
185188
});
186189
});
@@ -194,7 +197,7 @@ export function downloadOllamaModel(modelName: string): Promise<{ taskId: string
194197
resolve(response.data || { taskId: '', modelName, status: 'failed', progress: 0 });
195198
})
196199
.catch((error: any) => {
197-
console.error('启动Ollama模型下载失败:', error);
200+
console.error('Failed to start Ollama model download:', error);
198201
reject(error);
199202
});
200203
});
@@ -208,7 +211,7 @@ export function getDownloadProgress(taskId: string): Promise<DownloadTask> {
208211
resolve(response.data);
209212
})
210213
.catch((error: any) => {
211-
console.error('查询下载进度失败:', error);
214+
console.error('Failed to get download progress:', error);
212215
reject(error);
213216
});
214217
});
@@ -222,7 +225,7 @@ export function listDownloadTasks(): Promise<DownloadTask[]> {
222225
resolve(response.data || []);
223226
})
224227
.catch((error: any) => {
225-
console.error('获取下载任务列表失败:', error);
228+
console.error('Failed to list download tasks:', error);
226229
reject(error);
227230
});
228231
});
@@ -236,7 +239,7 @@ export function getCurrentConfigByKB(kbId: string): Promise<InitializationConfig
236239
resolve(response.data || {});
237240
})
238241
.catch((error: any) => {
239-
console.error('获取知识库配置失败:', error);
242+
console.error('Failed to get KB config:', error);
240243
reject(error);
241244
});
242245
});
@@ -257,7 +260,7 @@ export function checkRemoteModel(modelConfig: {
257260
resolve(response.data || {});
258261
})
259262
.catch((error: any) => {
260-
console.error('检查远程模型失败:', error);
263+
console.error('Failed to check remote model:', error);
261264
reject(error);
262265
});
263266
});
@@ -278,7 +281,7 @@ export function testEmbeddingModel(modelConfig: {
278281
resolve(response.data || {});
279282
})
280283
.catch((error: any) => {
281-
console.error('测试Embedding模型失败:', error);
284+
console.error('Failed to test Embedding model:', error);
282285
reject(error);
283286
});
284287
});
@@ -299,7 +302,7 @@ export function checkRerankModel(modelConfig: {
299302
resolve(response.data || {});
300303
})
301304
.catch((error: any) => {
302-
console.error('检查Rerank模型失败:', error);
305+
console.error('Failed to check Rerank model:', error);
303306
reject(error);
304307
});
305308
});
@@ -395,11 +398,11 @@ export function testMultimodalFunction(testData: {
395398
if (data.success) {
396399
resolve(data.data || {});
397400
} else {
398-
resolve({ success: false, message: data.message || '测试失败' });
401+
resolve({ success: false, message: data.message || t('error.initialization.testFailed') });
399402
}
400403
})
401404
.catch((error: any) => {
402-
console.error('多模态测试失败:', error);
405+
console.error('Failed multimodal test:', error);
403406
reject(error);
404407
});
405408
});
@@ -443,7 +446,7 @@ export function extractTextRelations(request: TextRelationExtractionRequest): Pr
443446
resolve(response.data || { nodes: [], relations: [] });
444447
})
445448
.catch((error: any) => {
446-
console.error('文本内容关系提取失败:', error);
449+
console.error('Failed to extract text relations:', error);
447450
reject(error);
448451
});
449452
});
@@ -466,7 +469,7 @@ export function fabriText(request: FabriTextRequest): Promise<FabriTextResponse>
466469
resolve(response.data || { text: '' });
467470
})
468471
.catch((error: any) => {
469-
console.error('文本内容生成失败:', error);
472+
console.error('Failed to generate text:', error);
470473
reject(error);
471474
});
472475
});
@@ -488,7 +491,7 @@ export function fabriTag(request: FabriTagRequest): Promise<FabriTagResponse> {
488491
resolve(response.data || { tags: [] as string[] });
489492
})
490493
.catch((error: any) => {
491-
console.error('标签生成失败:', error);
494+
console.error('Failed to generate tags:', error);
492495
reject(error);
493496
});
494497
});
@@ -514,7 +517,7 @@ export function listModelProviders(modelType?: string): Promise<ModelProviderOpt
514517
resolve(response.data || []);
515518
})
516519
.catch((error: any) => {
517-
console.error('获取模型厂商列表失败:', error);
520+
console.error('Failed to list model providers:', error);
518521
resolve([]); // 失败时返回空数组,前端可以回退到默认值
519522
});
520523
});

frontend/src/api/model/index.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import { get, post, put, del } from '../../utils/request';
2+
import i18n from '@/i18n'
3+
4+
const t = (key: string) => i18n.global.t(key)
25

36
// 模型类型定义
47
export interface ModelConfig {
@@ -36,11 +39,11 @@ export function createModel(data: ModelConfig): Promise<ModelConfig> {
3639
if (response.success && response.data) {
3740
resolve(response.data);
3841
} else {
39-
reject(new Error(response.message || '创建模型失败'));
42+
reject(new Error(response.message || t('error.model.createFailed')));
4043
}
4144
})
4245
.catch((error: any) => {
43-
console.error('创建模型失败:', error);
46+
console.error('Failed to create model:', error);
4447
reject(error);
4548
});
4649
});
@@ -62,7 +65,7 @@ export function listModels(type?: string): Promise<ModelConfig[]> {
6265
}
6366
})
6467
.catch((error: any) => {
65-
console.error('获取模型列表失败:', error);
68+
console.error('Failed to list models:', error);
6669
resolve([]);
6770
});
6871
});
@@ -76,11 +79,11 @@ export function getModel(id: string): Promise<ModelConfig> {
7679
if (response.success && response.data) {
7780
resolve(response.data);
7881
} else {
79-
reject(new Error(response.message || '获取模型失败'));
82+
reject(new Error(response.message || t('error.model.getFailed')));
8083
}
8184
})
8285
.catch((error: any) => {
83-
console.error('获取模型失败:', error);
86+
console.error('Failed to get model:', error);
8487
reject(error);
8588
});
8689
});
@@ -94,11 +97,11 @@ export function updateModel(id: string, data: Partial<ModelConfig>): Promise<Mod
9497
if (response.success && response.data) {
9598
resolve(response.data);
9699
} else {
97-
reject(new Error(response.message || '更新模型失败'));
100+
reject(new Error(response.message || t('error.model.updateFailed')));
98101
}
99102
})
100103
.catch((error: any) => {
101-
console.error('更新模型失败:', error);
104+
console.error('Failed to update model:', error);
102105
reject(error);
103106
});
104107
});
@@ -112,11 +115,11 @@ export function deleteModel(id: string): Promise<void> {
112115
if (response.success) {
113116
resolve();
114117
} else {
115-
reject(new Error(response.message || '删除模型失败'));
118+
reject(new Error(response.message || t('error.model.deleteFailed')));
116119
}
117120
})
118121
.catch((error: any) => {
119-
console.error('删除模型失败:', error);
122+
console.error('Failed to delete model:', error);
120123
reject(error);
121124
});
122125
});

frontend/src/api/tenant/index.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
import { get } from '@/utils/request'
2+
import i18n from '@/i18n'
3+
4+
const t = (key: string) => i18n.global.t(key)
25

36
// 租户信息接口
47
export interface TenantInfo {
@@ -45,7 +48,7 @@ export async function listAllTenants(): Promise<{ success: boolean; data?: { ite
4548
} catch (error: any) {
4649
return {
4750
success: false,
48-
message: error.message || '获取租户列表失败'
51+
message: error.message || t('error.tenant.listFailed')
4952
}
5053
}
5154
}
@@ -76,7 +79,7 @@ export async function searchTenants(params: SearchTenantsParams = {}): Promise<S
7679
} catch (error: any) {
7780
return {
7881
success: false,
79-
message: error.message || '搜索租户失败'
82+
message: error.message || t('error.tenant.searchFailed')
8083
}
8184
}
8285
}

frontend/src/components/AgentShareSettings.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="section-content">
33
<div class="section-header">
44
<h3 class="section-title">{{ $t('organization.share.title') }}</h3>
5-
<p class="section-desc">{{ $t('organization.share.agentShareDesc') || '将智能体共享到空间,空间成员可使用该智能体' }}</p>
5+
<p class="section-desc">{{ $t('organization.share.agentShareDesc') }}</p>
66
</div>
77
<!-- 共享范围说明:当传入 agent 时展示,仅提示 + 变更同步说明,不列具体开关 -->
88
<div v-if="agent?.config" class="share-scope-block">

0 commit comments

Comments
 (0)