mirror of
https://github.com/setube/ogame-vue-ts.git
synced 2026-05-12 07:55:11 +08:00
引入项目基础目录结构,包含多语言支持、主要页面与组件、核心游戏逻辑、UI 组件库、加密与本地持久化、自动化 Docker 构建流程、GitHub issue 模板(中英文)、README(中英文)、LICENSE 及开发配置文件。实现 OGame 单机版主要功能模块,为后续开发和扩展奠定基础。
39 lines
888 B
TypeScript
39 lines
888 B
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): 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
|
|
}
|
|
}
|
|
|
|
return typeof value === 'string' ? value : key
|
|
}
|
|
|
|
const setLocale = (locale: Locale) => {
|
|
gameStore.locale = locale
|
|
}
|
|
|
|
return {
|
|
t,
|
|
locale: currentLocale,
|
|
setLocale,
|
|
messages
|
|
}
|
|
}
|