51 lines
1.1 KiB
TypeScript
51 lines
1.1 KiB
TypeScript
import { createApp } from 'vue'
|
|
import { createPinia } from 'pinia'
|
|
import { createI18n } from 'vue-i18n'
|
|
import App from './App.vue'
|
|
import router from './router'
|
|
import hu from './i18n/hu'
|
|
import en from './i18n/en'
|
|
import './assets/main.css'
|
|
|
|
const messages = {
|
|
hu,
|
|
en,
|
|
}
|
|
|
|
/**
|
|
* Determine the initial locale:
|
|
* 1. If a saved locale exists in localStorage, use it.
|
|
* 2. Otherwise, detect the browser language (navigator.language).
|
|
* If it starts with 'hu', use 'hu'. For everything else, use 'en'.
|
|
*/
|
|
function detectLocale(): string {
|
|
const saved = localStorage.getItem('user-locale')
|
|
if (saved) return saved
|
|
|
|
if (typeof navigator !== 'undefined' && navigator.language) {
|
|
const browserLang = navigator.language.toLowerCase()
|
|
if (browserLang === 'hu' || browserLang.startsWith('hu-')) {
|
|
return 'hu'
|
|
}
|
|
}
|
|
|
|
return 'en'
|
|
}
|
|
|
|
const initialLocale = detectLocale()
|
|
|
|
const i18n = createI18n({
|
|
legacy: false,
|
|
locale: initialLocale,
|
|
fallbackLocale: 'en',
|
|
messages,
|
|
})
|
|
|
|
const app = createApp(App)
|
|
|
|
app.use(createPinia())
|
|
app.use(router)
|
|
app.use(i18n)
|
|
|
|
app.mount('#app')
|