mirror of
https://github.com/Wei-Shaw/claude-relay-service.git
synced 2026-01-23 21:17:30 +00:00
feat: 实现i18n核心配置和语言状态管理
- 创建i18n配置系统,支持简体中文/繁体中文/英文三种语言 - 实现浏览器语言自动检测和localStorage持久化 - 添加基础翻译文件,包含common、language、header、apiStats模块 - 创建locale store使用Pinia管理语言状态 - 配置语言标识符为纯文字:简/繁/EN,去除国旗emoji
This commit is contained in:
42
web/admin-spa/src/stores/locale.js
Normal file
42
web/admin-spa/src/stores/locale.js
Normal file
@@ -0,0 +1,42 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { i18n, SUPPORTED_LOCALES } from '@/i18n'
|
||||
|
||||
export const useLocaleStore = defineStore('locale', () => {
|
||||
const currentLocale = ref(i18n.global.locale.value)
|
||||
|
||||
// 切换语言
|
||||
const setLocale = (locale) => {
|
||||
if (!SUPPORTED_LOCALES[locale]) {
|
||||
console.warn(`Unsupported locale: ${locale}`)
|
||||
return
|
||||
}
|
||||
|
||||
currentLocale.value = locale
|
||||
i18n.global.locale.value = locale
|
||||
localStorage.setItem('app-locale', locale)
|
||||
|
||||
// 更新HTML lang属性
|
||||
document.documentElement.setAttribute('lang', locale)
|
||||
}
|
||||
|
||||
// 获取当前语言信息
|
||||
const getCurrentLocaleInfo = () => {
|
||||
return SUPPORTED_LOCALES[currentLocale.value] || SUPPORTED_LOCALES['zh-cn']
|
||||
}
|
||||
|
||||
// 获取所有支持的语言
|
||||
const getSupportedLocales = () => {
|
||||
return Object.entries(SUPPORTED_LOCALES).map(([key, value]) => ({
|
||||
code: key,
|
||||
...value
|
||||
}))
|
||||
}
|
||||
|
||||
return {
|
||||
currentLocale,
|
||||
setLocale,
|
||||
getCurrentLocaleInfo,
|
||||
getSupportedLocales
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user