feat: Integrate vue-i18n for multilingual support across components
- Added vue-i18n integration to various components for dynamic text translation. - Updated text placeholders, button labels, and error messages to utilize translation functions. - Enhanced user experience by providing localized content in the Knowledge Base, chat components, and settings. - Removed hardcoded strings and replaced them with translation keys for better maintainability and scalability.
This commit is contained in:
@@ -2,32 +2,32 @@
|
||||
<div class="chunk-detail">
|
||||
<div class="info-section">
|
||||
<div class="info-field">
|
||||
<span class="field-label">片段ID:</span>
|
||||
<span class="field-label">{{ $t('chat.chunkIdLabel') }}</span>
|
||||
<span class="field-value"><code>{{ data.chunk_id }}</code></span>
|
||||
</div>
|
||||
<div class="info-field">
|
||||
<span class="field-label">文档ID:</span>
|
||||
<span class="field-label">{{ $t('chat.documentIdLabel') }}</span>
|
||||
<span class="field-value"><code>{{ data.knowledge_id }}</code></span>
|
||||
</div>
|
||||
<div class="info-field">
|
||||
<span class="field-label">位置:</span>
|
||||
<span class="field-value">第 {{ data.chunk_index }} 个片段</span>
|
||||
<span class="field-label">{{ $t('chat.positionLabel') }}</span>
|
||||
<span class="field-value">{{ $t('chat.chunkPositionValue', { index: data.chunk_index }) }}</span>
|
||||
</div>
|
||||
<div v-if="data.content_length" class="info-field">
|
||||
<span class="field-label">内容长度:</span>
|
||||
<span class="field-value">{{ data.content_length }} 字符</span>
|
||||
<span class="field-label">{{ $t('chat.contentLengthLabelSimple') }}</span>
|
||||
<span class="field-value">{{ $t('chat.lengthChars', { value: data.content_length }) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="info-section">
|
||||
<div class="info-section-title">完整内容</div>
|
||||
<div class="info-section-title">{{ $t('chat.fullContentLabel') }}</div>
|
||||
<div class="full-content">{{ data.content }}</div>
|
||||
</div>
|
||||
|
||||
<div class="info-section">
|
||||
<div class="action-buttons">
|
||||
<button class="action-button" @click="copyToClipboard">
|
||||
📋 复制内容
|
||||
📋 {{ $t('chat.copyContent') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -37,11 +37,14 @@
|
||||
<script setup lang="ts">
|
||||
import { defineProps } from 'vue';
|
||||
import type { ChunkDetailData } from '@/types/tool-results';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
const props = defineProps<{
|
||||
data: ChunkDetailData;
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const copyToClipboard = () => {
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(props.data.content);
|
||||
|
||||
@@ -8,11 +8,11 @@
|
||||
</div>
|
||||
<div v-if="hasInfo" class="info-section">
|
||||
<div v-if="chunkId" class="info-field">
|
||||
<span class="field-label">片段ID:</span>
|
||||
<span class="field-label">{{ $t('chat.chunkIdLabel') }}</span>
|
||||
<span class="field-value"><code>{{ chunkId }}</code></span>
|
||||
</div>
|
||||
<div v-if="knowledgeId" class="info-field">
|
||||
<span class="field-label">文档ID:</span>
|
||||
<span class="field-label">{{ $t('chat.documentIdLabel') }}</span>
|
||||
<span class="field-value"><code>{{ knowledgeId }}</code></span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
<div class="database-query-display">
|
||||
<!-- Query Display -->
|
||||
<div v-if="data.query" class="query-section">
|
||||
<div class="section-header">执行的 SQL 查询:</div>
|
||||
<div class="section-header">{{ $t('chat.sqlQueryExecuted') }}</div>
|
||||
<pre class="query-code">{{ data.query }}</pre>
|
||||
</div>
|
||||
|
||||
<!-- Results Summary -->
|
||||
<div class="results-summary">
|
||||
<strong>返回结果:</strong> {{ data.row_count }} 行
|
||||
<span v-if="data.columns"> × {{ data.columns.length }} 列</span>
|
||||
<strong>{{ $t('chat.sqlResultsLabel') }}</strong> {{ data.row_count }} {{ $t('chat.rowsLabel') }}
|
||||
<span v-if="data.columns"> × {{ data.columns.length }} {{ $t('chat.columnsLabel') }}</span>
|
||||
</div>
|
||||
|
||||
<!-- Results Table -->
|
||||
@@ -32,23 +32,25 @@
|
||||
|
||||
<!-- No Results -->
|
||||
<div v-else class="no-results">
|
||||
未找到匹配的记录
|
||||
{{ $t('chat.noDatabaseRecords') }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { DatabaseQueryData } from '@/types/tool-results';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
interface Props {
|
||||
data: DatabaseQueryData;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
const { t } = useI18n();
|
||||
|
||||
const formatValue = (value: any): string => {
|
||||
if (value === null || value === undefined) {
|
||||
return '<NULL>';
|
||||
return t('chat.nullValuePlaceholder');
|
||||
}
|
||||
if (typeof value === 'object') {
|
||||
return JSON.stringify(value);
|
||||
|
||||
@@ -3,25 +3,25 @@
|
||||
<div class="info-card">
|
||||
<div class="info-section">
|
||||
<div class="info-field">
|
||||
<span class="field-label">文档ID:</span>
|
||||
<span class="field-label">{{ $t('chat.documentIdLabel') }}</span>
|
||||
<span class="field-value"><code>{{ data.knowledge_id }}</code></span>
|
||||
</div>
|
||||
<div class="info-field">
|
||||
<span class="field-label">文档标题:</span>
|
||||
<span class="field-label">{{ $t('chat.documentTitleLabel') }}</span>
|
||||
<span class="field-value">{{ data.title }}</span>
|
||||
</div>
|
||||
<div class="info-field">
|
||||
<span class="field-label">片段数量:</span>
|
||||
<span class="field-value">至少 {{ data.chunk_count_min }} 个</span>
|
||||
<span class="field-label">{{ $t('chat.chunkCountLabel') }}</span>
|
||||
<span class="field-value">{{ $t('chat.chunkCountValue', { count: data.chunk_count_min }) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="status-section">
|
||||
<div class="status-title">状态说明</div>
|
||||
<div class="status-title">{{ $t('chat.statusDescription') }}</div>
|
||||
<div class="status-list">
|
||||
<div class="status-item">✓ 文档已索引并可搜索</div>
|
||||
<div class="status-item">✓ 可使用搜索工具查找文档内容</div>
|
||||
<div class="status-item">✓ 可使用 get_chunk_detail 查看片段详情</div>
|
||||
<div class="status-item">✓ {{ $t('chat.statusIndexed') }}</div>
|
||||
<div class="status-item">✓ {{ $t('chat.statusSearchable') }}</div>
|
||||
<div class="status-item">✓ {{ $t('chat.statusChunkDetailAvailable') }}</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
<div class="graph-query-results">
|
||||
<!-- Graph Configuration Card -->
|
||||
<div v-if="data.graph_config" class="stats-card">
|
||||
<div class="stats-title">图谱配置</div>
|
||||
<div class="stats-title">{{ $t('chat.graphConfigTitle') }}</div>
|
||||
<div class="info-field">
|
||||
<span class="field-label">实体类型:</span>
|
||||
<span class="field-label">{{ $t('chat.entityTypesLabel') }}</span>
|
||||
<span class="field-value">{{ data.graph_config.nodes.join(', ') }}</span>
|
||||
</div>
|
||||
<div class="info-field">
|
||||
<span class="field-label">关系类型:</span>
|
||||
<span class="field-label">{{ $t('chat.relationTypesLabel') }}</span>
|
||||
<span class="field-value">{{ data.graph_config.relations.join(', ') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
@@ -16,7 +16,7 @@
|
||||
<!-- Results List -->
|
||||
<div v-if="data.results && data.results.length > 0" class="results-list">
|
||||
<div class="results-header">
|
||||
找到 {{ data.count }} 条相关结果
|
||||
{{ $t('chat.graphResultsHeader', { count: data.count }) }}
|
||||
</div>
|
||||
|
||||
<div
|
||||
@@ -28,7 +28,7 @@
|
||||
<div class="result-title">
|
||||
<span class="result-index">#{{ result.result_index }}</span>
|
||||
<span class="relevance-badge" :class="getRelevanceClass(result.relevance_level)">
|
||||
{{ result.relevance_level }}
|
||||
{{ getRelevanceLabel(result.relevance_level) }}
|
||||
</span>
|
||||
<span class="knowledge-title">{{ result.knowledge_title }}</span>
|
||||
</div>
|
||||
@@ -47,7 +47,7 @@
|
||||
</div>
|
||||
|
||||
<div v-else class="empty-state">
|
||||
未找到相关的图谱信息
|
||||
{{ $t('chat.graphNoResults') }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -55,11 +55,14 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, defineProps } from 'vue';
|
||||
import type { GraphQueryResultsData, RelevanceLevel } from '@/types/tool-results';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
const props = defineProps<{
|
||||
data: GraphQueryResultsData;
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const expandedResults = ref<string[]>([]);
|
||||
|
||||
const toggleResult = (chunkId: string) => {
|
||||
@@ -80,6 +83,16 @@ const getRelevanceClass = (level: RelevanceLevel): string => {
|
||||
};
|
||||
return classMap[level] || 'weak';
|
||||
};
|
||||
|
||||
const getRelevanceLabel = (level: RelevanceLevel): string => {
|
||||
const labelMap: Record<RelevanceLevel, string> = {
|
||||
'高相关': t('chat.relevanceHigh'),
|
||||
'中相关': t('chat.relevanceMedium'),
|
||||
'低相关': t('chat.relevanceLow'),
|
||||
'弱相关': t('chat.relevanceWeak'),
|
||||
};
|
||||
return labelMap[level] || level;
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
<div class="knowledge-base-list">
|
||||
<div v-if="data.knowledge_bases && data.knowledge_bases.length > 0">
|
||||
<div class="stats-card">
|
||||
<div class="stats-title">共 {{ data.count }} 个知识库</div>
|
||||
<div class="stats-title">{{ $t('chat.knowledgeBaseCount', { count: data.count }) }}</div>
|
||||
</div>
|
||||
|
||||
<div class="card-grid">
|
||||
@@ -29,7 +29,7 @@
|
||||
</div>
|
||||
|
||||
<div v-else class="empty-state">
|
||||
没有可用的知识库
|
||||
{{ $t('chat.noKnowledgeBases') }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
</div>
|
||||
|
||||
<div v-else class="no-steps">
|
||||
未提供具体步骤
|
||||
{{ $t('chat.noPlanSteps') }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -22,8 +22,8 @@
|
||||
</template>
|
||||
<div class="result-header">
|
||||
<div class="result-title">
|
||||
<span class="chunk-index">片段 #{{ chunk.index }}</span>
|
||||
<span class="chunk-position">(位置: {{ chunk.chunk_index }})</span>
|
||||
<span class="chunk-index">{{ $t('chat.chunkIndexLabel', { index: chunk.index }) }}</span>
|
||||
<span class="chunk-position">{{ $t('chat.chunkPositionLabel', { position: chunk.chunk_index }) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</t-popup>
|
||||
@@ -31,7 +31,7 @@
|
||||
</div>
|
||||
|
||||
<div v-else class="empty-state">
|
||||
没有找到相关片段
|
||||
{{ $t('chat.noRelatedChunks') }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<div class="result-title">
|
||||
<span class="result-index">#{{ result.result_index }}</span>
|
||||
<span class="relevance-badge" :class="getRelevanceClass(result.relevance_level)">
|
||||
{{ result.relevance_level }}
|
||||
{{ getRelevanceLabel(result.relevance_level) }}
|
||||
</span>
|
||||
<span class="knowledge-title">{{ result.knowledge_title }}</span>
|
||||
</div>
|
||||
@@ -37,7 +37,7 @@
|
||||
|
||||
<!-- Empty State -->
|
||||
<div v-else class="empty-state">
|
||||
没有找到搜索结果
|
||||
{{ $t('chat.noSearchResults') }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -47,12 +47,15 @@ import { ref, defineProps, computed } from 'vue';
|
||||
import type { SearchResultsData, SearchResultItem, RelevanceLevel } from '@/types/tool-results';
|
||||
import { getMatchTypeIcon } from '@/utils/tool-icons';
|
||||
import ContentPopup from './ContentPopup.vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
const props = defineProps<{
|
||||
data: SearchResultsData;
|
||||
arguments?: Record<string, any> | string;
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const results = computed(() => props.data.results || []);
|
||||
const kbCounts = computed(() => props.data.kb_counts);
|
||||
|
||||
@@ -105,6 +108,16 @@ const getRelevanceClass = (level: RelevanceLevel): string => {
|
||||
};
|
||||
return classMap[level] || 'weak';
|
||||
};
|
||||
|
||||
const getRelevanceLabel = (level: RelevanceLevel): string => {
|
||||
const labelMap: Record<RelevanceLevel, string> = {
|
||||
'高相关': t('chat.relevanceHigh'),
|
||||
'中相关': t('chat.relevanceMedium'),
|
||||
'低相关': t('chat.relevanceLow'),
|
||||
'弱相关': t('chat.relevanceWeak'),
|
||||
};
|
||||
return labelMap[level] || level;
|
||||
};
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<div class="thinking-display">
|
||||
<div class="thinking-content">
|
||||
<div class="thinking-icon">💭</div>
|
||||
<div class="thinking-icon" aria-hidden="true">💭</div>
|
||||
<div class="thinking-text">{{ data.thought }}</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -10,10 +10,13 @@
|
||||
<script setup lang="ts">
|
||||
import { defineProps } from 'vue';
|
||||
import type { ThinkingData } from '@/types/tool-results';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
const props = defineProps<{
|
||||
data: ThinkingData;
|
||||
}>();
|
||||
|
||||
useI18n(); // ensure component reacts to locale changes if needed
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
|
||||
@@ -19,11 +19,11 @@
|
||||
>
|
||||
<span class="result-domain">{{ safeHostname(item.url) }}</span>
|
||||
</a>
|
||||
<span v-else class="result-domain">未知链接</span>
|
||||
<span v-else class="result-domain">{{ $t('chat.unknownLink') }}</span>
|
||||
</div>
|
||||
<div class="result-meta">
|
||||
<span v-if="item.method" class="meta-pill">{{ formatMethod(item.method) }}</span>
|
||||
<span v-if="item.content_length" class="meta-text">长度 {{ formatLength(item.content_length) }}</span>
|
||||
<span v-if="item.content_length" class="meta-text">{{ $t('chat.contentLengthLabel', { value: formatLength(item.content_length) }) }}</span>
|
||||
<t-icon
|
||||
:name="isExpanded(index) ? 'chevron-up' : 'chevron-down'"
|
||||
class="expand-icon"
|
||||
@@ -42,29 +42,29 @@
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
>{{ item.url }}</a>
|
||||
<span v-else>未提供</span>
|
||||
<span v-else>{{ $t('chat.notProvided') }}</span>
|
||||
</span>
|
||||
</div>
|
||||
<div v-if="item.prompt" class="info-field">
|
||||
<span class="field-label">提示词</span>
|
||||
<span class="field-label">{{ $t('chat.promptLabel') }}</span>
|
||||
<span class="field-value">{{ item.prompt }}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="item.error" class="info-section">
|
||||
<div class="info-section-title error">错误信息</div>
|
||||
<div class="info-section-title error">{{ $t('chat.errorMessageLabel') }}</div>
|
||||
<div class="full-content error-text">{{ item.error }}</div>
|
||||
</div>
|
||||
|
||||
<div v-else>
|
||||
<div v-if="item.summary" class="info-section">
|
||||
<div class="info-section-title">总结</div>
|
||||
<div class="info-section-title">{{ $t('chat.summaryLabel') }}</div>
|
||||
<div class="full-content">{{ item.summary }}</div>
|
||||
</div>
|
||||
|
||||
<div v-if="item.raw_content" class="info-section">
|
||||
<div class="info-section-title">
|
||||
原始文本
|
||||
{{ $t('chat.rawTextLabel') }}
|
||||
<span class="raw-length" v-if="item.content_length">
|
||||
({{ formatLength(item.content_length) }})
|
||||
</span>
|
||||
@@ -76,7 +76,7 @@
|
||||
{{ truncate(item.raw_content) }}
|
||||
</div>
|
||||
<button class="action-button" @click.stop="toggleRaw(index)">
|
||||
{{ isRawExpanded(index) ? '收起原文' : '展开原文' }}
|
||||
{{ isRawExpanded(index) ? $t('chat.collapseRaw') : $t('chat.expandRaw') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -84,19 +84,21 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-else class="empty-state">未获取到网页内容</div>
|
||||
<div v-else class="empty-state">{{ $t('chat.noWebContent') }}</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import type { WebFetchResultsData, WebFetchResultItem } from '@/types/tool-results';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
interface Props {
|
||||
data: WebFetchResultsData;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
const { t } = useI18n();
|
||||
|
||||
const items = computed<WebFetchResultItem[]>(() => props.data.results || []);
|
||||
const expandedCards = ref<Set<number>>(new Set());
|
||||
@@ -147,14 +149,14 @@ const safeHostname = (url: string): string => {
|
||||
};
|
||||
|
||||
const formatLength = (length: number): string => {
|
||||
if (!length || Number.isNaN(length)) return '0';
|
||||
if (!length || Number.isNaN(length)) return t('chat.lengthChars', { value: 0 });
|
||||
if (length >= 10000) {
|
||||
return `${(length / 10000).toFixed(1)} 万字`;
|
||||
return t('chat.lengthTenThousands', { value: (length / 10000).toFixed(1) });
|
||||
}
|
||||
if (length >= 1000) {
|
||||
return `${(length / 1000).toFixed(1)} 千字`;
|
||||
return t('chat.lengthThousands', { value: (length / 1000).toFixed(1) });
|
||||
}
|
||||
return `${length} 字`;
|
||||
return t('chat.lengthChars', { value: length });
|
||||
};
|
||||
|
||||
const formatMethod = (method: string): string => {
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
class="results-group"
|
||||
>
|
||||
<!-- <div class="group-header">
|
||||
<span class="group-intro">以下 {{ group.items.length }} 条内容来自</span>
|
||||
<span class="group-intro">{{ $t('chat.webGroupIntro', { count: group.items.length }) }}</span>
|
||||
<span class="group-source">{{ group.label }}</span>
|
||||
</div> -->
|
||||
<div class="results-list">
|
||||
@@ -47,7 +47,7 @@
|
||||
|
||||
<!-- Empty State -->
|
||||
<div v-else class="empty-state">
|
||||
未找到搜索结果
|
||||
{{ $t('chat.webSearchNoResults') }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -55,12 +55,14 @@
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
import type { WebSearchResultsData, WebSearchResultItem } from '@/types/tool-results';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
interface Props {
|
||||
data: WebSearchResultsData;
|
||||
}
|
||||
|
||||
const props = defineProps<Props>();
|
||||
const { t, locale } = useI18n();
|
||||
|
||||
const results = computed(() => props.data.results || []);
|
||||
|
||||
@@ -79,7 +81,7 @@ const groupedResults = computed<Group[]>(() => {
|
||||
} else {
|
||||
// fallback to domain
|
||||
const url = (item as any).url as string | undefined;
|
||||
const hostname = url ? safeHostname(url) : '其他';
|
||||
const hostname = url ? safeHostname(url) : t('chat.otherSource');
|
||||
key = `dom:${hostname}`;
|
||||
label = hostname;
|
||||
}
|
||||
@@ -94,7 +96,7 @@ const groupedResults = computed<Group[]>(() => {
|
||||
for (const item of list) {
|
||||
const source = (item as any).source as string | undefined;
|
||||
const url = (item as any).url as string | undefined;
|
||||
const hostname = url ? safeHostname(url) : '其他';
|
||||
const hostname = url ? safeHostname(url) : t('chat.otherSource');
|
||||
const key = source && source.trim() ? `src:${source.trim()}` : `dom:${hostname}`;
|
||||
if (!seen.has(key)) {
|
||||
seen.add(key);
|
||||
@@ -118,7 +120,7 @@ const safeHostname = (url: string): string => {
|
||||
const urlObj = new URL(url);
|
||||
return urlObj.hostname;
|
||||
} catch {
|
||||
return '其他';
|
||||
return t('chat.otherSource');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -131,7 +133,7 @@ const truncateContent = (content: string, maxLength: number = 300): string => {
|
||||
const formatDate = (dateStr: string): string => {
|
||||
try {
|
||||
const date = new Date(dateStr);
|
||||
return date.toLocaleDateString('zh-CN', {
|
||||
return date.toLocaleDateString(locale.value || 'zh-CN', {
|
||||
year: 'numeric',
|
||||
month: 'long',
|
||||
day: 'numeric'
|
||||
|
||||
Reference in New Issue
Block a user