@intlify/unplugin-vue-i18n 1.4.0 → 1.5.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 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:
package/lib/index.cjs CHANGED
@@ -629,10 +629,29 @@ async function generateBundleResources(resources, query, isProduction, {
629
629
  codes.push(`${JSON.stringify(name)}: ${code}`);
630
630
  }
631
631
  }
632
- return `export default {
633
- ${codes.join(`,
634
- `)}
635
- }`;
632
+ return `const isObject = (item) => item && typeof item === 'object' && !Array.isArray(item);
633
+
634
+ const mergeDeep = (target, ...sources) => {
635
+ if (!sources.length) return target;
636
+ const source = sources.shift();
637
+
638
+ if (isObject(target) && isObject(source)) {
639
+ for (const key in source) {
640
+ if (isObject(source[key])) {
641
+ if (!target[key]) Object.assign(target, { [key]: {} });
642
+ mergeDeep(target[key], source[key]);
643
+ } else {
644
+ Object.assign(target, { [key]: source[key] });
645
+ }
646
+ }
647
+ }
648
+
649
+ return mergeDeep(target, ...sources);
650
+ }
651
+
652
+ export default mergeDeep({},
653
+ ${codes.map((code) => `{${code}}`).join(",\n")}
654
+ );`;
636
655
  }
637
656
  async function getCode(source, filename, sourceMap, query, framework = "vite") {
638
657
  const { index, issuerPath } = query;
package/lib/index.mjs CHANGED
@@ -617,10 +617,29 @@ async function generateBundleResources(resources, query, isProduction, {
617
617
  codes.push(`${JSON.stringify(name)}: ${code}`);
618
618
  }
619
619
  }
620
- return `export default {
621
- ${codes.join(`,
622
- `)}
623
- }`;
620
+ return `const isObject = (item) => item && typeof item === 'object' && !Array.isArray(item);
621
+
622
+ const mergeDeep = (target, ...sources) => {
623
+ if (!sources.length) return target;
624
+ const source = sources.shift();
625
+
626
+ if (isObject(target) && isObject(source)) {
627
+ for (const key in source) {
628
+ if (isObject(source[key])) {
629
+ if (!target[key]) Object.assign(target, { [key]: {} });
630
+ mergeDeep(target[key], source[key]);
631
+ } else {
632
+ Object.assign(target, { [key]: source[key] });
633
+ }
634
+ }
635
+ }
636
+
637
+ return mergeDeep(target, ...sources);
638
+ }
639
+
640
+ export default mergeDeep({},
641
+ ${codes.map((code) => `{${code}}`).join(",\n")}
642
+ );`;
624
643
  }
625
644
  async function getCode(source, filename, sourceMap, query, framework = "vite") {
626
645
  const { index, issuerPath } = query;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@intlify/unplugin-vue-i18n",
3
- "version": "1.4.0",
3
+ "version": "1.5.0",
4
4
  "description": "unplugin for Vue I18n",
5
5
  "author": {
6
6
  "name": "kazuya kawaguchi",