Skip to content

Commit 6a4a702

Browse files
committed
update docs
1 parent a6ff9af commit 6a4a702

File tree

1 file changed

+61
-30
lines changed

1 file changed

+61
-30
lines changed

README.md

+61-30
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@
1111

1212
**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!
1313

14+
1415
## Status: Beta ![Test](https://github.com/intlify/vue-i18n-loader/workflows/Test/badge.svg)
1516

1617
<br/>
1718

19+
1820
## :star: Features
1921
- i18n resource pre-compilation
20-
- `i18n` custom block
22+
- i18n custom block
2123
- i18n resource definition
2224
- i18n resource importing
2325
- Locale of i18n resource definition
@@ -39,6 +41,7 @@ $ npm i --save-dev @intlify/vue-i18n-loader@next
3941
$ yarn add -D @intlify/vue-i18n-loader@next
4042
```
4143

44+
4245
## :rocket: i18n resource pre-compilation
4346

4447
### Why do we need to require the configuration?
@@ -51,7 +54,7 @@ If you are using the runtime version, you will need to compile before importing
5154

5255
You can pre-commpile by configuring vue-i18n-loader as the webpack loader.
5356

54-
### Webpack configration
57+
### webpack configration
5558

5659
As an example, if your project has the locale messagess in `src/locales`, your webpack config will look like this:
5760

@@ -114,9 +117,9 @@ module.exports = {
114117
The above uses webpack's `Rule.include` to specify the i18n resources to be precompiled. You can also use [`Rule.exclude`](https://webpack.js.org/configuration/module/#ruleexclude) to set the target.
115118

116119

117-
## :rocket: `i18n` custom block
120+
## :rocket: i18n custom block
118121

119-
The below example that`App.vue` have `i18n` custom block:
122+
The below example that `App.vue` have i18n custom block:
120123

121124
### i18n resource definition
122125

@@ -160,7 +163,7 @@ export default {
160163
</i18n>
161164
```
162165

163-
The locale messages defined at `i18n` custom blocks are **json format default**.
166+
The locale messages defined at i18n custom blocks are **json format default**.
164167

165168
### i18n resource importing
166169

@@ -274,7 +277,7 @@ app.use(i18n)
274277
app.mount('#app')
275278
```
276279

277-
### Webpack Config
280+
### webpack Config
278281

279282
`vue-loader` (`next` version):
280283

@@ -294,35 +297,63 @@ module.exports = {
294297
}
295298
```
296299

297-
## :rocket: loader options
298300

299-
### forceStringify
301+
## :wrench: Options
300302

301-
Whether pre-compile number and boolean values as message functions that return the string value, default `false`
303+
### `forceStringify`
302304

303-
```javascript
304-
module.exports = {
305-
module: {
306-
rules: [
307-
// ...
308-
{
309-
test: /\.(json5?|ya?ml)$/,
310-
type: 'javascript/auto',
311-
include: [path.resolve(__dirname, './src/locales')],
312-
use: [
313-
{
314-
loader: '@intlify/vue-i18n-loader',
315-
options: {
316-
forceStringify: true
305+
- **Type:** `boolean`
306+
- **Default:** `false`
307+
308+
Whether pre-compile number and boolean values as message functions that return the string value.
309+
310+
for example, the following json resources:
311+
312+
```json
313+
{
314+
"trueValue": true,
315+
"falseValue": false,
316+
"nullValue": null,
317+
"numberValue": 1
318+
}
319+
```
320+
321+
after pre-compiled (development):
322+
323+
```js
324+
export default {
325+
"trueValue": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize(["true"])};fn.source="true";return fn;})(),
326+
"falseValue": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize(["false"])};fn.source="false";return fn;})(),
327+
"nullValue": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize(["null"])};fn.source="null";return fn;})(),
328+
"numberValue": (()=>{const fn=(ctx) => {const { normalize: _normalize } = ctx;return _normalize(["1"])};fn.source="1";return fn;})()
329+
}
330+
```
331+
332+
webpack configration:
333+
334+
```javascript
335+
module.exports = {
336+
module: {
337+
rules: [
338+
// ...
339+
{
340+
test: /\.(json5?|ya?ml)$/,
341+
type: 'javascript/auto',
342+
include: [path.resolve(__dirname, './src/locales')],
343+
use: [
344+
{
345+
loader: '@intlify/vue-i18n-loader',
346+
options: {
347+
forceStringify: true
348+
}
317349
}
318-
}
319-
]
320-
},
321-
// ...
322-
]
350+
]
351+
},
352+
// ...
353+
]
354+
}
323355
}
324-
}
325-
```
356+
```
326357

327358
## :scroll: Changelog
328359
Details changes for each release are documented in the [CHANGELOG.md](https://github.com/intlify/vue-i18n-loader/blob/master/CHANGELOG.md).

0 commit comments

Comments
 (0)