mirror of
https://github.com/setube/ogame-vue-ts.git
synced 2026-05-12 07:55:11 +08:00
重构BattleReportDialog和BattleSimulatorView相关静态资源,替换旧版JS/CSS文件,提升界面一致性和交互体验。新增和优化空状态、滚动区域等通用UI组件,移除部分冗余composable,完善多语言内容。引入导弹逻辑,补充版本检测工具,提升整体代码结构和可维护性。
48 lines
1.1 KiB
TypeScript
48 lines
1.1 KiB
TypeScript
import { computed } from 'vue'
|
|
import { useGameStore } from '@/stores/gameStore'
|
|
import { locales, type Locale } from '@/locales'
|
|
|
|
export const useI18n = () => {
|
|
const gameStore = useGameStore()
|
|
|
|
const currentLocale = computed(() => gameStore.locale)
|
|
|
|
const messages = computed(() => locales[currentLocale.value])
|
|
|
|
// 获取翻译文本的辅助函数
|
|
const t = (key: string, params?: Record<string, string | number>): string => {
|
|
const keys = key.split('.')
|
|
let value: any = messages.value
|
|
|
|
for (const k of keys) {
|
|
if (value && typeof value === 'object' && k in value) {
|
|
value = value[k]
|
|
} else {
|
|
return key // 如果找不到翻译,返回原始 key
|
|
}
|
|
}
|
|
|
|
let result = typeof value === 'string' ? value : key
|
|
|
|
// 替换参数占位符
|
|
if (params) {
|
|
Object.entries(params).forEach(([paramKey, paramValue]) => {
|
|
result = result.replace(new RegExp(`\\{${paramKey}\\}`, 'g'), String(paramValue))
|
|
})
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
const setLocale = (locale: Locale) => {
|
|
gameStore.locale = locale
|
|
}
|
|
|
|
return {
|
|
t,
|
|
locale: currentLocale,
|
|
setLocale,
|
|
messages
|
|
}
|
|
}
|