This repository was archived by the owner on Jul 4, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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`
- Loading branch information
Showing
9 changed files
with
191 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,6 @@ lib | |
*.swp | ||
*~ | ||
examples/**/dist | ||
.env | ||
.env | ||
# intellij/webstorm stuff | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
|
||
### i18n resources pre-compilation | ||
|
||
Since [email protected], 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. | ||
Since [email protected], 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. | ||
|
||
However, with the message compiler, the javascript function conversion will not work in some environments (e.g. CSP). For this reason, [email protected] and later offer a full version that includes compiler and runtime, and a runtime only version. | ||
|
||
|
@@ -122,7 +122,7 @@ export default defineConfig({ | |
|
||
### i18n custom block | ||
|
||
the below example that `examples/composition/App.vue` have i18n custom block: | ||
The below example that `examples/composition/App.vue` have `i18n` custom block: | ||
|
||
```vue | ||
<template> | ||
|
@@ -171,9 +171,10 @@ You can be used by specifying the following format in the `lang` attribute: | |
|
||
- json (default) | ||
- yaml | ||
- yml | ||
- json5 | ||
|
||
example `yaml` foramt: | ||
example `yaml` format: | ||
|
||
```vue | ||
<i18n lang="yaml"> | ||
|
@@ -322,7 +323,7 @@ About details, See the below section | |
|
||
Whether pre-compile number and boolean values as message functions that return the string value. | ||
|
||
for example, the following json resources: | ||
For example, the following json resources: | ||
|
||
```json | ||
{ | ||
|
@@ -372,6 +373,88 @@ About details, See the below section | |
} | ||
``` | ||
|
||
### `defaultSFCLang` | ||
|
||
- **Type:** `string` | ||
- **Default:** `undefined` | ||
|
||
Specify the content for all your inlined `i18n` custom blocks on your `SFC`. | ||
|
||
`defaultSFCLang` must have one of the following values: | ||
|
||
``` | ||
- json | ||
- json5 | ||
- yaml | ||
- yml | ||
``` | ||
|
||
On inlined `i18n` custom blocks that have specified the `lang` attribute, the `defaultSFCLang` is not applied. | ||
|
||
For example, with `defaultSFCLang: "yaml"` or `defaultSFCLang: "yml"`, this custom block: | ||
```html | ||
<i18n lang="yaml"> | ||
en: | ||
hello: Hello | ||
es: | ||
hello: Hola | ||
</i18n> | ||
``` | ||
|
||
and this another one, are equivalent: | ||
```html | ||
<i18n> | ||
en: | ||
hello: Hello | ||
es: | ||
hello: Hola | ||
</i18n> | ||
``` | ||
|
||
### `globalSFCScope` | ||
|
||
- **Type:** `boolean` | ||
- **Default:** `undefined` | ||
|
||
Whether to include all `i18n` custom blocks on your `SFC` on `global` scope. | ||
|
||
If `true`, it will be applied to all inlined `i18n` or `imported` custom blocks. | ||
|
||
**Warning**: beware enabling `globalSFCScope: true`, all `i18n` custom blocks in all your `SFC` will be on `global` scope. | ||
|
||
For example, with `globalSFCScope: true`, this custom block: | ||
|
||
```html | ||
<i18n lang="yaml" global> | ||
en: | ||
hello: Hello | ||
es: | ||
hello: Hola | ||
</i18n> | ||
``` | ||
|
||
and this another one, are equivalent: | ||
|
||
```html | ||
<i18n lang="yaml"> | ||
en: | ||
hello: Hello | ||
es: | ||
hello: Hola | ||
</i18n> | ||
``` | ||
|
||
You can also use `defaultSFCLang: "yaml"`, following with previous example, this another is also equivalent to previous ones: | ||
|
||
```html | ||
<i18n> | ||
en: | ||
hello: Hello | ||
es: | ||
hello: Hola | ||
</i18n> | ||
``` | ||
|
||
## :scroll: Changelog | ||
|
||
Details changes for each release are documented in the [CHANGELOG.md](https://github.com/intlify/vite-plugin-vue-i18n/blob/master/CHANGELOG.md). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<i18n> | ||
en: | ||
hello: hello from defaults! | ||
</i18n> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<i18n src="./message.json"> | ||
</i18n> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters