@intlify/unplugin-vue-i18n 0.1.1 β 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +27 -0
- package/README.md +145 -5
- package/index.d.ts +1 -0
- package/lib/index.cjs +9 -1
- package/lib/index.mjs +9 -1
- package/messages.d.ts +5 -0
- package/package.json +11 -7
- package/types.d.ts +1 -0
- package/vite.d.ts +1 -0
- package/webpack.d.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,31 @@
|
|
|
1
1
|
|
|
2
|
+
## @intlify/unplugin-vue-i18n@0.2.1 (2022-05-07)
|
|
3
|
+
|
|
4
|
+
#### :bug: Bug Fixes
|
|
5
|
+
* [#118](https://github.com/intlify/bundle-tools/pull/118) fix(unplugin-vue-i18n): code transforming strictly ([@kazupon](https://github.com/kazupon))
|
|
6
|
+
|
|
7
|
+
#### Committers: 1
|
|
8
|
+
- kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
## @intlify/unplugin-vue-i18n@0.2.0 (2022-05-06)
|
|
12
|
+
|
|
13
|
+
#### :star: Features
|
|
14
|
+
* [#117](https://github.com/intlify/bundle-tools/pull/117) feat: support virtual resource importing ([@kazupon](https://github.com/kazupon))
|
|
15
|
+
|
|
16
|
+
#### Committers: 1
|
|
17
|
+
- kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
## @intlify/unplugin-vue-i18n@0.1.2 (2022-05-06)
|
|
21
|
+
|
|
22
|
+
#### :bug: Bug Fixes
|
|
23
|
+
* [#115](https://github.com/intlify/bundle-tools/pull/115) fix(unplugin-vue-i18n): export d.ts files ([@kazupon](https://github.com/kazupon))
|
|
24
|
+
|
|
25
|
+
#### Committers: 1
|
|
26
|
+
- kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
|
|
27
|
+
|
|
28
|
+
|
|
2
29
|
## @intlify/unplugin-vue-i18n@0.1.1 (2022-05-06)
|
|
3
30
|
|
|
4
31
|
#### :bug: Bug Fixes
|
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ npm i @intlify/unplugin-vue-i18n
|
|
|
28
28
|
|
|
29
29
|
```ts
|
|
30
30
|
// vite.config.ts
|
|
31
|
-
import vueI18n from 'unplugin-vue-i18n/vite'
|
|
31
|
+
import vueI18n from '@intlify/unplugin-vue-i18n/vite'
|
|
32
32
|
|
|
33
33
|
export default defineConfig({
|
|
34
34
|
plugins: [
|
|
@@ -43,7 +43,7 @@ export default defineConfig({
|
|
|
43
43
|
<summary>Webpack</summary><br>
|
|
44
44
|
|
|
45
45
|
```ts
|
|
46
|
-
const VueI18nPlugin = require('unplugin-vue-i18n/webpack')
|
|
46
|
+
const VueI18nPlugin = require('@intlify/unplugin-vue-i18n/webpack')
|
|
47
47
|
|
|
48
48
|
// webpack.config.js
|
|
49
49
|
module.exports = {
|
|
@@ -56,6 +56,148 @@ module.exports = {
|
|
|
56
56
|
|
|
57
57
|
<br></details>
|
|
58
58
|
|
|
59
|
+
## π Usage
|
|
60
|
+
|
|
61
|
+
### i18n resources pre-compilation
|
|
62
|
+
|
|
63
|
+
Since `vue-i18n@v9.x`, 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.
|
|
64
|
+
|
|
65
|
+
However, with the message compiler, the javascript function conversion will not work in some environments (e.g. CSP). For this reason, `vue-i18n@v9.x` and later offer a full version that includes compiler and runtime, and a runtime only version.
|
|
66
|
+
|
|
67
|
+
If you are using the runtime version, you will need to compile before importing locale messages by managing them in a file such as `.json`.
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
### i18n custom block
|
|
71
|
+
|
|
72
|
+
The below example that `examples/vite/src/App.vue` have `i18n` custom block:
|
|
73
|
+
|
|
74
|
+
```vue
|
|
75
|
+
<template>
|
|
76
|
+
<form>
|
|
77
|
+
<label>{{ t('language') }}</label>
|
|
78
|
+
<select v-model="locale">
|
|
79
|
+
<option value="en">en</option>
|
|
80
|
+
<option value="ja">ja</option>
|
|
81
|
+
</select>
|
|
82
|
+
</form>
|
|
83
|
+
<p>{{ t('hello') }}</p>
|
|
84
|
+
<Banana />
|
|
85
|
+
</template>
|
|
86
|
+
|
|
87
|
+
<script>
|
|
88
|
+
import { useI18n } from 'vue-i18n'
|
|
89
|
+
import Banana from './Banana.vue'
|
|
90
|
+
|
|
91
|
+
export default {
|
|
92
|
+
name: 'App',
|
|
93
|
+
components: {
|
|
94
|
+
Banana
|
|
95
|
+
},
|
|
96
|
+
setup() {
|
|
97
|
+
const { t, locale } = useI18n({
|
|
98
|
+
inheritLocale: true,
|
|
99
|
+
useScope: 'local'
|
|
100
|
+
})
|
|
101
|
+
return { t, locale }
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
</script>
|
|
105
|
+
|
|
106
|
+
<i18n>
|
|
107
|
+
{
|
|
108
|
+
"en": {
|
|
109
|
+
"language": "Language",
|
|
110
|
+
"hello": "hello, world!"
|
|
111
|
+
},
|
|
112
|
+
"ja": {
|
|
113
|
+
"language": "θ¨θͺ",
|
|
114
|
+
"hello": "γγγ«γ‘γ―γδΈηοΌ"
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
</i18n>
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Locale Messages formatting
|
|
121
|
+
|
|
122
|
+
You can be used by specifying the following format in the `lang` attribute:
|
|
123
|
+
|
|
124
|
+
- json (default)
|
|
125
|
+
- yaml
|
|
126
|
+
- yml
|
|
127
|
+
- json5
|
|
128
|
+
|
|
129
|
+
example `yaml` format:
|
|
130
|
+
|
|
131
|
+
```vue
|
|
132
|
+
<i18n lang="yaml">
|
|
133
|
+
en:
|
|
134
|
+
hello: 'Hello World!'
|
|
135
|
+
ja:
|
|
136
|
+
hello: 'γγγ«γ‘γ―γδΈηοΌ'
|
|
137
|
+
</i18n>
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### Static bundle importing
|
|
141
|
+
|
|
142
|
+
unplugin-vue-i18n allows you to statically bundle i18n resources such as `json` or `yaml` specified by the [`include` option](#include) of the plugin described below as locale messages with the `import` syntax.
|
|
143
|
+
|
|
144
|
+
In this case, only one i18n resource can be statically bundled at a time with `import` syntax, so the these code will be redundant for multiple locales.
|
|
145
|
+
|
|
146
|
+
```js
|
|
147
|
+
import { createApp } from 'vue'
|
|
148
|
+
import { createI18n } from 'vue-i18n'
|
|
149
|
+
/*
|
|
150
|
+
* The i18n resources in the path specified in the plugin `include` option can be read
|
|
151
|
+
* as vue-i18n optimized locale messages using the import syntax
|
|
152
|
+
*/
|
|
153
|
+
import en from './src/locales/en.json'
|
|
154
|
+
import ja from './src/locales/ja.yaml'
|
|
155
|
+
import fr from './src/locales/fr.json5'
|
|
156
|
+
|
|
157
|
+
const i18n = createI18n({
|
|
158
|
+
locale: 'en',
|
|
159
|
+
messages: {
|
|
160
|
+
en,
|
|
161
|
+
ja,
|
|
162
|
+
fr
|
|
163
|
+
}
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
const app = createApp()
|
|
167
|
+
app.use(i18n).mount('#app')
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
unplugin-vue-i18n can use the bundler virtual mechanism to import all locales at once, using the special identifier `@intlify/unplugin-vue-i18n/messages`, as the bellow:
|
|
171
|
+
|
|
172
|
+
```js
|
|
173
|
+
import { createApp } from 'vue'
|
|
174
|
+
import { createI18n } from 'vue-i18n'
|
|
175
|
+
/*
|
|
176
|
+
* All i18n resources specified in the plugin `include` option can be loaded
|
|
177
|
+
* at once using the import syntax
|
|
178
|
+
*/
|
|
179
|
+
import messages from '@intlify/unplugin-vue-i18n/messages'
|
|
180
|
+
|
|
181
|
+
const i18n = createI18n({
|
|
182
|
+
locale: 'en',
|
|
183
|
+
messages
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
const app = createApp()
|
|
187
|
+
app.use(i18n).mount('#app')
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
### Types
|
|
191
|
+
|
|
192
|
+
If you want type definition of `@intlify/unplugin-vue-i18n/messages`, add `unplugin-vue-i18n/messages` to `compilerOptions.types` of your tsconfig:
|
|
193
|
+
|
|
194
|
+
```json
|
|
195
|
+
{
|
|
196
|
+
"compilerOptions": {
|
|
197
|
+
"types": ["@intlify/unplugin-vue-i18n/messages"]
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
```
|
|
59
201
|
|
|
60
202
|
## π§ Options
|
|
61
203
|
|
|
@@ -73,7 +215,7 @@ module.exports = {
|
|
|
73
215
|
- yml
|
|
74
216
|
```
|
|
75
217
|
|
|
76
|
-
Note `json` resources matches this option, it will be handled **before the internal json plugin of
|
|
218
|
+
Note `json` resources matches this option, it will be handled **before the internal json plugin of bundler, and will not be processed afterwards**, else the option doesn't match, the bundler side will handle.
|
|
77
219
|
|
|
78
220
|
### `forceStringify`
|
|
79
221
|
|
|
@@ -206,9 +348,7 @@ module.exports = {
|
|
|
206
348
|
|
|
207
349
|
|
|
208
350
|
## β
TODO
|
|
209
|
-
- [ ] Virtual resource importing
|
|
210
351
|
- [ ] Bundling optimizations
|
|
211
|
-
- [ ] i18n custom block birdge mode (for vite)
|
|
212
352
|
- [ ] Support nuxt
|
|
213
353
|
|
|
214
354
|
## π Changelog
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default, unplugin, PluginOptions, SFCLangFormat } from './lib/index'
|
package/lib/index.cjs
CHANGED
|
@@ -121,6 +121,15 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
121
121
|
return {
|
|
122
122
|
name: "unplugin-vue-i18n",
|
|
123
123
|
enforce: meta.framework === "vite" ? "pre" : "post",
|
|
124
|
+
transformInclude(id) {
|
|
125
|
+
debug("transformInclude", id);
|
|
126
|
+
if (meta.framework === "vite") {
|
|
127
|
+
return true;
|
|
128
|
+
} else {
|
|
129
|
+
const { filename } = parseVueRequest(id);
|
|
130
|
+
return filename.endsWith("vue") || filename.endsWith(INTLIFY_BUNDLE_IMPORT_ID) || filename.endsWith(INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID) ? true : /\.(json5?|ya?ml)$/.test(id) && filter(id);
|
|
131
|
+
}
|
|
132
|
+
},
|
|
124
133
|
vite: {
|
|
125
134
|
configResolved(config) {
|
|
126
135
|
isProduction = config.isProduction;
|
|
@@ -189,7 +198,6 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
189
198
|
async transform(code, id) {
|
|
190
199
|
const { filename, query } = parseVueRequest(id);
|
|
191
200
|
debug("transform", id, JSON.stringify(query), filename);
|
|
192
|
-
debug("transform (code)", code);
|
|
193
201
|
let langInfo = defaultSFCLang;
|
|
194
202
|
let inSourceMap;
|
|
195
203
|
if (!query.vue) {
|
package/lib/index.mjs
CHANGED
|
@@ -110,6 +110,15 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
110
110
|
return {
|
|
111
111
|
name: "unplugin-vue-i18n",
|
|
112
112
|
enforce: meta.framework === "vite" ? "pre" : "post",
|
|
113
|
+
transformInclude(id) {
|
|
114
|
+
debug("transformInclude", id);
|
|
115
|
+
if (meta.framework === "vite") {
|
|
116
|
+
return true;
|
|
117
|
+
} else {
|
|
118
|
+
const { filename } = parseVueRequest(id);
|
|
119
|
+
return filename.endsWith("vue") || filename.endsWith(INTLIFY_BUNDLE_IMPORT_ID) || filename.endsWith(INTLIFY_BUNDLE_IMPORT_DEPRECTED_ID) ? true : /\.(json5?|ya?ml)$/.test(id) && filter(id);
|
|
120
|
+
}
|
|
121
|
+
},
|
|
113
122
|
vite: {
|
|
114
123
|
configResolved(config) {
|
|
115
124
|
isProduction = config.isProduction;
|
|
@@ -178,7 +187,6 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
178
187
|
async transform(code, id) {
|
|
179
188
|
const { filename, query } = parseVueRequest(id);
|
|
180
189
|
debug("transform", id, JSON.stringify(query), filename);
|
|
181
|
-
debug("transform (code)", code);
|
|
182
190
|
let langInfo = defaultSFCLang;
|
|
183
191
|
let inSourceMap;
|
|
184
192
|
if (!query.vue) {
|
package/messages.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@intlify/unplugin-vue-i18n",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "unplugin for Vue I18n",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "kazuya kawaguchi",
|
|
@@ -42,7 +42,8 @@
|
|
|
42
42
|
"node": ">= 12"
|
|
43
43
|
},
|
|
44
44
|
"files": [
|
|
45
|
-
"lib"
|
|
45
|
+
"lib",
|
|
46
|
+
"*.d.ts"
|
|
46
47
|
],
|
|
47
48
|
"homepage": "https://github.com/intlify/bundle-tools/blob/main/packages/unplugin-vue-i18n/README.md",
|
|
48
49
|
"keywords": [
|
|
@@ -58,25 +59,28 @@
|
|
|
58
59
|
"license": "MIT",
|
|
59
60
|
"main": "lib/index.cjs",
|
|
60
61
|
"module": "./lib/index.mjs",
|
|
61
|
-
"types": "
|
|
62
|
+
"types": "./index.d.ts",
|
|
62
63
|
"exports": {
|
|
63
64
|
".": {
|
|
64
65
|
"require": "./lib/index.cjs",
|
|
65
66
|
"import": "./lib/index.mjs",
|
|
66
|
-
"types": "./
|
|
67
|
+
"types": "./index.d.ts"
|
|
67
68
|
},
|
|
68
69
|
"./vite": {
|
|
69
70
|
"require": "./lib/vite.cjs",
|
|
70
71
|
"import": "./lib/vite.mjs",
|
|
71
|
-
"types": "./
|
|
72
|
+
"types": "./vite.d.ts"
|
|
72
73
|
},
|
|
73
74
|
"./webpack": {
|
|
74
75
|
"require": "./lib/webpack.cjs",
|
|
75
76
|
"import": "./lib/webpack.mjs",
|
|
76
|
-
"types": "./
|
|
77
|
+
"types": "./webpack.d.ts"
|
|
77
78
|
},
|
|
78
79
|
"./types": {
|
|
79
|
-
"types": "./
|
|
80
|
+
"types": "./types.d.ts"
|
|
81
|
+
},
|
|
82
|
+
"./messages": {
|
|
83
|
+
"types": "./messages.d.ts"
|
|
80
84
|
},
|
|
81
85
|
"./lib/*": "./lib/*",
|
|
82
86
|
"./package.json": "./package.json"
|
package/types.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PluginOptions, SFCLangFormat } from './lib/types'
|
package/vite.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './lib/vite'
|
package/webpack.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './lib/webpack'
|