-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvueParser.js
More file actions
53 lines (42 loc) · 1.47 KB
/
vueParser.js
File metadata and controls
53 lines (42 loc) · 1.47 KB
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
44
45
46
47
48
49
50
51
52
53
// https://github.com/FranckFreiburger/vue3-sfc-loader
// https://github.com/FranckFreiburger/vue3-sfc-loader/blob/main/docs/examples.md#use-sfc-custom-blocks-for-i18n
import ca from './lang/ca.js';
import en from './lang/en.js';
import es from './lang/es.js';
const i18n = VueI18n.createI18n();
const options = {
moduleCache: { vue: Vue },
async getFile(url) {
const res = await fetch(url);
if (!res.ok)
throw Object.assign(new Error(res.statusText + ' ' + url), { res });
return {
getContentData: asBinary => asBinary ? res.arrayBuffer() : res.text(),
}
},
addStyle: (textContent) => {
const style = Object.assign(document.createElement('style'), { textContent });
const ref = document.head.getElementsByTagName('style')[0] || null;
document.head.insertBefore(style, ref);
},
customBlockHandler(block, filename, options) {
if (block.type !== 'i18n')
return
const messages = JSON.parse(block.content);
for (let locale in messages)
i18n.global.mergeLocaleMessage(locale, messages[locale]);
}
}
const { loadModule } = window['vue3-sfc-loader'];
const app = Vue.createApp({
components: {
'app-manager': Vue.defineAsyncComponent(() => loadModule('./AppManager.vue', options)),
},
template: '<app-manager></app-manager>'
});
// Translations
i18n.global.mergeLocaleMessage('ca', ca);
i18n.global.mergeLocaleMessage('en', en);
i18n.global.mergeLocaleMessage('es', es);
app.use(i18n);
app.mount(document.body);