10
10
11
11
<p align =" center " >vue-i18n loader for custom blocks</p >
12
12
13
+ ** NOTE:** :warning : This ` next ` branch is development branch for Vue 3! The stable version is now in [ ` master ` ] ( https://github.com/intlify/vue-i18n-loader/tree/master ) branch!
14
+
15
+ ## Status: Alpha ![ Test] ( https://github.com/intlify/vue-i18n-loader/workflows/Test/badge.svg )
16
+
13
17
<br />
14
18
19
+ ## :star : Features
20
+ - ` i18n ` custom block
21
+ - i18n resource definition
22
+ - i18n resource importing
23
+ - Locale of i18n resource definition
24
+ - i18n resource formatting
25
+ - i18n resource optimaization
26
+
27
+
15
28
## :cd : Installation
16
29
17
- $ npm i --save-dev @intlify/vue-i18n-loader
30
+ ### NPM
31
+
32
+ ``` sh
33
+ $ npm i --save-dev @intlify/vue-i18n-extensions@alpha
34
+ ```
35
+
36
+ ### YARN
37
+
38
+ ``` sh
39
+ $ yarn add -D @intlify/vue-i18n-extensions@alpha
40
+ ```
18
41
19
- ## :rocket : Usage
42
+ ## :rocket : ` i18n ` custom block
20
43
21
44
the below example that` App.vue ` have ` i18n ` custom block:
22
45
23
- ### Basic
46
+ ### i18n resource definition
24
47
25
48
``` vue
26
49
<template>
27
- <p>{{ $ t('hello') }}</p>
50
+ <p>{{ t('hello') }}</p>
28
51
</template>
29
52
30
53
<script>
54
+ import { useI18n } from 'vue-i18n'
55
+
31
56
export default {
32
57
name: 'app',
33
- // ...
58
+ setup() {
59
+ // Somthing todo ...
60
+ return {
61
+ ...,
62
+ ...useI18n({
63
+ // ...
64
+ })
65
+ }
66
+ }
34
67
}
35
68
</script>
36
69
@@ -46,11 +79,11 @@ export default {
46
79
</i18n>
47
80
```
48
81
49
- The locale messages defined at ` i18n ` custom blocks are ** json format default** .
82
+ The locale messages defined at ` i18n ` custom blocks are ** json format default** .
50
83
51
- ### Source importing
84
+ ### i18n resource importing
52
85
53
- you also can:
86
+ you also can use ` src ` attribute :
54
87
55
88
``` vue
56
89
<i18n src="./myLang.json"></i18n>
@@ -68,9 +101,9 @@ you also can:
68
101
}
69
102
```
70
103
71
- ### Locale definition
104
+ ### Locale of i18n resource definition
72
105
73
- You can define locale messages for each locale with ` locale ` attr in single-file components:
106
+ You can define locale messages for each locale with ` locale ` attribute in single-file components:
74
107
75
108
``` vue
76
109
<i18n locale="en">
@@ -89,7 +122,7 @@ You can define locale messages for each locale with `locale` attr in single-file
89
122
The above defines two locales, which are merged at target single-file components.
90
123
91
124
92
- ### Locale Messages formatting
125
+ ### i18n resource formatting
93
126
94
127
Besides json format, You can be used by specifying the following format in the ` lang ` attribute:
95
128
@@ -124,14 +157,13 @@ example json5 format:
124
157
### JavaScript
125
158
126
159
``` javascript
127
- import Vue from ' vue'
128
- import VueI18n from ' vue-i18n'
160
+ import { createApp } from ' vue'
161
+ import { createI18n } from ' vue-i18n'
129
162
import App from ' ./App.vue'
130
163
131
- Vue .use (VueI18n)
132
-
133
- const i18n = new VueI18n ({
134
- locale: ' en' ,
164
+ // setup i18n instance with globaly
165
+ const i18n = createI18n ({
166
+ locale: ' ja' ,
135
167
messages: {
136
168
en: {
137
169
// ...
@@ -141,62 +173,58 @@ const i18n = new VueI18n({
141
173
}
142
174
}
143
175
})
144
- new Vue ({
145
- i18n,
146
- render : h => h (App)
147
- }).$mount (' #app' )
148
- ```
149
-
150
- ### Webpack Config
151
176
152
- ` vue-loader ` (v15 or later):
177
+ const app = createApp (App)
153
178
154
- ``` javascript
155
- // for vue.config.js (Vue CLI)
156
- module .exports = {
157
- chainWebpack : config => {
158
- config .module
159
- .rule (' i18n' )
160
- .resourceQuery (/ blockType=i18n/ )
161
- .type (' javascript/auto' )
162
- .use (' i18n' )
163
- .loader (' @intlify/vue-i18n-loader' )
164
- }
165
- }
179
+ app .use (i18n)
180
+ app .mount (' #app' )
166
181
```
167
182
168
- ` vue-loader ` (v15 or later):
183
+ ### Webpack Config
184
+
185
+ ` vue-loader ` (` next ` version):
169
186
170
187
``` javascript
171
- // for webpack.config.js (Without Vue CLI)
172
188
module .exports = {
173
189
module: {
174
190
rules: [
191
+ // ...
175
192
{
176
193
resourceQuery: / blockType=i18n/ ,
177
194
type: ' javascript/auto' ,
178
- loader: ' @intlify/vue-i18n-loader' ,
195
+ loader: ' @intlify/vue-i18n-loader'
179
196
},
197
+ // ...
180
198
]
181
199
}
182
200
}
183
201
```
184
202
185
- ` vue-loader ` (~ v14.x):
203
+ ## :rocket : i18n resource optimazation
204
+
205
+ You can optimize your localization performance with pre-compiling the i18n resources.
206
+
207
+ You need to specify the ` preCompile: true ` option in your webpack config as below:
186
208
187
209
``` javascript
188
- // for webpack config file
189
210
module .exports = {
190
211
module: {
191
- rules: [{
192
- test: / \. vue$ / ,
193
- loader: ' vue' ,
194
- options: {
195
- loaders: {
196
- i18n: ' @intlify/vue-i18n-loader'
197
- }
198
- }
199
- }]
212
+ rules: [
213
+ // ...
214
+ {
215
+ resourceQuery: / blockType=i18n/ ,
216
+ type: ' javascript/auto' ,
217
+ use: [
218
+ {
219
+ loader: ' @intlify/vue-i18n-loader' ,
220
+ options: {
221
+ preCompile: true // you need to specify at here!
222
+ }
223
+ }
224
+ ]
225
+ },
226
+ // ...
227
+ ]
200
228
}
201
229
}
202
230
```
0 commit comments