mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-09-13 11:04:25 +08:00
refactor: 删除部分多余的代码和注释
This commit is contained in:
@@ -2,7 +2,6 @@ import { createI18n } from 'vue-i18n'
|
||||
import zhCN from './zh-CN'
|
||||
import enUS from './en-US'
|
||||
|
||||
// Supported languages
|
||||
export const supportedLanguages = [
|
||||
{ code: 'zh-CN', name: '中文', flag: '🇨🇳' },
|
||||
{ code: 'en-US', name: 'English', flag: '🇺🇸' },
|
||||
@@ -10,33 +9,26 @@ export const supportedLanguages = [
|
||||
|
||||
export type SupportedLocale = (typeof supportedLanguages)[number]['code']
|
||||
|
||||
// Detect browser language with improved logic
|
||||
function detectLanguage(): SupportedLocale {
|
||||
// 1. Check localStorage for saved preference
|
||||
const stored = localStorage.getItem('language')
|
||||
if (stored && supportedLanguages.some((l) => l.code === stored)) {
|
||||
return stored as SupportedLocale
|
||||
}
|
||||
|
||||
// 2. Check browser language list (navigator.languages is more comprehensive)
|
||||
const languages = navigator.languages || [navigator.language]
|
||||
for (const lang of languages) {
|
||||
const normalizedLang = lang.toLowerCase()
|
||||
// Check for Chinese variants (zh, zh-CN, zh-TW, zh-HK, etc.)
|
||||
if (normalizedLang.startsWith('zh')) {
|
||||
return 'zh-CN'
|
||||
}
|
||||
// Check for English variants
|
||||
if (normalizedLang.startsWith('en')) {
|
||||
return 'en-US'
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Default to English
|
||||
return 'en-US'
|
||||
}
|
||||
|
||||
// Initialize language and set HTML lang attribute
|
||||
function initializeLanguage(): SupportedLocale {
|
||||
const lang = detectLanguage()
|
||||
document.documentElement.setAttribute('lang', lang)
|
||||
|
||||
Reference in New Issue
Block a user