nuxt-i18n-micro 1.83.3 → 1.84.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.
@@ -8,5 +8,5 @@
8
8
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BBbCCCx2.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.BRj5A2lo.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/CfVvufsh.js">
11
- <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/MjlAM4Ld.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1744713099692,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"d336aef4-7a77-4a5f-81be-4d05de86c7bc",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
11
+ <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/MjlAM4Ld.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1745573186060,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"b44e2c27-d406-446e-8b5c-449b8e228196",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
@@ -8,5 +8,5 @@
8
8
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BBbCCCx2.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.BRj5A2lo.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/CfVvufsh.js">
11
- <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/MjlAM4Ld.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1744713099692,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"d336aef4-7a77-4a5f-81be-4d05de86c7bc",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
11
+ <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/MjlAM4Ld.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1745573186060,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"b44e2c27-d406-446e-8b5c-449b8e228196",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
@@ -1 +1 @@
1
- {"id":"d336aef4-7a77-4a5f-81be-4d05de86c7bc","timestamp":1744713090095}
1
+ {"id":"b44e2c27-d406-446e-8b5c-449b8e228196","timestamp":1745573180739}
@@ -0,0 +1 @@
1
+ {"id":"b44e2c27-d406-446e-8b5c-449b8e228196","timestamp":1745573180739,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
@@ -8,5 +8,5 @@
8
8
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BBbCCCx2.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.BRj5A2lo.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/CfVvufsh.js">
11
- <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/MjlAM4Ld.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1744713099692,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"d336aef4-7a77-4a5f-81be-4d05de86c7bc",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
11
+ <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/MjlAM4Ld.js" crossorigin></script></head><body><div id="__nuxt"></div><div id="teleports"></div><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1745573186060,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"b44e2c27-d406-446e-8b5c-449b8e228196",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-i18n-micro",
3
3
  "configKey": "i18n",
4
- "version": "1.83.3",
4
+ "version": "1.84.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "2.0.0"
package/dist/module.mjs CHANGED
@@ -1,13 +1,13 @@
1
1
  import path, { resolve } from 'node:path';
2
2
  import * as fs from 'node:fs';
3
3
  import fs__default, { readFileSync, existsSync, mkdirSync, writeFileSync } from 'node:fs';
4
- import { useNuxt, defineNuxtModule, useLogger, createResolver, addTemplate, addImportsDir, addPlugin, addServerHandler, addComponentsDir, addTypeTemplate, extendPages, addPrerenderRoutes } from '@nuxt/kit';
4
+ import { useNuxt, defineNuxtModule, useLogger, createResolver, addTemplate, addImportsDir, addPlugin, addServerHandler, addComponentsDir, addTypeTemplate, addPrerenderRoutes } from '@nuxt/kit';
5
5
  import { watch } from 'chokidar';
6
6
  import { isPrefixAndDefaultStrategy, isPrefixStrategy, isNoPrefixStrategy, isPrefixExceptDefaultStrategy, withPrefixStrategy } from 'nuxt-i18n-micro-core';
7
7
  import { fileURLToPath } from 'node:url';
8
8
  import { onDevToolsInitialized, extendServerRpc } from '@nuxt/devtools-kit';
9
9
  import sirv from 'sirv';
10
- import { extractLocaleRoutes, normalizePath, isLocaleDefault, isPageRedirectOnly, cloneArray, buildRouteName, removeLeadingSlash, shouldAddLocalePrefix, buildFullPath, buildFullPathNoPrefix } from './utils.mjs';
10
+ import { extractLocaleRoutes, normalizePath, isLocaleDefault, isPageRedirectOnly, cloneArray, removeLeadingSlash, buildRouteName, shouldAddLocalePrefix, buildFullPath, buildFullPathNoPrefix } from './utils.mjs';
11
11
 
12
12
  const DEVTOOLS_UI_PORT = 3030;
13
13
  const DEVTOOLS_UI_ROUTE = "/__nuxt-i18n-micro";
@@ -287,15 +287,77 @@ class PageManager {
287
287
  }
288
288
  });
289
289
  }
290
- createLocalizedChildren(routes, parentPath, localeCodes, modifyName = true, addLocalePrefix = false) {
291
- return routes.flatMap((route) => this.createLocalizedVariants(route, parentPath, localeCodes, modifyName, addLocalePrefix));
290
+ createLocalizedChildren(routes, parentPath, localeCodes, modifyName = true, addLocalePrefix = false, parentIsLocalized = false, localizedParentPaths = {}) {
291
+ return routes.flatMap(
292
+ (route) => this.createLocalizedVariants(
293
+ route,
294
+ parentPath,
295
+ localeCodes,
296
+ modifyName,
297
+ addLocalePrefix,
298
+ parentIsLocalized,
299
+ localizedParentPaths
300
+ )
301
+ );
292
302
  }
293
- createLocalizedVariants(route, parentPath, localeCodes, modifyName, addLocalePrefix) {
303
+ createLocalizedVariants(route, parentPath, localeCodes, modifyName, addLocalePrefix, parentIsLocalized, localizedParentPaths) {
294
304
  const routePath = normalizePath(route.path);
305
+ const isDynamic = routePath.startsWith(":");
295
306
  const fullPath = normalizePath(path.posix.join(parentPath, routePath));
296
307
  const customLocalePaths = this.localizedPaths[fullPath];
297
- const localizedChildren = this.createLocalizedChildren(route.children ?? [], fullPath, localeCodes, modifyName);
298
- return localeCodes.map((locale) => this.createLocalizedChildRoute(route, routePath, locale, customLocalePaths, localizedChildren, modifyName, addLocalePrefix));
308
+ if (isDynamic && !customLocalePaths) {
309
+ const localizedChildren = this.createLocalizedChildren(
310
+ route.children ?? [],
311
+ fullPath,
312
+ localeCodes,
313
+ modifyName,
314
+ addLocalePrefix,
315
+ true,
316
+ localizedParentPaths
317
+ );
318
+ const baseName = buildRouteNameFromRoute(route.name, route.path);
319
+ return [
320
+ {
321
+ ...route,
322
+ name: modifyName ? `localized-${baseName}` : baseName,
323
+ path: removeLeadingSlash(routePath),
324
+ children: localizedChildren
325
+ }
326
+ ];
327
+ }
328
+ const result = [];
329
+ for (const locale of localeCodes) {
330
+ const parentPathLocalized = localizedParentPaths[locale] || parentPath;
331
+ const fullPath2 = normalizePath(path.posix.join(parentPathLocalized, routePath));
332
+ const localizedChildren = this.createLocalizedChildren(
333
+ route.children ?? [],
334
+ fullPath2,
335
+ [locale],
336
+ modifyName,
337
+ addLocalePrefix,
338
+ true,
339
+ localizedParentPaths
340
+ );
341
+ const routeName = this.buildLocalizedRouteName(
342
+ buildRouteNameFromRoute(route.name, route.path),
343
+ locale,
344
+ modifyName,
345
+ parentIsLocalized || !!customLocalePaths
346
+ );
347
+ const finalPath = this.buildLocalizedRoutePath(
348
+ routePath,
349
+ locale,
350
+ customLocalePaths,
351
+ addLocalePrefix
352
+ );
353
+ result.push({
354
+ ...route,
355
+ name: routeName,
356
+ path: removeLeadingSlash(finalPath),
357
+ children: localizedChildren
358
+ });
359
+ }
360
+ return result;
299
361
  }
300
362
  createLocalizedRoute(page, localeCodes, originalChildren, isCustom, customPath = "", customRegex, force = false) {
301
363
  const routePath = this.buildRoutePath(localeCodes, page.path, encodeURI(customPath), isCustom, customRegex, force);
@@ -304,28 +366,25 @@ class PageManager {
304
366
  const routeName = buildRouteName(buildRouteNameFromRoute(page.name, page.path), localeCodes[0], isCustom);
305
367
  return {
306
368
  ...page,
307
- children: this.createLocalizedChildren(originalChildren, page.path, localeCodes, true),
369
+ children: this.createLocalizedChildren(originalChildren, page.path, localeCodes, true, false, true),
308
370
  path: routePath,
309
371
  name: routeName
310
372
  };
311
373
  }
312
- createLocalizedChildRoute(route, routePath, locale, customLocalePaths, children, modifyName, addLocalePrefix) {
313
- const finalPath = this.buildLocalizedRoutePath(routePath, locale, customLocalePaths, addLocalePrefix);
314
- const routeName = this.buildLocalizedRouteName(buildRouteNameFromRoute(route.name, route.path), locale, modifyName);
315
- return {
316
- ...route,
317
- name: routeName,
318
- path: removeLeadingSlash(finalPath),
319
- children
320
- };
321
- }
322
374
  buildLocalizedRoutePath(routePath, locale, customLocalePaths, addLocalePrefix) {
323
375
  const basePath = customLocalePaths?.[locale] || routePath;
324
376
  const normalizedBasePath = encodeURI(normalizePath(basePath));
325
377
  return shouldAddLocalePrefix(locale, this.defaultLocale, addLocalePrefix, isPrefixStrategy(this.strategy)) ? buildFullPath(locale, normalizedBasePath) : normalizedBasePath;
326
378
  }
327
- buildLocalizedRouteName(baseName, locale, modifyName) {
328
- return modifyName && !isLocaleDefault(locale, this.defaultLocale, isPrefixStrategy(this.strategy) || isPrefixAndDefaultStrategy(this.strategy)) ? `localized-${baseName}-${locale}` : baseName;
379
+ buildLocalizedRouteName(baseName, locale, modifyName, forceLocaleSuffix = false) {
380
+ if (!modifyName) {
381
+ return baseName;
382
+ }
383
+ if (forceLocaleSuffix) {
384
+ return `localized-${baseName}-${locale}`;
385
+ }
386
+ const shouldAddLocaleSuffix = locale && !isLocaleDefault(locale, this.defaultLocale, isPrefixStrategy(this.strategy) || isPrefixAndDefaultStrategy(this.strategy));
387
+ return shouldAddLocaleSuffix ? `localized-${baseName}-${locale}` : `localized-${baseName}`;
329
388
  }
330
389
  buildRoutePath(localeCodes, originalPath, customPath, isCustom, customRegex, force = false) {
331
390
  if (isNoPrefixStrategy(this.strategy)) {
@@ -554,7 +613,7 @@ const module = defineNuxtModule({
554
613
  getContents: () => generateI18nTypes()
555
614
  });
556
615
  }
557
- extendPages((pages) => {
616
+ nuxt.hook("pages:resolved", (pages) => {
558
617
  const prerenderRoutes = [];
559
618
  const pagesNames = pages.map((page) => page.name).filter((name) => name !== void 0 && (!options.routesLocaleLinks || !options.routesLocaleLinks[name]));
560
619
  localeManager.locales.forEach((locale) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-i18n-micro",
3
- "version": "1.83.3",
3
+ "version": "1.84.0",
4
4
  "description": "Nuxt I18n Micro is a lightweight, high-performance internationalization module for Nuxt, designed to handle multi-language support with minimal overhead, fast build times, and efficient runtime performance.",
5
5
  "repository": "s00d/nuxt-i18n-micro",
6
6
  "license": "MIT",
@@ -60,8 +60,8 @@
60
60
  "sirv": "^2.0.4",
61
61
  "ufo": "^1.5.4",
62
62
  "nuxt-i18n-micro-core": "1.0.18",
63
- "nuxt-i18n-micro-test-utils": "1.0.6",
64
- "nuxt-i18n-micro-types": "1.0.4"
63
+ "nuxt-i18n-micro-types": "1.0.4",
64
+ "nuxt-i18n-micro-test-utils": "1.0.6"
65
65
  },
66
66
  "devDependencies": {
67
67
  "@nuxt/devtools": "^2.1.0",
@@ -1 +0,0 @@
1
- {"id":"d336aef4-7a77-4a5f-81be-4d05de86c7bc","timestamp":1744713090095,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}