You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jul 4, 2021. It is now read-only.
feat: add default lang and global scope plugin options for SFC i18n custom block (#109)
* feat: add `defaultSFCLang` and `globalSFCScope` configuration options
* chore: exclude intellij/webstorm stuff from `.gitignore`
* chore: add logic to use new configuration options only on SFC custom blocks
* chore: remove extra comma
* chore: add `defaultSFCLang` and `globalSFCScope` options on `test/utils.ts` on build function
* test: add `defaultSFCLang` and `globalSFCScope` tests on custom blocks
test: add `default-lang.vue` for `defaultSFCLang` and `globalSFCScope` tests
* test: add `defaultSFCLang` and `globalSFCScope` snapshots tests
* test: add `globalSFCScope and import` test
* test: add `globalSFCScope and import` snapshot test
* docs: correct some small errata and wording
docs: add docs for `defaultSFCLang` and `globalSFCScope`
* docs: add hint for `defaultSFCLang` and warning for `globalSFCScope`
Copy file name to clipboardExpand all lines: README.md
+87-4Lines changed: 87 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -90,7 +90,7 @@ Also, if you do a production build with vite, Vue I18n will automatically bundle
90
90
91
91
### i18n resources pre-compilation
92
92
93
-
Since vue-i18n@v9.0, The locale messages are handled with message compiler, which converts them to javascript functions after compiling. After compiling, message compiler converts them into javascript functions, which can improve the performance of the application.
93
+
Since vue-i18n@v9.0, the locale messages are handled with message compiler, which converts them to javascript functions after compiling. After compiling, message compiler converts them into javascript functions, which can improve the performance of the application.
94
94
95
95
However, with the message compiler, the javascript function conversion will not work in some environments (e.g. CSP). For this reason, vue-i18n@v9.0 and later offer a full version that includes compiler and runtime, and a runtime only version.
96
96
@@ -122,7 +122,7 @@ export default defineConfig({
122
122
123
123
### i18n custom block
124
124
125
-
the below example that `examples/composition/App.vue` have i18n custom block:
125
+
The below example that `examples/composition/App.vue` have `i18n` custom block:
126
126
127
127
```vue
128
128
<template>
@@ -171,9 +171,10 @@ You can be used by specifying the following format in the `lang` attribute:
171
171
172
172
- json (default)
173
173
- yaml
174
+
- yml
174
175
- json5
175
176
176
-
example `yaml`foramt:
177
+
example `yaml`format:
177
178
178
179
```vue
179
180
<i18n lang="yaml">
@@ -322,7 +323,7 @@ About details, See the below section
322
323
323
324
Whether pre-compile number and boolean values as message functions that return the string value.
324
325
325
-
for example, the following json resources:
326
+
For example, the following json resources:
326
327
327
328
```json
328
329
{
@@ -372,6 +373,88 @@ About details, See the below section
372
373
}
373
374
```
374
375
376
+
### `defaultSFCLang`
377
+
378
+
-**Type:**`string`
379
+
-**Default:**`undefined`
380
+
381
+
Specify the content for all your inlined `i18n` custom blocks on your `SFC`.
382
+
383
+
`defaultSFCLang` must have one of the following values:
384
+
385
+
```
386
+
- json
387
+
- json5
388
+
- yaml
389
+
- yml
390
+
```
391
+
392
+
On inlined `i18n` custom blocks that have specified the `lang` attribute, the `defaultSFCLang` is not applied.
393
+
394
+
For example, with `defaultSFCLang: "yaml"` or `defaultSFCLang: "yml"`, this custom block:
395
+
```html
396
+
<i18nlang="yaml">
397
+
en:
398
+
hello: Hello
399
+
es:
400
+
hello: Hola
401
+
</i18n>
402
+
```
403
+
404
+
and this another one, are equivalent:
405
+
```html
406
+
<i18n>
407
+
en:
408
+
hello: Hello
409
+
es:
410
+
hello: Hola
411
+
</i18n>
412
+
```
413
+
414
+
### `globalSFCScope`
415
+
416
+
-**Type:**`boolean`
417
+
-**Default:**`undefined`
418
+
419
+
Whether to include all `i18n` custom blocks on your `SFC` on `global` scope.
420
+
421
+
If `true`, it will be applied to all inlined `i18n` or `imported` custom blocks.
422
+
423
+
**Warning**: beware enabling `globalSFCScope: true`, all `i18n` custom blocks in all your `SFC` will be on `global` scope.
424
+
425
+
For example, with `globalSFCScope: true`, this custom block:
426
+
427
+
```html
428
+
<i18nlang="yaml"global>
429
+
en:
430
+
hello: Hello
431
+
es:
432
+
hello: Hola
433
+
</i18n>
434
+
```
435
+
436
+
and this another one, are equivalent:
437
+
438
+
```html
439
+
<i18nlang="yaml">
440
+
en:
441
+
hello: Hello
442
+
es:
443
+
hello: Hola
444
+
</i18n>
445
+
```
446
+
447
+
You can also use `defaultSFCLang: "yaml"`, following with previous example, this another is also equivalent to previous ones:
448
+
449
+
```html
450
+
<i18n>
451
+
en:
452
+
hello: Hello
453
+
es:
454
+
hello: Hola
455
+
</i18n>
456
+
```
457
+
375
458
## :scroll: Changelog
376
459
377
460
Details changes for each release are documented in the [CHANGELOG.md](https://github.com/intlify/vite-plugin-vue-i18n/blob/master/CHANGELOG.md).
0 commit comments