init
This commit is contained in:
194
vw-agentic-rag/web/src/utils/i18n.ts-demo
Normal file
194
vw-agentic-rag/web/src/utils/i18n.ts-demo
Normal file
@@ -0,0 +1,194 @@
|
||||
// 多语言支持配置
|
||||
export type Language = 'zh' | 'en';
|
||||
|
||||
export interface Translations {
|
||||
// 通用
|
||||
loading: string;
|
||||
error: string;
|
||||
expand: string;
|
||||
collapse: string;
|
||||
|
||||
// 页面标题和描述
|
||||
appTitle: string;
|
||||
appDescription: string;
|
||||
welcomeMessage: string;
|
||||
|
||||
// 工具相关
|
||||
toolSearching: string;
|
||||
toolProcessing: string;
|
||||
toolCompleted: string;
|
||||
toolFailed: string;
|
||||
toolStandardSearch: string;
|
||||
toolDocumentSearch: string;
|
||||
toolQuery: string;
|
||||
toolFound: string;
|
||||
toolRetrieved: string;
|
||||
toolResults: string;
|
||||
toolChunks: string;
|
||||
toolMoreResults: string;
|
||||
toolMoreChunks: string;
|
||||
toolDocumentChunk: string;
|
||||
|
||||
// 状态消息
|
||||
statusSearching: string;
|
||||
statusProcessing: string;
|
||||
statusCompleted: string;
|
||||
statusError: string;
|
||||
|
||||
// 新增:工具汇总相关
|
||||
toolExecutionSummary: string;
|
||||
resultsText: string;
|
||||
tooltip: string;
|
||||
}
|
||||
|
||||
export const translations: Record<Language, Translations> = {
|
||||
zh: {
|
||||
// 通用
|
||||
loading: '加载中...',
|
||||
error: '错误',
|
||||
expand: '展开',
|
||||
collapse: '收起',
|
||||
|
||||
// 页面标题和描述
|
||||
appTitle: '代理式RAG',
|
||||
appDescription: '先进的AI代理,支持RAG检索和工具调用',
|
||||
welcomeMessage: '你好!我是你的 AI 助手。我可以解答有关标准和法规的问题,基于从知识库智能检索到的信息。',
|
||||
|
||||
// 工具相关
|
||||
toolSearching: '搜索中...',
|
||||
toolProcessing: '处理中...',
|
||||
toolCompleted: '已完成',
|
||||
toolFailed: '失败',
|
||||
toolStandardSearch: '标准/法规语义检索',
|
||||
toolDocumentSearch: '文档块语义检索',
|
||||
toolQuery: '查询',
|
||||
toolFound: '找到',
|
||||
toolRetrieved: '获取',
|
||||
toolResults: '条结果',
|
||||
toolChunks: '片段',
|
||||
toolMoreResults: '还有',
|
||||
toolMoreChunks: '还有',
|
||||
toolDocumentChunk: '文档块',
|
||||
|
||||
// 状态消息
|
||||
statusSearching: '搜索中...',
|
||||
statusProcessing: '处理中...',
|
||||
statusCompleted: '已完成',
|
||||
statusError: '发生错误',
|
||||
|
||||
// 工具汇总相关
|
||||
toolExecutionSummary: '工具执行汇总',
|
||||
resultsText: '个结果',
|
||||
tooltip: 'AI 可能会出错,请核对重要信息。'
|
||||
},
|
||||
|
||||
en: {
|
||||
// 通用
|
||||
loading: 'Loading...',
|
||||
error: 'Error',
|
||||
expand: 'Expand',
|
||||
collapse: 'Collapse',
|
||||
|
||||
// 页面标题和描述
|
||||
appTitle: 'Agentic RAG',
|
||||
appDescription: 'Advanced AI Agent with RAG and Tool Support',
|
||||
welcomeMessage: 'Hello! I\'m AI agent that answer your questions about standards and regulations, grounded on information intelligently retrieved from the knowledge base.',
|
||||
|
||||
// 工具相关
|
||||
toolSearching: 'Searching...',
|
||||
toolProcessing: 'Processing...',
|
||||
toolCompleted: 'Completed',
|
||||
toolFailed: 'Failed',
|
||||
toolStandardSearch: 'Standard/Regulation Semantic Retrieval',
|
||||
toolDocumentSearch: 'Document Chunk Semantic Retrieval',
|
||||
toolQuery: 'Query',
|
||||
toolFound: 'Found',
|
||||
toolRetrieved: 'Retrieved',
|
||||
toolResults: 'results',
|
||||
toolChunks: 'Fragment',
|
||||
toolMoreResults: 'more results',
|
||||
toolMoreChunks: 'more chunks',
|
||||
toolDocumentChunk: 'Document Chunk',
|
||||
|
||||
// 状态消息
|
||||
statusSearching: 'Searching...',
|
||||
statusProcessing: 'Processing...',
|
||||
statusCompleted: 'Completed',
|
||||
statusError: 'Error occurred',
|
||||
|
||||
// 工具汇总相关
|
||||
toolExecutionSummary: 'Tool Execution Summary',
|
||||
resultsText: 'results',
|
||||
tooltip: 'AI can make mistakes. Please check important info'
|
||||
},
|
||||
};
|
||||
|
||||
// 获取浏览器首选语言
|
||||
export function getBrowserLanguage(): Language {
|
||||
if (typeof window === 'undefined') return 'zh'; // SSR fallback
|
||||
|
||||
const browserLang = navigator.language.toLowerCase();
|
||||
|
||||
// 检查是否为中文
|
||||
if (browserLang.startsWith('zh')) {
|
||||
return 'zh';
|
||||
}
|
||||
|
||||
// 默认返回英文
|
||||
return 'en';
|
||||
}
|
||||
|
||||
// 从URL参数获取语言设置
|
||||
export function getLanguageFromURL(): Language | null {
|
||||
if (typeof window === 'undefined') return null; // SSR fallback
|
||||
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const langParam = urlParams.get('lang')?.toLowerCase();
|
||||
|
||||
if (langParam === 'zh' || langParam === 'en') {
|
||||
return langParam as Language;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
// 获取当前应该使用的语言
|
||||
export function getCurrentLanguage(): Language {
|
||||
// 优先使用URL参数
|
||||
const urlLang = getLanguageFromURL();
|
||||
if (urlLang) {
|
||||
return urlLang;
|
||||
}
|
||||
|
||||
// 其次使用localStorage保存的语言
|
||||
if (typeof window !== 'undefined') {
|
||||
const savedLang = localStorage.getItem('preferred-language') as Language;
|
||||
if (savedLang && (savedLang === 'zh' || savedLang === 'en')) {
|
||||
return savedLang;
|
||||
}
|
||||
}
|
||||
|
||||
// 最后使用浏览器语言
|
||||
return getBrowserLanguage();
|
||||
}
|
||||
|
||||
// 保存语言设置到localStorage
|
||||
export function saveLanguagePreference(language: Language) {
|
||||
if (typeof window !== 'undefined') {
|
||||
localStorage.setItem('preferred-language', language);
|
||||
}
|
||||
}
|
||||
|
||||
// 切换语言并更新URL
|
||||
export function switchLanguage(language: Language) {
|
||||
saveLanguagePreference(language);
|
||||
|
||||
if (typeof window !== 'undefined') {
|
||||
const url = new URL(window.location.href);
|
||||
url.searchParams.set('lang', language);
|
||||
window.history.replaceState({}, '', url.toString());
|
||||
|
||||
// 触发重新渲染
|
||||
window.dispatchEvent(new Event('languagechange'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user