fix: language

This commit is contained in:
王性驊 2025-09-11 19:45:25 +08:00
parent 036f8186f4
commit 9039fb1a57
2 changed files with 14 additions and 6 deletions

View File

@ -1,10 +1,9 @@
<script setup> <script setup>
import Taskbar from '~/components/Taskbar.vue'; import Taskbar from '~/components/Taskbar.vue';
import AboutMeWindow from '~/components/AboutMeWindow.vue'; import AboutMeWindow from '~/components/AboutMeWindow.vue';
import { ref, reactive, onMounted, onUnmounted, computed, watch } from 'vue'; import { ref, reactive, onMounted, onUnmounted, computed } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
const { locale } = useI18n();
// Reactive array to hold all window states // Reactive array to hold all window states
const windows = reactive([]); const windows = reactive([]);

View File

@ -48,7 +48,7 @@ defineProps({
}, },
}); });
const currentTime = ref(new Date().toLocaleTimeString()); const currentTime = ref('');
const isMounted = ref(false); const isMounted = ref(false);
let timerId = null; let timerId = null;
const showStartMenu = ref(false); const showStartMenu = ref(false);
@ -79,11 +79,20 @@ const restoreMinimizedWindow = (id) => {
emit('restore-window', id); emit('restore-window', id);
}; };
const updateCurrentTime = () => {
// Map i18n locale to a specific locale for time formatting
const timeLocale = locale.value === 'zh-tw' ? 'zh-TW' : 'en-US';
currentTime.value = new Date().toLocaleTimeString(timeLocale);
};
// Watch for locale changes to update the time format immediately
watch(locale, updateCurrentTime);
onMounted(() => { onMounted(() => {
isMounted.value = true; isMounted.value = true;
timerId = setInterval(() => { updateCurrentTime(); // Set initial time based on current locale
currentTime.value = new Date().toLocaleTimeString(); timerId = setInterval(updateCurrentTime, 1000);
}, 1000);
}); });
onUnmounted(() => { onUnmounted(() => {