import { ref, computed } from 'vue' import i18n, { loadLocaleAsync } from '../i18n/index.js' const switching = ref(false) // 语言懒加载切换逻辑 // current 派生自全局 i18n composer 的 locale(composition 模式下在 i18n.global), // 与各组件内 useI18n({ useScope: 'global' }) 读到的是同一个 ref。 export function useI18nLazy() { const current = computed(() => i18n.global.locale.value) async function switchLocale(locale) { if (switching.value || current.value === locale) return switching.value = true try { await loadLocaleAsync(locale) } finally { switching.value = false } } return { current, switching, switchLocale } }