All files / repo/src main.ts

0% Statements 0/34
0% Branches 0/1
0% Functions 0/1
0% Lines 0/34

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43                                                                                     
import { createPinia } from 'pinia';
import { createApp } from 'vue';
import App from './App.vue';
import './assests/scss/main.scss';
import { availableLocales, i18n } from './i18n';
import { OhVueIcon } from './icons';
 
const app = createApp(App);
const pinia = createPinia();
 
app.use(i18n);
app.use(pinia);
app.component('VIcon', OhVueIcon);
 
async function loadLocale(locale: string) {
  if (!availableLocales.includes(locale)) return;
  try {
    const messages = await fetch(`/i18n/${locale}.json`).then((res) => res.json());
    i18n.global.setLocaleMessage(locale, messages);
    i18n.global.locale.value = locale;
  } catch (err) {
    console.warn(`Failed to load locale: ${locale}`, err);
  }
}
 
let initialLocale = localStorage.getItem('user-locale');
 
if (!initialLocale) {
  const browserLang = navigator.language.split('-')[0];
  if (availableLocales.includes(browserLang)) {
    initialLocale = browserLang;
  } else {
    initialLocale = 'en';
  }
  localStorage.setItem('user-locale', initialLocale);
}
 
loadLocale(initialLocale).then(() => {
  app.mount('#app');
});
 
export { loadLocale };