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.
Copy file name to clipboardExpand all lines: README.md
+50Lines changed: 50 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -125,6 +125,56 @@ ja:
125
125
</i18n>
126
126
```
127
127
128
+
### Static bundle importing
129
+
130
+
vite-plugin-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.
131
+
132
+
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.
133
+
134
+
```js
135
+
import { createApp } from'vue'
136
+
import { createI18n } from'vue-i18n'
137
+
/*
138
+
* The i18n resources in the path specified in the plugin `include` option can be read
139
+
* as vue-i18n optimized locale messages using the import syntax
140
+
*/
141
+
importenfrom'./src/locales/en.json'
142
+
importjafrom'./src/locales/ja.yaml'
143
+
importfrfrom'./src/locales/fr.json5'
144
+
145
+
consti18n=createI18n({
146
+
locale:'en',
147
+
messages: {
148
+
en,
149
+
ja,
150
+
fr
151
+
}
152
+
})
153
+
154
+
constapp=createApp()
155
+
app.use(i18n).mount('#app)
156
+
```
157
+
158
+
vite-plugin-vue-i18n can use the vite (rollup) mechanism to import all locales at once, using the special identifier `@intlify/vite-plugin-vue-i18n/messages`, as the bellow:
159
+
160
+
```js
161
+
import { createApp } from 'vue'
162
+
import { createI18n } from 'vue-i18n'
163
+
/*
164
+
* All i18n resources specified in the plugin `include` option can be loaded
165
+
* at once using the import syntax
166
+
*/
167
+
import messages from '@intlify/vite-plugin-vue-i18n/messages'
168
+
169
+
const i18n = createI18n({
170
+
locale: 'en',
171
+
messages
172
+
})
173
+
174
+
const app = createApp()
175
+
app.use(i18n).mount('#app)
176
+
```
177
+
128
178
### Bundle optimizations
129
179
130
180
vite-plugin-vue-i18n allows you to support bundle size optimization provided by vue-i18n.
0 commit comments