Skip to content

Commit 5419a8f

Browse files
authored
fix(docs): add more unplugin-vue-i18n docs and tweak some sections (#1221)
1 parent 7b5ae5e commit 5419a8f

File tree

2 files changed

+103
-8
lines changed

2 files changed

+103
-8
lines changed

docs/guide/advanced/optimization.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ Also, the message compiler is not bundled, therefore **bundle size can be reduce
2323
We can configure these modules with module path using the module resolve alias feature (e.g. `resolve.alias` vite and webpack) of some bundler, but It takes time and effort.
2424
Intlify project provides plugins/loaders for some bundlers, for simplicity
2525

26-
### `@intlify/unplugin-vue-i18n`
26+
### unplugin-vue-i18n
2727

2828
[`unplugin`](https://github.com/unjs/unplugin) is an unified plugin system for bundle tool such as vite, webpack, rollup, esbuild and etc.
2929

30-
Intlify project is providing [`@intlify/unplugin-vue-i18n`](https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n) for vite and webpack.
30+
Intlify project is providing [`unplugin-vue-i18n`](https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n) for vite and webpack.
3131

3232
If you do the production build, Vue I18n will automatically bundle the runtime only module
3333

@@ -83,11 +83,11 @@ module.exports = {
8383
8484
About optoins and features, see the detail [page](https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n#intlifyunplugin-vue-i18n)
8585
86-
### `@intlify/vite-plugin-vue-i18n`
86+
### vite-plugin-vue-i18n
8787
8888
[`vite`](https://vitejs.dev/) is next generation frontend tooling.
8989
90-
Intlify project is providing [`@intlify/vite-plugin-vue-i18n`](https://github.com/intlify/bundle-tools/tree/main/packages/vite-plugin-vue-i18n)
90+
Intlify project is providing [`vite-plugin-vue-i18n`](https://github.com/intlify/bundle-tools/tree/main/packages/vite-plugin-vue-i18n)
9191
9292
If you do a production build, Vue I18n will automatically bundle the runtime only module
9393
@@ -127,11 +127,11 @@ export default defineConfig({
127127
128128
About optoins and features, see the detail [page](https://github.com/intlify/bundle-tools/tree/main/packages/vite-plugin-vue-i18n)
129129
130-
### `@intlify/vue-i18n-loader`
130+
### vue-i18n-loader
131131
132132
[webpack](https://webpack.js.org/) is a static module bundler for modern JavaScript applications.
133133
134-
Intlify project is providing [`@intlify/vue-i18n-loader`](https://github.com/intlify/bundle-tools/tree/main/packages/vue-i18n-loader)
134+
Intlify project is providing [`vue-i18n-loader`](https://github.com/intlify/bundle-tools/tree/main/packages/vue-i18n-loader)
135135
136136
:::warning NOTICE
137137
This plugin will be deprecated in the near future, because we can replace `@intlify/unplugin-vue-i18n`.

docs/guide/advanced/sfc.md

Lines changed: 97 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,70 @@ To use i18n custom blocks, you need to use the following plugins for bundler.
5151

5252
## Bundling with Vite
5353

54+
### unplugin-vue-i18n
55+
56+
[`unplugin`](https://github.com/unjs/unplugin) is an unified plugin system for bundle tool such as vite, webpack, rollup, esbuild and etc.
57+
58+
[`unplugin-vue-i18n`](https://github.com/intlify/bundle-tools/tree/main/packages/unplugin-vue-i18n) for vite and webpack.
59+
60+
:::tip REQUIREMENTS
61+
- vite: **v3 or later**
62+
- @vitejs/plugin-vue: **v3.2.0 or later**.
63+
:::
64+
65+
#### Installation
66+
67+
```sh
68+
npm i --save-dev @intlify/unplugin-vue-i18n
69+
```
70+
71+
#### Configure plugin for Vite
72+
73+
See also [use global format](#use-global-format-with-vite-plugin) and [use global scope](#use-global-scope-with-vite-plugin).
74+
75+
```js
76+
// vite.config.ts
77+
import { defineConfig } from 'vite'
78+
import { resolve, dirname } from 'node:path'
79+
import { fileURLToPath } from 'node:url'
80+
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite'
81+
82+
export default defineConfig({
83+
/* ... */
84+
plugins: [
85+
/* ... */
86+
VueI18nPlugin({
87+
/* options */
88+
// locale messages resource pre-compile option
89+
include: resolve(dirname(fileURLToPath(import.meta.url)), './path/to/src/locales/**'),
90+
}),
91+
],
92+
})
93+
```
94+
95+
#### Configure plugin for Webpack
96+
97+
See also [use global format](#use-global-format-with-vite-plugin) and [use global scope](#use-global-scope-with-vite-plugin).
98+
99+
```js
100+
// webpack.config.js
101+
const path = require('path')
102+
const VueI18nPlugin = require('@intlify/unplugin-vue-i18n/webpack')
103+
104+
module.exports = {
105+
/* ... */
106+
plugins: [
107+
/* ... */
108+
VueI18nPlugin({
109+
/* options */
110+
// locale messages resourece pre-compile option
111+
include: path.resolve(__dirname, './path/to/src/locales/**'),
112+
})
113+
]
114+
}
115+
```
116+
117+
54118
### vite-plugin-vue-i18n
55119
56120
[vite-plugin-vue-i18n](https://github.com/intlify/bundle-tools/tree/main/packages/vite-plugin-vue-i18n) is vite plugin for [Vite](https://github.com/vitejs/vite).
@@ -60,6 +124,10 @@ To use i18n custom blocks, you need to use the following plugins for bundler.
60124
- @vitejs/plugin-vue: **v1.0.4 or later**.
61125
:::
62126
127+
:::warning NOTICE
128+
This plugin will be deprecated in the near future, because we can replace `unplugin-vue-i18n`.
129+
:::
130+
63131
#### Installation
64132
65133
```sh
@@ -102,6 +170,10 @@ export default defineConfig({
102170
- vue-loader: **v16 or later**.
103171
:::
104172
173+
:::warning NOTICE
174+
This plugin will be deprecated in the near future, because we can replace `unplugin-vue-i18n`.
175+
:::
176+
105177
#### Installation
106178
107179
```sh
@@ -158,6 +230,10 @@ module.exports = {
158230
- rollup-plugin-vue: **v6 or later**.
159231
:::
160232
233+
:::warning NOTICE
234+
This plugin will be deprecated in the near future, because we can replace `unplugin-vue-i18n`.
235+
:::
236+
161237
#### Installation
162238
163239
```sh
@@ -303,7 +379,7 @@ The `i18n` custom blocks below of `json5` format:
303379
304380
### Define global format
305381
306-
If you are using one of `@intlify/vite-plugin-vue-i18n` plugin on your project, you can also define the `lang` for all your inlined `i18n` custom blocks on all your SFC using the `defaultSFCLang` option.
382+
If you are using `unplugin-vue-i18n` and `vite-plugin-vue-i18n` on your project, you can also define the `lang` for all your inlined `i18n` custom blocks on all your SFC using the `defaultSFCLang` option.
307383
308384
:::warning NOTICE
309385
`@intlify/vue-i18n-loader` and `@intlify/rollup-plugin-vue-i18n` are currently in progress to add this feature.
@@ -392,6 +468,20 @@ plugins: [
392468
You can use define locale messages for global scope with `global` attribute:
393469
394470
```html
471+
<script setup lang="ts">
472+
import { useI18n } from 'vue-i18n'
473+
// something imports ...
474+
475+
/**
476+
* NOTE:
477+
* you **must always call `useI18n` in global scope.
478+
* If you do not call it, the resource defined in the custom block will not be enabled.
479+
*/
480+
const { t } = useI18n(/*{ useScope: 'global' }*/)
481+
482+
// something todo ...
483+
</script>
484+
395485
<i18n global>
396486
{
397487
"en": {
@@ -403,9 +493,14 @@ You can use define locale messages for global scope with `global` attribute:
403493
404494
In the above example, since the `global` attribute is set, the locale messages defined in `i18n` custom blocks can be merged as a resource for locale messages of global scope.
405495
496+
:::warning NOTICE
497+
you **must always call `useI18n` in global scope.
498+
If you do not call it, the resource defined in the custom block will not be enabled.
499+
:::
500+
406501
### Define global scope
407502
408-
If you are using one of `@intlify/vite-plugin-vue-i18n` plugin on your project, you can also define the `global` scope for all your `i18n` custom blocks on all your SFC using the `globalSFCScope` option.
503+
If you are using `unplugin-vue-i18n` and `vite-plugin-vue-i18n` on your project, you can also define the `global` scope for all your `i18n` custom blocks on all your SFC using the `globalSFCScope` option.
409504
410505
:::warning NOTICE
411506
`@intlify/vue-i18n-loader` and `@intlify/rollup-plugin-vue-i18n` are currently in progress to add this feature.

0 commit comments

Comments
 (0)