@intlify/unplugin-vue-i18n 0.1.2 β†’ 0.2.0

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 CHANGED
@@ -1,4 +1,13 @@
1
1
 
2
+ ## @intlify/unplugin-vue-i18n@0.2.0 (2022-05-06)
3
+
4
+ #### :star: Features
5
+ * [#117](https://github.com/intlify/bundle-tools/pull/117) feat: support virtual resource importing ([@kazupon](https://github.com/kazupon))
6
+
7
+ #### Committers: 1
8
+ - kazuya kawaguchi ([@kazupon](https://github.com/kazupon))
9
+
10
+
2
11
  ## @intlify/unplugin-vue-i18n@0.1.2 (2022-05-06)
3
12
 
4
13
  #### :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 Vite, and will not be processed afterwards**, else the option doesn't match, the Vite side will handle.
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/messages.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ declare module '@intlify/unplugin-vue-i18n/messages' {
2
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
+ const messages: any
4
+ export default messages
5
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlify/unplugin-vue-i18n",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "unplugin for Vue I18n",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",
@@ -79,6 +79,9 @@
79
79
  "./types": {
80
80
  "types": "./types.d.ts"
81
81
  },
82
+ "./messages": {
83
+ "types": "./messages.d.ts"
84
+ },
82
85
  "./lib/*": "./lib/*",
83
86
  "./package.json": "./package.json"
84
87
  },