@intlify/unplugin-vue-i18n 1.4.0 → 1.6.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/README.md +30 -10
- package/lib/index.cjs +34 -4
- package/lib/index.d.cts +1 -0
- package/lib/index.d.mts +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.mjs +34 -4
- package/lib/types.d.cts +4 -0
- package/lib/types.d.mts +4 -0
- package/lib/types.d.ts +4 -0
- package/lib/vite.d.cts +1 -0
- package/lib/vite.d.mts +1 -0
- package/lib/vite.d.ts +1 -0
- package/lib/webpack.d.cts +1 -0
- package/lib/webpack.d.mts +1 -0
- package/lib/webpack.d.ts +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -225,6 +225,8 @@ export default defineConfig({
|
|
|
225
225
|
],
|
|
226
226
|
})
|
|
227
227
|
```
|
|
228
|
+
unplugin-vue-i18n will automatically merge locale files into `@intlify/unplugin-vue-i18n/messages`. This allows locales to be split across multiple files, for example `src/locales/fruits/en.json` and `src/locales/vegetables/en.json`.
|
|
229
|
+
|
|
228
230
|
### Types
|
|
229
231
|
|
|
230
232
|
If you want type definition of `@intlify/unplugin-vue-i18n/messages`, add `unplugin-vue-i18n/messages` to `compilerOptions.types` of your tsconfig:
|
|
@@ -279,13 +281,13 @@ This plugin will automatically select and bundle `petite-vue-i18n` build accordi
|
|
|
279
281
|
|
|
280
282
|
If nothing is specified for this option, i.e. `undefined`, nothing is done to the resource in the above format.
|
|
281
283
|
|
|
282
|
-
> ⚠️ NOTE:
|
|
284
|
+
> ⚠️ NOTE:
|
|
283
285
|
`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.
|
|
284
286
|
|
|
285
|
-
> ⚠️ NOTE:
|
|
287
|
+
> ⚠️ NOTE:
|
|
286
288
|
`yaml` resources don't support multi documentation with `|`, alias with `&` and `*`, tags with `! `, `@`, etc. Only simple data structures.
|
|
287
289
|
|
|
288
|
-
> ⚠️ NOTE:
|
|
290
|
+
> ⚠️ NOTE:
|
|
289
291
|
`js` and `ts` resources are set **simple export (`export default`) as locale messages object, as default**.
|
|
290
292
|
|
|
291
293
|
```js
|
|
@@ -297,7 +299,7 @@ This plugin will automatically select and bundle `petite-vue-i18n` build accordi
|
|
|
297
299
|
|
|
298
300
|
If you need to use programmatically dynamic resource construction, you would be enable `allowDynamic` option. about details, see the section.
|
|
299
301
|
|
|
300
|
-
> ⚠️ NOTE:
|
|
302
|
+
> ⚠️ NOTE:
|
|
301
303
|
If you use the `js` and `ts` resources formats, set the paths, so your application code is not targeted. We recommend that resources be isolated from the application code.
|
|
302
304
|
|
|
303
305
|
|
|
@@ -352,12 +354,12 @@ This plugin will automatically select and bundle `petite-vue-i18n` build accordi
|
|
|
352
354
|
|
|
353
355
|
Whether locale mesages should be compiled by JIT (Just in Time) compilation with vue-i18n's message compiler.
|
|
354
356
|
|
|
355
|
-
> ⚠️ NOTE:
|
|
357
|
+
> ⚠️ NOTE:
|
|
356
358
|
This option works with vue-i18n v9.3 and later.
|
|
357
359
|
|
|
358
360
|
JIT compilation has been supported since vue-i18n v9.3. This means that since v9 was released until now, the message compiler compiles to executable JavaScript code, however it did not work in the CSP environment. Also, since this was an AOT (Ahead of Time) compilation, it was not possible to dynamically retrieve locale messages from the back-end Database and compose locale mesages with programatic.
|
|
359
361
|
|
|
360
|
-
> ⚠️ NOTE:
|
|
362
|
+
> ⚠️ NOTE:
|
|
361
363
|
Enabling JIT compilation causes the message compiler to generate AST objects for locale mesages instead of JavaScript code. If you pre-compile locale messages with a tool such as the [Intlify CLI](https://github.com/intlify/cli) and import them dynamically, you need to rebuild that resource.
|
|
362
364
|
|
|
363
365
|
About JIT compilation, See [here](https://vue-i18n.intlify.dev/guide/advanced/optimization.html#jit-compilation)
|
|
@@ -371,10 +373,10 @@ Whether to tree-shake message compiler when we will be bundling.
|
|
|
371
373
|
|
|
372
374
|
If do you will use this option, you need to enable `jitCompilation` option.
|
|
373
375
|
|
|
374
|
-
> ⚠️ NOTE:
|
|
376
|
+
> ⚠️ NOTE:
|
|
375
377
|
This option works with vue-i18n v9.3 and later.
|
|
376
378
|
|
|
377
|
-
> ⚠️ NOTE:
|
|
379
|
+
> ⚠️ NOTE:
|
|
378
380
|
If you enable this option, **you should check resources in your application are pre-compiled with this plugin.** If you will be loading resources dynamically from the back-end via the API, enabling this option do not work because there is not message compiler.
|
|
379
381
|
|
|
380
382
|
### `ssr`
|
|
@@ -384,7 +386,7 @@ If you enable this option, **you should check resources in your application are
|
|
|
384
386
|
|
|
385
387
|
Whether to bundle vue-i18n module for SSR at build time
|
|
386
388
|
|
|
387
|
-
> ⚠️ NOTE:
|
|
389
|
+
> ⚠️ NOTE:
|
|
388
390
|
This option works with vue-i18n v9.4 and later.
|
|
389
391
|
|
|
390
392
|
### `runtimeOnly`
|
|
@@ -393,7 +395,7 @@ If you enable this option, **you should check resources in your application are
|
|
|
393
395
|
- **Default:** `true`
|
|
394
396
|
|
|
395
397
|
Whether or not to automatically use Vue I18n **runtime-only** in production build, set `vue-i18n.runtime.esm-bundler.js` in the `vue-i18n` field of bundler config, the below:
|
|
396
|
-
|
|
398
|
+
|
|
397
399
|
```
|
|
398
400
|
- vite config: `resolve.alias`
|
|
399
401
|
- webpack config: `resolve.alias`
|
|
@@ -545,6 +547,24 @@ If you enable this option, **you should check resources in your application are
|
|
|
545
547
|
|
|
546
548
|
> ⚠️ Note that if you set `bridge: true`, the bundle size will increase. It is recommended to disable this mode after the migration from vue-i18n@v8.26 to vue-i18n@v9.x is completed.
|
|
547
549
|
|
|
550
|
+
### `legacy`
|
|
551
|
+
|
|
552
|
+
- **Type:** `boolean`
|
|
553
|
+
- **Default:** `false`
|
|
554
|
+
|
|
555
|
+
This option supports Vue I18n v8.x compatibility for resources in i18n custom blocks.
|
|
556
|
+
|
|
557
|
+
> ⚠️ To work for Vue 2.7, the value of `vueVersion` must be set to `'v2.7'`.
|
|
558
|
+
|
|
559
|
+
### `vueVersion`
|
|
560
|
+
|
|
561
|
+
- **Type:** `string`
|
|
562
|
+
- **Default:** `undefined`
|
|
563
|
+
|
|
564
|
+
The version of Vue that will be used by Vue I18n. This option is enabled when the `legacy` option is `true`.
|
|
565
|
+
|
|
566
|
+
Available values are `'v2.6'` and `'v2.7'`.
|
|
567
|
+
|
|
548
568
|
### `esm`
|
|
549
569
|
|
|
550
570
|
- **Type:** `boolean`
|
package/lib/index.cjs
CHANGED
|
@@ -131,6 +131,9 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
131
131
|
const useClassComponent = !!options.useClassComponent;
|
|
132
132
|
const bridge = !!options.bridge;
|
|
133
133
|
debug("bridge", bridge);
|
|
134
|
+
const legacy = !!options.legacy;
|
|
135
|
+
debug("legacy", legacy);
|
|
136
|
+
const vueVersion = shared.isString(options.vueVersion) ? options.vueVersion : void 0;
|
|
134
137
|
const runtimeOnly = shared.isBoolean(options.runtimeOnly) ? options.runtimeOnly : true;
|
|
135
138
|
debug("runtimeOnly", runtimeOnly);
|
|
136
139
|
const jitCompilation = !!options.jitCompilation;
|
|
@@ -307,6 +310,8 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
307
310
|
strictMessage,
|
|
308
311
|
escapeHtml,
|
|
309
312
|
bridge,
|
|
313
|
+
legacy,
|
|
314
|
+
vueVersion,
|
|
310
315
|
jit: jitCompilation,
|
|
311
316
|
onlyLocales,
|
|
312
317
|
exportESM: esm,
|
|
@@ -522,6 +527,8 @@ const unplugin = unplugin$1.createUnplugin((options = {}, meta) => {
|
|
|
522
527
|
isGlobal: globalSFCScope,
|
|
523
528
|
useClassComponent,
|
|
524
529
|
bridge,
|
|
530
|
+
legacy,
|
|
531
|
+
vueVersion,
|
|
525
532
|
jit: jitCompilation,
|
|
526
533
|
strictMessage,
|
|
527
534
|
escapeHtml,
|
|
@@ -629,10 +636,29 @@ async function generateBundleResources(resources, query, isProduction, {
|
|
|
629
636
|
codes.push(`${JSON.stringify(name)}: ${code}`);
|
|
630
637
|
}
|
|
631
638
|
}
|
|
632
|
-
return `
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
639
|
+
return `const isObject = (item) => item && typeof item === 'object' && !Array.isArray(item);
|
|
640
|
+
|
|
641
|
+
const mergeDeep = (target, ...sources) => {
|
|
642
|
+
if (!sources.length) return target;
|
|
643
|
+
const source = sources.shift();
|
|
644
|
+
|
|
645
|
+
if (isObject(target) && isObject(source)) {
|
|
646
|
+
for (const key in source) {
|
|
647
|
+
if (isObject(source[key])) {
|
|
648
|
+
if (!target[key]) Object.assign(target, { [key]: {} });
|
|
649
|
+
mergeDeep(target[key], source[key]);
|
|
650
|
+
} else {
|
|
651
|
+
Object.assign(target, { [key]: source[key] });
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
return mergeDeep(target, ...sources);
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
export default mergeDeep({},
|
|
660
|
+
${codes.map((code) => `{${code}}`).join(",\n")}
|
|
661
|
+
);`;
|
|
636
662
|
}
|
|
637
663
|
async function getCode(source, filename, sourceMap, query, framework = "vite") {
|
|
638
664
|
const { index, issuerPath } = query;
|
|
@@ -671,6 +697,8 @@ function getOptions(filename, isProduction, query, sourceMap, {
|
|
|
671
697
|
forceStringify = false,
|
|
672
698
|
isGlobal = false,
|
|
673
699
|
bridge = false,
|
|
700
|
+
legacy = false,
|
|
701
|
+
vueVersion = "v2.6",
|
|
674
702
|
onlyLocales = [],
|
|
675
703
|
exportESM = true,
|
|
676
704
|
useClassComponent = false,
|
|
@@ -690,6 +718,8 @@ function getOptions(filename, isProduction, query, sourceMap, {
|
|
|
690
718
|
strictMessage,
|
|
691
719
|
escapeHtml,
|
|
692
720
|
bridge,
|
|
721
|
+
legacy,
|
|
722
|
+
vueVersion,
|
|
693
723
|
jit,
|
|
694
724
|
onlyLocales,
|
|
695
725
|
exportESM,
|
package/lib/index.d.cts
CHANGED
package/lib/index.d.mts
CHANGED
package/lib/index.d.ts
CHANGED
package/lib/index.mjs
CHANGED
|
@@ -119,6 +119,9 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
119
119
|
const useClassComponent = !!options.useClassComponent;
|
|
120
120
|
const bridge = !!options.bridge;
|
|
121
121
|
debug("bridge", bridge);
|
|
122
|
+
const legacy = !!options.legacy;
|
|
123
|
+
debug("legacy", legacy);
|
|
124
|
+
const vueVersion = isString(options.vueVersion) ? options.vueVersion : void 0;
|
|
122
125
|
const runtimeOnly = isBoolean(options.runtimeOnly) ? options.runtimeOnly : true;
|
|
123
126
|
debug("runtimeOnly", runtimeOnly);
|
|
124
127
|
const jitCompilation = !!options.jitCompilation;
|
|
@@ -295,6 +298,8 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
295
298
|
strictMessage,
|
|
296
299
|
escapeHtml,
|
|
297
300
|
bridge,
|
|
301
|
+
legacy,
|
|
302
|
+
vueVersion,
|
|
298
303
|
jit: jitCompilation,
|
|
299
304
|
onlyLocales,
|
|
300
305
|
exportESM: esm,
|
|
@@ -510,6 +515,8 @@ const unplugin = createUnplugin((options = {}, meta) => {
|
|
|
510
515
|
isGlobal: globalSFCScope,
|
|
511
516
|
useClassComponent,
|
|
512
517
|
bridge,
|
|
518
|
+
legacy,
|
|
519
|
+
vueVersion,
|
|
513
520
|
jit: jitCompilation,
|
|
514
521
|
strictMessage,
|
|
515
522
|
escapeHtml,
|
|
@@ -617,10 +624,29 @@ async function generateBundleResources(resources, query, isProduction, {
|
|
|
617
624
|
codes.push(`${JSON.stringify(name)}: ${code}`);
|
|
618
625
|
}
|
|
619
626
|
}
|
|
620
|
-
return `
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
627
|
+
return `const isObject = (item) => item && typeof item === 'object' && !Array.isArray(item);
|
|
628
|
+
|
|
629
|
+
const mergeDeep = (target, ...sources) => {
|
|
630
|
+
if (!sources.length) return target;
|
|
631
|
+
const source = sources.shift();
|
|
632
|
+
|
|
633
|
+
if (isObject(target) && isObject(source)) {
|
|
634
|
+
for (const key in source) {
|
|
635
|
+
if (isObject(source[key])) {
|
|
636
|
+
if (!target[key]) Object.assign(target, { [key]: {} });
|
|
637
|
+
mergeDeep(target[key], source[key]);
|
|
638
|
+
} else {
|
|
639
|
+
Object.assign(target, { [key]: source[key] });
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
return mergeDeep(target, ...sources);
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
export default mergeDeep({},
|
|
648
|
+
${codes.map((code) => `{${code}}`).join(",\n")}
|
|
649
|
+
);`;
|
|
624
650
|
}
|
|
625
651
|
async function getCode(source, filename, sourceMap, query, framework = "vite") {
|
|
626
652
|
const { index, issuerPath } = query;
|
|
@@ -659,6 +685,8 @@ function getOptions(filename, isProduction, query, sourceMap, {
|
|
|
659
685
|
forceStringify = false,
|
|
660
686
|
isGlobal = false,
|
|
661
687
|
bridge = false,
|
|
688
|
+
legacy = false,
|
|
689
|
+
vueVersion = "v2.6",
|
|
662
690
|
onlyLocales = [],
|
|
663
691
|
exportESM = true,
|
|
664
692
|
useClassComponent = false,
|
|
@@ -678,6 +706,8 @@ function getOptions(filename, isProduction, query, sourceMap, {
|
|
|
678
706
|
strictMessage,
|
|
679
707
|
escapeHtml,
|
|
680
708
|
bridge,
|
|
709
|
+
legacy,
|
|
710
|
+
vueVersion,
|
|
681
711
|
jit,
|
|
682
712
|
onlyLocales,
|
|
683
713
|
exportESM,
|
package/lib/types.d.cts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CodeGenOptions } from '@intlify/bundle-utils';
|
|
2
|
+
|
|
1
3
|
type SFCLangFormat = 'json' | 'json5' | 'yml' | 'yaml';
|
|
2
4
|
interface PluginOptions {
|
|
3
5
|
include?: string | string[];
|
|
@@ -14,6 +16,8 @@ interface PluginOptions {
|
|
|
14
16
|
defaultSFCLang?: SFCLangFormat;
|
|
15
17
|
globalSFCScope?: boolean;
|
|
16
18
|
bridge?: boolean;
|
|
19
|
+
legacy?: boolean;
|
|
20
|
+
vueVersion?: CodeGenOptions['vueVersion'];
|
|
17
21
|
useClassComponent?: boolean;
|
|
18
22
|
useVueI18nImportName?: boolean;
|
|
19
23
|
strictMessage?: boolean;
|
package/lib/types.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CodeGenOptions } from '@intlify/bundle-utils';
|
|
2
|
+
|
|
1
3
|
type SFCLangFormat = 'json' | 'json5' | 'yml' | 'yaml';
|
|
2
4
|
interface PluginOptions {
|
|
3
5
|
include?: string | string[];
|
|
@@ -14,6 +16,8 @@ interface PluginOptions {
|
|
|
14
16
|
defaultSFCLang?: SFCLangFormat;
|
|
15
17
|
globalSFCScope?: boolean;
|
|
16
18
|
bridge?: boolean;
|
|
19
|
+
legacy?: boolean;
|
|
20
|
+
vueVersion?: CodeGenOptions['vueVersion'];
|
|
17
21
|
useClassComponent?: boolean;
|
|
18
22
|
useVueI18nImportName?: boolean;
|
|
19
23
|
strictMessage?: boolean;
|
package/lib/types.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CodeGenOptions } from '@intlify/bundle-utils';
|
|
2
|
+
|
|
1
3
|
type SFCLangFormat = 'json' | 'json5' | 'yml' | 'yaml';
|
|
2
4
|
interface PluginOptions {
|
|
3
5
|
include?: string | string[];
|
|
@@ -14,6 +16,8 @@ interface PluginOptions {
|
|
|
14
16
|
defaultSFCLang?: SFCLangFormat;
|
|
15
17
|
globalSFCScope?: boolean;
|
|
16
18
|
bridge?: boolean;
|
|
19
|
+
legacy?: boolean;
|
|
20
|
+
vueVersion?: CodeGenOptions['vueVersion'];
|
|
17
21
|
useClassComponent?: boolean;
|
|
18
22
|
useVueI18nImportName?: boolean;
|
|
19
23
|
strictMessage?: boolean;
|
package/lib/vite.d.cts
CHANGED
package/lib/vite.d.mts
CHANGED
package/lib/vite.d.ts
CHANGED
package/lib/webpack.d.cts
CHANGED
package/lib/webpack.d.mts
CHANGED
package/lib/webpack.d.ts
CHANGED