2023-02-19 17:13:33 +01:00
|
|
|
import { createApp } from 'vue';
|
2023-06-16 18:18:16 +02:00
|
|
|
import { createI18n } from 'vue-i18n';
|
|
|
|
|
|
2023-02-19 17:13:33 +01:00
|
|
|
import './style.css';
|
|
|
|
|
|
2023-07-14 14:48:43 +02:00
|
|
|
import '@fontsource/noto-sans';
|
2023-05-23 11:08:06 +02:00
|
|
|
|
2023-02-19 17:13:33 +01:00
|
|
|
import { createRouter, createWebHashHistory } from 'vue-router';
|
|
|
|
|
|
2024-08-23 18:12:17 +02:00
|
|
|
import { fetcher } from 'pankow';
|
|
|
|
|
|
2023-07-12 14:22:58 +02:00
|
|
|
import FileManager from './FileManager.vue';
|
2023-02-22 15:59:23 +01:00
|
|
|
import Home from './views/Home.vue';
|
2023-02-26 23:34:31 +01:00
|
|
|
import Viewer from './views/Viewer.vue';
|
2023-02-19 17:13:33 +01:00
|
|
|
|
|
|
|
|
const routes = [
|
2023-02-28 17:11:54 +01:00
|
|
|
{ path: '/', redirect: '/home' },
|
2023-04-11 16:29:58 +02:00
|
|
|
{ path: '/home/:type?/:resourceId?/:cwd*', component: Home },
|
2023-04-16 18:13:22 +02:00
|
|
|
{ path: '/viewer/:type/:resourceId/:filePath*', component: Viewer }
|
2023-02-19 17:13:33 +01:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const router = createRouter({
|
|
|
|
|
// 4. Provide the history implementation to use. We are using the hash history for simplicity here.
|
|
|
|
|
history: createWebHashHistory(),
|
2023-02-26 15:00:16 +01:00
|
|
|
routes,
|
2023-02-19 17:13:33 +01:00
|
|
|
});
|
|
|
|
|
|
2023-06-16 18:18:16 +02:00
|
|
|
const translations = {};
|
|
|
|
|
const i18n = createI18n({
|
2024-07-22 16:20:15 +02:00
|
|
|
locale: 'en', // set locale
|
|
|
|
|
fallbackLocale: 'en', // set fallback locale
|
|
|
|
|
messages: translations,
|
|
|
|
|
// will replace our double {{}} to vue-i18n single brackets
|
|
|
|
|
messageResolver: (keys, key) => {
|
|
|
|
|
let message = key.split('.').reduce((o, k) => o && o[k] || null, keys);
|
|
|
|
|
|
|
|
|
|
// fallback tr key
|
|
|
|
|
if (message === null) message = key;
|
|
|
|
|
|
|
|
|
|
return message.replaceAll('{{', '{').replaceAll('}}', '}');
|
|
|
|
|
}
|
2023-06-16 18:18:16 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// https://vue-i18n.intlify.dev/guide/advanced/lazy.html
|
|
|
|
|
(async function loadLanguages() {
|
|
|
|
|
const API_ORIGIN = import.meta.env.VITE_API_ORIGIN ? 'https://' + import.meta.env.VITE_API_ORIGIN : '';
|
|
|
|
|
|
|
|
|
|
async function loadLanguage(lang) {
|
|
|
|
|
try {
|
2024-08-23 18:12:17 +02:00
|
|
|
const result = await fetcher.get(`${API_ORIGIN}/translation/${lang}.json`);
|
|
|
|
|
translations[lang] = result.body;
|
2023-06-16 18:18:16 +02:00
|
|
|
} catch (e) {
|
|
|
|
|
console.error(`Failed to load language file for ${lang}`, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await loadLanguage('en');
|
|
|
|
|
|
|
|
|
|
const locale = window.localStorage.NG_TRANSLATE_LANG_KEY;
|
|
|
|
|
if (locale && locale !== 'en') {
|
|
|
|
|
await loadLanguage(locale);
|
|
|
|
|
|
|
|
|
|
if (i18n.mode === 'legacy') {
|
|
|
|
|
i18n.global.locale = locale;
|
|
|
|
|
} else {
|
|
|
|
|
i18n.global.locale.value = locale;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-12 14:22:58 +02:00
|
|
|
const app = createApp(FileManager);
|
2023-02-19 17:13:33 +01:00
|
|
|
|
2023-06-26 16:35:07 +02:00
|
|
|
app.use(i18n);
|
|
|
|
|
app.use(router);
|
2023-02-19 17:13:33 +01:00
|
|
|
|
2023-06-26 16:35:07 +02:00
|
|
|
app.mount('#app');
|
|
|
|
|
})();
|