Skip to content

Commit b241c76

Browse files
wip: customBlockHandler example
1 parent 1ce1e9b commit b241c76

File tree

1 file changed

+29
-20
lines changed

1 file changed

+29
-20
lines changed

test/index.html

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,55 @@
22
<html>
33
<body>
44
<script src="https://unpkg.com/vue@next/dist/vue.runtime.global.prod.js"></script>
5+
<script src="https://unpkg.com/vue-i18n@next"></script>
56
<script src="vue3-sfc-loader.js"></script>
67
<script>
78

89
/* <!-- */
910
const config = {
1011
files: {
1112
'/component.vue': `
12-
<script>
13-
const { test } = require('./foo/test.js')
14-
console.log( test() );
15-
</script>
16-
`,
17-
18-
'/foo/test.js': `
19-
exports.test = function() {
20-
21-
return require('../bar/test.js').test();
22-
}
23-
`,
24-
25-
'/bar/test.js': `
26-
exports.test = function() {
27-
28-
return 'test_ok';
13+
<template>
14+
{{ $t('hello') }}
15+
</template>
16+
<i18n>
17+
{
18+
"en": {
19+
"hello": "hello world!"
20+
},
21+
"ja": {
22+
"hello": "こんにちは、世界!"
23+
}
2924
}
30-
`
25+
</i18n>
26+
`
3127
}
3228
};
3329
/* --> */
3430

31+
const i18n = VueI18n.createI18n();
3532

3633
const options = {
3734
moduleCache: { vue: Vue },
3835
getFile: url => config.files[url],
3936
addStyle: () => {},
37+
customBlockHandler(block, filename, options) {
38+
39+
if ( block.type !== 'i18n' )
40+
return
41+
42+
const messages = JSON.parse(block.content);
43+
for ( let locale in messages )
44+
i18n.global.mergeLocaleMessage(locale, messages[locale]);
45+
}
4046
}
4147

42-
Vue.createApp(Vue.defineAsyncComponent(() => window['vue3-sfc-loader'].loadModule('/component.vue', options))).mount(document.body);
48+
const app = Vue.createApp(Vue.defineAsyncComponent(() => window['vue3-sfc-loader'].loadModule('/component.vue', options)));
49+
50+
app.use(i18n);
51+
52+
app.mount(document.body);
4353

4454
</script>
4555
</body>
4656
</html>
47-

0 commit comments

Comments
 (0)