FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: 部分UI在英文设置下未国际化 · byesoft/ChatLab@fe0a2ed · GitHub

forked from ChatLab/ChatLab

Commit fe0a2ed

Browse files
committed
fix: 部分UI在英文设置下未国际化
1 parent bc6c385 commit fe0a2ed

12 files changed

Lines changed: 144 additions & 61 deletions

File tree

‎packages/chart-message/MessageView.vue‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ const monthNames = computed(() => [
7878
const typeChartData = computed<EChartPieData>(() => {
7979
const sorted = [...messageTypes.value].sort((a, b) => b.count - a.count)
8080
return {
81-
labels: sorted.map((item) => getMessageTypeName(item.type)),
81+
labels: sorted.map((item) => getMessageTypeName(item.type, t)),
8282
values: sorted.map((item) => item.count),
8383
}
8484
})
@@ -89,7 +89,7 @@ const typeSummary = computed(() => {
8989
const sorted = [...messageTypes.value].sort((a, b) => b.count - a.count)
9090
9191
return sorted.map((item) => ({
92-
name: getMessageTypeName(item.type),
92+
name: getMessageTypeName(item.type, t),
9393
count: item.count,
9494
percentage: total > 0 ? Math.round((item.count / total) * 100) : 0,
9595
}))

‎packages/chart-message/types.ts‎

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,32 +25,42 @@ export enum MessageType {
2525
OTHER = 99,
2626
}
2727

28-
/** 消息类型名称映射 */
29-
const MESSAGE_TYPE_NAMES: Record<number, string> = {
30-
[MessageType.TEXT]: '文字',
31-
[MessageType.IMAGE]: '图片',
32-
[MessageType.VOICE]: '语音',
33-
[MessageType.VIDEO]: '视频',
34-
[MessageType.FILE]: '文件',
35-
[MessageType.EMOJI]: '表情',
36-
[MessageType.LINK]: '链接',
37-
[MessageType.LOCATION]: '位置',
38-
[MessageType.RED_PACKET]: '红包',
39-
[MessageType.TRANSFER]: '转账',
40-
[MessageType.POKE]: '拍一拍',
41-
[MessageType.CALL]: '通话',
42-
[MessageType.SHARE]: '分享',
43-
[MessageType.REPLY]: '回复',
44-
[MessageType.FORWARD]: '转发',
45-
[MessageType.CONTACT]: '名片',
46-
[MessageType.SYSTEM]: '系统',
47-
[MessageType.RECALL]: '撤回',
48-
[MessageType.OTHER]: '其他',
28+
/** 消息类型 i18n key 映射 */
29+
const MESSAGE_TYPE_KEYS: Record<number, string> = {
30+
// 基础消息类型
31+
[MessageType.TEXT]: 'text',
32+
[MessageType.IMAGE]: 'image',
33+
[MessageType.VOICE]: 'voice',
34+
[MessageType.VIDEO]: 'video',
35+
[MessageType.FILE]: 'file',
36+
[MessageType.EMOJI]: 'emoji',
37+
[MessageType.LINK]: 'link',
38+
[MessageType.LOCATION]: 'location',
39+
// 交互消息类型
40+
[MessageType.RED_PACKET]: 'redPacket',
41+
[MessageType.TRANSFER]: 'transfer',
42+
[MessageType.POKE]: 'poke',
43+
[MessageType.CALL]: 'call',
44+
[MessageType.SHARE]: 'share',
45+
[MessageType.REPLY]: 'reply',
46+
[MessageType.FORWARD]: 'forward',
47+
[MessageType.CONTACT]: 'contact',
48+
// 系统消息类型
49+
[MessageType.SYSTEM]: 'system',
50+
[MessageType.RECALL]: 'recall',
51+
// 其他
52+
[MessageType.OTHER]: 'other',
4953
}
5054

51-
/** 获取消息类型名称 */
52-
export function getMessageTypeName(type: MessageType | number): string {
53-
return MESSAGE_TYPE_NAMES[type] || '未知'
55+
/**
56+
* 获取消息类型名称
57+
* @param type 消息类型
58+
* @param t 可选的 i18n t 函数,传入时使用 common.messageType.* 键
59+
*/
60+
export function getMessageTypeName(type: MessageType | number, t?: (key: string) => string): string {
61+
const key = MESSAGE_TYPE_KEYS[type]
62+
if (t && key) return t(`common.messageType.${key}`)
63+
return t ? t('common.messageType.unknown') : '未知'
5464
}
5565

5666
/** 小时活跃度 */

‎src/components/charts/EChartCalendar.vue‎

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* ECharts 日历热力图组件(GitHub 贡献图风格)
44
*/
55
import { computed, ref, watch, onMounted, onUnmounted } from 'vue'
6+
import { useI18n } from 'vue-i18n'
67
import * as echarts from 'echarts/core'
78
import { HeatmapChart } from 'echarts/charts'
89
import { CalendarComponent, TooltipComponent, VisualMapComponent } from 'echarts/components'
@@ -30,6 +31,7 @@ const props = withDefaults(defineProps<Props>(), {
3031
height: 180,
3132
})
3233
34+
const { t, locale } = useI18n()
3335
const isDark = useDark()
3436
const chartRef = ref<HTMLElement | null>(null)
3537
let chartInstance: echarts.ECharts | null = null
@@ -70,7 +72,7 @@ const option = computed<ECOption>(() => ({
7072
formatter: (params: any) => {
7173
const date = params.data[0]
7274
const value = params.data[1]
73-
return `${date}<br/>消息: ${value}`
75+
return `${date}<br/>${t('views.message.calendarTooltipMessages')}: ${value}`
7476
},
7577
},
7678
visualMap: {
@@ -111,13 +113,35 @@ const option = computed<ECOption>(() => ({
111113
show: true,
112114
color: isDark.value ? '#9ca3af' : '#6b7280',
113115
fontSize: 10,
116+
nameMap: [
117+
t('common.month.jan'),
118+
t('common.month.feb'),
119+
t('common.month.mar'),
120+
t('common.month.apr'),
121+
t('common.month.may'),
122+
t('common.month.jun'),
123+
t('common.month.jul'),
124+
t('common.month.aug'),
125+
t('common.month.sep'),
126+
t('common.month.oct'),
127+
t('common.month.nov'),
128+
t('common.month.dec'),
129+
],
114130
},
115131
dayLabel: {
116132
show: true,
117133
firstDay: 1, // 从周一开始
118134
color: isDark.value ? '#6b7280' : '#9ca3af',
119135
fontSize: 10,
120-
nameMap: ['', '', '', '', '', '', ''],
136+
nameMap: [
137+
t('common.weekday.sun'),
138+
t('common.weekday.mon'),
139+
t('common.weekday.tue'),
140+
t('common.weekday.wed'),
141+
t('common.weekday.thu'),
142+
t('common.weekday.fri'),
143+
t('common.weekday.sat'),
144+
],
121145
},
122146
splitLine: {
123147
show: false,
@@ -153,8 +177,8 @@ function handleResize() {
153177
chartInstance?.resize()
154178
}
155179
156-
// 监听数据和主题变化
157-
watch([() => props.data, isDark], () => {
180+
// 监听数据、主题、语言变化
181+
watch([() => props.data, isDark, locale], () => {
158182
updateChart()
159183
})
160184

‎src/i18n/locales/en-US/common.json‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@
4040
"members": "members",
4141
"days": "days"
4242
},
43+
"messageType": {
44+
"text": "Text",
45+
"image": "Image",
46+
"voice": "Voice",
47+
"video": "Video",
48+
"file": "File",
49+
"emoji": "Emoji",
50+
"link": "Link",
51+
"location": "Location",
52+
"redPacket": "Red Packet",
53+
"transfer": "Transfer",
54+
"poke": "Poke",
55+
"call": "Call",
56+
"share": "Share",
57+
"reply": "Reply",
58+
"forward": "Forward",
59+
"contact": "Contact",
60+
"system": "System",
61+
"recall": "Recalled",
62+
"other": "Other",
63+
"unknown": "Unknown"
64+
},
4365
"weekday": {
4466
"mon": "Mon",
4567
"tue": "Tue",

‎src/i18n/locales/en-US/views.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"heatmapHint": "Shows chat time patterns",
3838
"calendarHeatmap": "Message Calendar",
3939
"calendarHint": "Daily message distribution",
40+
"calendarTooltipMessages": "Messages",
4041
"lengthDetailTitle": "Short Messages (1-25 chars)",
4142
"lengthDetailHint": "Per character",
4243
"lengthGroupedTitle": "Length Range Distribution",

‎src/i18n/locales/zh-CN/common.json‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,28 @@
4040
"members": "个成员",
4141
"days": ""
4242
},
43+
"messageType": {
44+
"text": "文字",
45+
"image": "图片",
46+
"voice": "语音",
47+
"video": "视频",
48+
"file": "文件",
49+
"emoji": "表情",
50+
"link": "链接",
51+
"location": "位置",
52+
"redPacket": "红包",
53+
"transfer": "转账",
54+
"poke": "拍一拍",
55+
"call": "通话",
56+
"share": "分享",
57+
"reply": "回复",
58+
"forward": "转发",
59+
"contact": "名片",
60+
"system": "系统",
61+
"recall": "撤回",
62+
"other": "其他",
63+
"unknown": "未知"
64+
},
4365
"weekday": {
4466
"mon": "周一",
4567
"tue": "周二",

‎src/i18n/locales/zh-CN/views.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
"heatmapHint": "展示聊天时间规律",
3838
"calendarHeatmap": "消息日历",
3939
"calendarHint": "每日消息分布",
40+
"calendarTooltipMessages": "消息",
4041
"lengthDetailTitle": "短消息分布 (1-25字)",
4142
"lengthDetailHint": "逐字统计",
4243
"lengthGroupedTitle": "长度区间分布",

‎src/pages/group-chat/components/OverviewTab.vue‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ const { dailyChartData } = useDailyTrend(props.dailyActivity)
5656
// 消息类型图表数据
5757
const typeChartData = computed<EChartPieData>(() => {
5858
return {
59-
labels: props.messageTypes.map((t) => getMessageTypeName(t.type)),
60-
values: props.messageTypes.map((t) => t.count),
59+
labels: props.messageTypes.map((item) => getMessageTypeName(item.type, t)),
60+
values: props.messageTypes.map((item) => item.count),
6161
}
6262
})
6363

‎src/pages/group-chat/index.vue‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ onMounted(() => {
208208
icon="i-heroicons-plus-circle"
209209
@click="showIncrementalImportModal = true"
210210
>
211-
{{ t('analysis.incrementalImport', '增量导入') }}
211+
{{ t('analysis.tooltip.incrementalImport') }}
212212
</UButton>
213213
<UButton
214214
color="primary"
@@ -217,7 +217,7 @@ onMounted(() => {
217217
icon="i-heroicons-chat-bubble-bottom-center-text"
218218
@click="openChatRecordViewer"
219219
>
220-
{{ t('analysis.chatViewer', '聊天记录查看器') }}
220+
{{ t('analysis.tooltip.chatViewer') }}
221221
</UButton>
222222
<UTooltip :text="t('analysis.tooltip.sessionIndex')">
223223
<UButton

‎src/pages/private-chat/components/OverviewTab.vue‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ const { dailyChartData } = useDailyTrend(props.dailyActivity)
5454
// 消息类型图表数据
5555
const typeChartData = computed<EChartPieData>(() => {
5656
return {
57-
labels: props.messageTypes.map((t) => getMessageTypeName(t.type)),
58-
values: props.messageTypes.map((t) => t.count),
57+
labels: props.messageTypes.map((item) => getMessageTypeName(item.type, t)),
58+
values: props.messageTypes.map((item) => item.count),
5959
}
6060
})
6161

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL