From bb64c1c7534b46025413b1609693cb028d3d466c Mon Sep 17 00:00:00 2001 From: Mocilac Date: Fri, 25 Jul 2025 10:30:50 +0200 Subject: [PATCH] added language support for task tooltip --- src/components/TaskBar.vue | 24 +++++++++++++++++------- src/composables/useI18n.ts | 2 ++ 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/components/TaskBar.vue b/src/components/TaskBar.vue index 37ed492..3d9faa1 100644 --- a/src/components/TaskBar.vue +++ b/src/components/TaskBar.vue @@ -3,6 +3,10 @@ import { ref, computed, onUnmounted, onMounted, nextTick, watch } from 'vue' import type { Task } from '../models/classes/Task' import { TimelineScale } from '../models/types/TimelineScale' + +import { useI18n } from '../composables/useI18n' + + interface Props { task: Task rowHeight: number @@ -30,6 +34,12 @@ interface Props { const props = defineProps() +const { setLocale, getTranslation } = useI18n() + +const t = (key: string): string => { + return getTranslation(key) +} + const emit = defineEmits([ 'update:task', 'bar-mounted', @@ -825,9 +835,9 @@ const handleBubbleMouseDown = (event: MouseEvent) => { // 格式化日期显示 const formatDisplayDate = (dateStr: string | undefined): string => { - if (!dateStr) return '未设置' + if (!dateStr) return t('dateNotSet') const date = createLocalDate(dateStr) - if (!date) return '未设置' + if (!date) return t('dateNotSet') const year = date.getFullYear() const month = String(date.getMonth() + 1).padStart(2, '0') @@ -1065,23 +1075,23 @@ const calculatePositionFromTimelineData = (
{{ task.name }}
- 计划开始: + {{ t('startDate') }}: {{ formatDisplayDate(task.startDate) }}
- 计划结束: + {{ t('endDate') }}: {{ formatDisplayDate(task.endDate) }}
- 计划工时: + {{ t('estimatedHours') }}: {{ workHourInfo.total }}h
- 已用工时: + {{ t('actualHours') }}: {{ workHourInfo.used }}h
- 完成率: + {{ t('progress') }}: {{ task.progress || 0 }}%
diff --git a/src/composables/useI18n.ts b/src/composables/useI18n.ts index 5eb906b..c126f53 100644 --- a/src/composables/useI18n.ts +++ b/src/composables/useI18n.ts @@ -6,6 +6,7 @@ export type Locale = 'zh-CN' | 'en-US' // 多语言配置 const messages = { 'zh-CN': { + dateNotSet: '未设置', // TaskList Header taskName: '任务名称', predecessor: '前置任务', @@ -158,6 +159,7 @@ const messages = { days: '天', }, 'en-US': { + dateNotSet:'Not set', // TaskList Header taskName: 'Task Name', predecessor: 'Predecessor',