Skip to content

Commit d9d9086

Browse files
committed
update docs
1 parent 7835805 commit d9d9086

File tree

1 file changed

+79
-51
lines changed

1 file changed

+79
-51
lines changed

README.md

Lines changed: 79 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,60 @@
1010

1111
<p align="center">vue-i18n loader for custom blocks</p>
1212

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+
1317
<br/>
1418

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+
1528
## :cd: Installation
1629

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+
```
1841

19-
## :rocket: Usage
42+
## :rocket: `i18n` custom block
2043

2144
the below example that`App.vue` have `i18n` custom block:
2245

23-
### Basic
46+
### i18n resource definition
2447

2548
```vue
2649
<template>
27-
<p>{{ $t('hello') }}</p>
50+
<p>{{ t('hello') }}</p>
2851
</template>
2952
3053
<script>
54+
import { useI18n } from 'vue-i18n'
55+
3156
export default {
3257
name: 'app',
33-
// ...
58+
setup() {
59+
// Somthing todo ...
60+
return {
61+
...,
62+
...useI18n({
63+
// ...
64+
})
65+
}
66+
}
3467
}
3568
</script>
3669
@@ -46,11 +79,11 @@ export default {
4679
</i18n>
4780
```
4881

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**.
5083

51-
### Source importing
84+
### i18n resource importing
5285

53-
you also can:
86+
you also can use `src` attribute:
5487

5588
```vue
5689
<i18n src="./myLang.json"></i18n>
@@ -68,9 +101,9 @@ you also can:
68101
}
69102
```
70103

71-
### Locale definition
104+
### Locale of i18n resource definition
72105

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:
74107

75108
```vue
76109
<i18n locale="en">
@@ -89,7 +122,7 @@ You can define locale messages for each locale with `locale` attr in single-file
89122
The above defines two locales, which are merged at target single-file components.
90123

91124

92-
### Locale Messages formatting
125+
### i18n resource formatting
93126

94127
Besides json format, You can be used by specifying the following format in the `lang` attribute:
95128

@@ -124,14 +157,13 @@ example json5 format:
124157
### JavaScript
125158

126159
```javascript
127-
import Vue from 'vue'
128-
import VueI18n from 'vue-i18n'
160+
import { createApp } from 'vue'
161+
import { createI18n } from 'vue-i18n'
129162
import App from './App.vue'
130163

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',
135167
messages: {
136168
en: {
137169
// ...
@@ -141,62 +173,58 @@ const i18n = new VueI18n({
141173
}
142174
}
143175
})
144-
new Vue({
145-
i18n,
146-
render: h => h(App)
147-
}).$mount('#app')
148-
```
149-
150-
### Webpack Config
151176

152-
`vue-loader` (v15 or later):
177+
const app = createApp(App)
153178

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')
166181
```
167182

168-
`vue-loader` (v15 or later):
183+
### Webpack Config
184+
185+
`vue-loader` (`next` version):
169186

170187
```javascript
171-
// for webpack.config.js (Without Vue CLI)
172188
module.exports = {
173189
module: {
174190
rules: [
191+
// ...
175192
{
176193
resourceQuery: /blockType=i18n/,
177194
type: 'javascript/auto',
178-
loader: '@intlify/vue-i18n-loader',
195+
loader: '@intlify/vue-i18n-loader'
179196
},
197+
// ...
180198
]
181199
}
182200
}
183201
```
184202

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:
186208

187209
```javascript
188-
// for webpack config file
189210
module.exports = {
190211
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+
]
200228
}
201229
}
202230
```

0 commit comments

Comments
 (0)