File tree Expand file tree Collapse file tree 1 file changed +29
-20
lines changed Expand file tree Collapse file tree 1 file changed +29
-20
lines changed Original file line number Diff line number Diff line change 2
2
< html >
3
3
< body >
4
4
< script src ="https://unpkg.com/vue@next/dist/vue.runtime.global.prod.js "> </ script >
5
+ < script src ="https://unpkg.com/vue-i18n@next "> </ script >
5
6
< script src ="vue3-sfc-loader.js "> </ script >
6
7
< script >
7
8
8
9
/* <!-- */
9
10
const config = {
10
11
files : {
11
12
'/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
+ }
29
24
}
30
- `
25
+ </i18n>
26
+ `
31
27
}
32
28
} ;
33
29
/* --> */
34
30
31
+ const i18n = VueI18n . createI18n ( ) ;
35
32
36
33
const options = {
37
34
moduleCache : { vue : Vue } ,
38
35
getFile : url => config . files [ url ] ,
39
36
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
+ }
40
46
}
41
47
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 ) ;
43
53
44
54
</ script >
45
55
</ body >
46
56
</ html >
47
-
You can’t perform that action at this time.
0 commit comments