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,3 +1,5 @@
|
||||
import i18n from '@/i18n';
|
||||
|
||||
const STREAMING_IMAGE_PLACEHOLDER = '<span class="streaming-image-loading"><span class="streaming-image-loading__skeleton"></span></span>';
|
||||
|
||||
export const replaceIncompleteImageWithPlaceholder = (content: string): string => {
|
||||
@@ -23,17 +25,17 @@ export const replaceIncompleteImageWithPlaceholder = (content: string): string =
|
||||
|
||||
export const formatManualTitle = (question?: string): string => {
|
||||
if (!question) {
|
||||
return '会话摘录';
|
||||
return i18n.global.t('chat.sessionExcerpt');
|
||||
}
|
||||
const condensed = question.replace(/\s+/g, ' ').trim();
|
||||
if (!condensed) {
|
||||
return '会话摘录';
|
||||
return i18n.global.t('chat.sessionExcerpt');
|
||||
}
|
||||
return condensed.length > 40 ? `${condensed.slice(0, 40)}...` : condensed;
|
||||
};
|
||||
|
||||
export const buildManualMarkdown = (_question: string, answer: string): string => {
|
||||
const safeAnswer = answer?.trim() || '(无回答内容)';
|
||||
const safeAnswer = answer?.trim() || i18n.global.t('chat.noAnswerContent');
|
||||
return `${safeAnswer}`;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { MessagePlugin } from "tdesign-vue-next";
|
||||
import i18n from '@/i18n';
|
||||
|
||||
// 声明全局运行时配置类型
|
||||
declare global {
|
||||
@@ -53,13 +54,13 @@ export function kbFileTypeVerification(file: any, silent = false, validTypes?: S
|
||||
const type = file.name.substring(file.name.lastIndexOf(".") + 1).toLowerCase();
|
||||
if (!allowed.has(type)) {
|
||||
if (!silent) {
|
||||
MessagePlugin.error("不支持的文件类型!");
|
||||
MessagePlugin.error(i18n.global.t('error.unsupportedFileType'));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (file.size > MAX_FILE_SIZE_BYTES) {
|
||||
if (!silent) {
|
||||
MessagePlugin.error(`文件大小不能超过 ${MAX_FILE_SIZE_MB}M!`);
|
||||
MessagePlugin.error(i18n.global.t('error.fileSizeExceeded', { size: MAX_FILE_SIZE_MB }));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
* Mermaid 图表全屏查看器
|
||||
* 支持:点击放大、滚轮缩放、鼠标拖拽、高清导出
|
||||
*/
|
||||
import i18n from '@/i18n';
|
||||
|
||||
/**
|
||||
* 下载 SVG 为 PNG 图片(使用实际渲染尺寸)
|
||||
@@ -54,7 +55,7 @@ const showBtnFeedback = (btn: HTMLElement, success: boolean, text?: string): voi
|
||||
const origColor = btn.style.color
|
||||
const origTitle = btn.title
|
||||
btn.style.color = success ? '#07c05f' : '#ef4444'
|
||||
btn.title = text || (success ? '成功' : '失败')
|
||||
btn.title = text || (success ? i18n.global.t('common.success') : i18n.global.t('common.failed'))
|
||||
setTimeout(() => {
|
||||
btn.style.color = origColor
|
||||
btn.title = origTitle
|
||||
@@ -93,11 +94,12 @@ export const openMermaidFullscreen = (svgHtml: string): void => {
|
||||
return btn
|
||||
}
|
||||
|
||||
const zoomInBtn = createBtn('放大', '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/><line x1="11" y1="8" x2="11" y2="14"/><line x1="8" y1="11" x2="14" y2="11"/></svg>')
|
||||
const zoomOutBtn = createBtn('缩小', '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/><line x1="8" y1="11" x2="14" y2="11"/></svg>')
|
||||
const resetBtn = createBtn('重置', '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg>')
|
||||
const downloadBtn = createBtn('下载图片', '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg>')
|
||||
const closeBtn = createBtn('关闭', '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>')
|
||||
const t = (key: string) => i18n.global.t(key);
|
||||
const zoomInBtn = createBtn(t('mermaid.zoomIn'), '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/><line x1="11" y1="8" x2="11" y2="14"/><line x1="8" y1="11" x2="14" y2="11"/></svg>')
|
||||
const zoomOutBtn = createBtn(t('mermaid.zoomOut'), '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/><line x1="8" y1="11" x2="14" y2="11"/></svg>')
|
||||
const resetBtn = createBtn(t('mermaid.reset'), '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></svg>')
|
||||
const downloadBtn = createBtn(t('mermaid.download'), '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg>')
|
||||
const closeBtn = createBtn(t('mermaid.close'), '<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>')
|
||||
toolbar.append(zoomInBtn, zoomOutBtn, resetBtn, downloadBtn, closeBtn)
|
||||
|
||||
// 创建内容区域
|
||||
@@ -139,7 +141,7 @@ export const openMermaidFullscreen = (svgHtml: string): void => {
|
||||
e.stopPropagation()
|
||||
if (!svgEl) return
|
||||
downloadSvgAsImage(svgEl)
|
||||
showBtnFeedback(downloadBtn, true, '下载中...')
|
||||
showBtnFeedback(downloadBtn, true, t('mermaid.downloading'))
|
||||
}
|
||||
|
||||
// 关闭函数
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
// src/utils/request.js
|
||||
import axios from "axios";
|
||||
import { generateRandomString } from "./index";
|
||||
import i18n from '@/i18n'
|
||||
|
||||
const t = (key: string) => i18n.global.t(key)
|
||||
|
||||
// API基础URL
|
||||
const BASE_URL = import.meta.env.VITE_IS_DOCKER ? "" : "http://localhost:8080";
|
||||
@@ -81,13 +84,13 @@ instance.interceptors.response.use(
|
||||
const originalRequest = error.config;
|
||||
|
||||
if (!error.response) {
|
||||
return Promise.reject({ message: "网络错误,请检查您的网络连接" });
|
||||
return Promise.reject({ message: t('error.networkError') });
|
||||
}
|
||||
|
||||
// 如果是登录接口的401,直接返回错误以便页面展示toast,不做跳转
|
||||
if (error.response.status === 401 && originalRequest?.url?.includes('/auth/login')) {
|
||||
const { status, data } = error.response;
|
||||
return Promise.reject({ status, message: (typeof data === 'object' ? data?.message : data) || '用户名或密码错误' });
|
||||
return Promise.reject({ status, message: (typeof data === 'object' ? data?.message : data) || t('error.invalidCredentials') });
|
||||
}
|
||||
|
||||
// 如果是401错误且不是刷新token的请求,尝试刷新token
|
||||
@@ -130,7 +133,7 @@ instance.interceptors.response.use(
|
||||
|
||||
return instance(originalRequest);
|
||||
} else {
|
||||
throw new Error(response.message || 'Token刷新失败');
|
||||
throw new Error(response.message || t('error.tokenRefreshFailed'));
|
||||
}
|
||||
} catch (refreshError) {
|
||||
// 刷新失败,清除所有token并跳转到登录页
|
||||
@@ -162,7 +165,7 @@ instance.interceptors.response.use(
|
||||
window.location.href = '/login';
|
||||
}
|
||||
|
||||
return Promise.reject({ message: '请重新登录' });
|
||||
return Promise.reject({ message: t('error.pleaseRelogin') });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,7 +173,7 @@ instance.interceptors.response.use(
|
||||
if (error.response.status === 413) {
|
||||
return Promise.reject({
|
||||
status: 413,
|
||||
message: '文件大小超过限制,请上传较小的文件',
|
||||
message: t('error.fileSizeExceeded'),
|
||||
success: false
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
* Tool Icons Utility
|
||||
* Maps tool names and match types to icons for better UI display
|
||||
*/
|
||||
import i18n from '@/i18n'
|
||||
|
||||
const t = (key: string) => i18n.global.t(key)
|
||||
|
||||
// Tool name to icon mapping
|
||||
export const toolIcons: Record<string, string> = {
|
||||
@@ -17,7 +20,18 @@ export const toolIcons: Record<string, string> = {
|
||||
todo_write: '📋',
|
||||
};
|
||||
|
||||
// Match type to icon mapping
|
||||
// Match type internal keys for icon mapping
|
||||
const matchTypeIconKeys: Record<string, string> = {
|
||||
vector: '🎯',
|
||||
keyword: '🔤',
|
||||
adjacent: '📌',
|
||||
history: '📜',
|
||||
parent: '⬆️',
|
||||
relation: '🔗',
|
||||
graph: '🕸️',
|
||||
};
|
||||
|
||||
// Match type to icon mapping (Chinese keys preserved for API compatibility)
|
||||
export const matchTypeIcons: Record<string, string> = {
|
||||
'向量匹配': '🎯',
|
||||
'关键词匹配': '🔤',
|
||||
@@ -35,23 +49,26 @@ export function getToolIcon(toolName: string): string {
|
||||
|
||||
// Get icon for a match type
|
||||
export function getMatchTypeIcon(matchType: string): string {
|
||||
return matchTypeIcons[matchType] || '📍';
|
||||
return matchTypeIcons[matchType] || matchTypeIconKeys[matchType] || '📍';
|
||||
}
|
||||
|
||||
// Get tool display name (user-friendly)
|
||||
// Tool name to i18n key mapping
|
||||
const toolDisplayNameKeys: Record<string, string> = {
|
||||
multi_kb_search: 'tools.multiKbSearch',
|
||||
knowledge_search: 'tools.knowledgeSearch',
|
||||
grep_chunks: 'tools.grepChunks',
|
||||
get_chunk_detail: 'tools.getChunkDetail',
|
||||
list_knowledge_chunks: 'tools.listKnowledgeChunks',
|
||||
list_knowledge_bases: 'tools.listKnowledgeBases',
|
||||
get_document_info: 'tools.getDocumentInfo',
|
||||
query_knowledge_graph: 'tools.queryKnowledgeGraph',
|
||||
think: 'tools.think',
|
||||
todo_write: 'tools.todoWrite',
|
||||
};
|
||||
|
||||
// Get tool display name (user-friendly, localized)
|
||||
export function getToolDisplayName(toolName: string): string {
|
||||
const displayNames: Record<string, string> = {
|
||||
multi_kb_search: '跨库搜索',
|
||||
knowledge_search: '知识库搜索',
|
||||
grep_chunks: '文本模式搜索',
|
||||
get_chunk_detail: '获取片段详情',
|
||||
list_knowledge_chunks: '查看知识分块',
|
||||
list_knowledge_bases: '列出知识库',
|
||||
get_document_info: '获取文档信息',
|
||||
query_knowledge_graph: '查询知识图谱',
|
||||
think: '深度思考',
|
||||
todo_write: '制定计划',
|
||||
};
|
||||
return displayNames[toolName] || toolName;
|
||||
const key = toolDisplayNameKeys[toolName];
|
||||
return key ? t(key) : toolName;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user