nuxt-i18n-micro 1.63.2 → 1.64.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/AXE8DZQI.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.EgQ3RNLZ.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/D9gx-VEt.js">
11
- <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/Ddb0iCRU.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},1737032293724,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"4fb36a07-acc6-4000-9c26-f521b5d784b5",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
11
+ <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/Ddb0iCRU.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},1737052999565,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"17ca5a6a-83c6-4759-8a74-a56490050218",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
@@ -8,5 +8,5 @@
8
8
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/AXE8DZQI.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.EgQ3RNLZ.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/D9gx-VEt.js">
11
- <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/Ddb0iCRU.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},1737032293724,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"4fb36a07-acc6-4000-9c26-f521b5d784b5",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
11
+ <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/Ddb0iCRU.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},1737052999565,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"17ca5a6a-83c6-4759-8a74-a56490050218",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
@@ -1 +1 @@
1
- {"id":"4fb36a07-acc6-4000-9c26-f521b5d784b5","timestamp":1737032288794}
1
+ {"id":"17ca5a6a-83c6-4759-8a74-a56490050218","timestamp":1737052992903}
@@ -0,0 +1 @@
1
+ {"id":"17ca5a6a-83c6-4759-8a74-a56490050218","timestamp":1737052992903,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
@@ -8,5 +8,5 @@
8
8
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/AXE8DZQI.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.EgQ3RNLZ.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/D9gx-VEt.js">
11
- <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/Ddb0iCRU.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},1737032293724,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"4fb36a07-acc6-4000-9c26-f521b5d784b5",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
11
+ <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/Ddb0iCRU.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},1737052999565,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"17ca5a6a-83c6-4759-8a74-a56490050218",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.63.2",
4
+ "version": "1.64.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "2.0.0"
package/dist/module.mjs CHANGED
@@ -8,7 +8,7 @@ import { globby } from 'globby';
8
8
  import { fileURLToPath } from 'node:url';
9
9
  import { onDevToolsInitialized, extendServerRpc } from '@nuxt/devtools-kit';
10
10
  import sirv from 'sirv';
11
- import { extractLocaleRoutes, normalizePath, isLocaleDefault, isPageRedirectOnly, cloneArray, buildRouteName, removeLeadingSlash, shouldAddLocalePrefix, buildFullPath } from './utils.mjs';
11
+ import { extractLocaleRoutes, normalizePath, isLocaleDefault, isPageRedirectOnly, cloneArray, buildRouteName, removeLeadingSlash, shouldAddLocalePrefix, buildFullPath, buildFullPathNoPrefix } from './utils.mjs';
12
12
  import { isPrefixAndDefaultStrategy, isPrefixStrategy, isNoPrefixStrategy, withPrefixStrategy } from '../dist/runtime/helpers.js';
13
13
 
14
14
  const DEVTOOLS_UI_PORT = 3030;
@@ -201,13 +201,23 @@ class PageManager {
201
201
  if (!customPath)
202
202
  return;
203
203
  const isDefaultLocale = isLocaleDefault(locale, this.defaultLocale, isPrefixStrategy(this.strategy));
204
- if (isDefaultLocale) {
205
- page.path = normalizePath(customPath);
204
+ if (isNoPrefixStrategy(this.strategy)) {
205
+ const newRoute = this.createLocalizedRoute(page, [locale.code], page.children ?? [], true, customPath, customRegex);
206
+ if (newRoute)
207
+ additionalRoutes.push(newRoute);
206
208
  } else {
207
- additionalRoutes.push(this.createLocalizedRoute(page, [locale.code], page.children ?? [], true, customPath, customRegex));
208
- }
209
- if (isPrefixAndDefaultStrategy(this.strategy) && locale === this.defaultLocale) {
210
- additionalRoutes.push(this.createLocalizedRoute(page, [locale.code], page.children ?? [], true, customPath, customRegex, true));
209
+ if (isDefaultLocale) {
210
+ page.path = normalizePath(customPath);
211
+ } else {
212
+ const newRoute = this.createLocalizedRoute(page, [locale.code], page.children ?? [], true, customPath, customRegex);
213
+ if (newRoute)
214
+ additionalRoutes.push(newRoute);
215
+ }
216
+ if (isPrefixAndDefaultStrategy(this.strategy) && locale === this.defaultLocale) {
217
+ const newRoute = this.createLocalizedRoute(page, [locale.code], page.children ?? [], true, customPath, customRegex, true);
218
+ if (newRoute)
219
+ additionalRoutes.push(newRoute);
220
+ }
211
221
  }
212
222
  });
213
223
  }
@@ -218,7 +228,9 @@ class PageManager {
218
228
  const normalizedFullPath = normalizePath(page.path);
219
229
  const localeCodesWithoutCustomPaths = this.filterLocaleCodesWithoutCustomPaths(normalizedFullPath);
220
230
  if (localeCodesWithoutCustomPaths.length) {
221
- additionalRoutes.push(this.createLocalizedRoute(page, localeCodesWithoutCustomPaths, originalChildren, false, "", customRegex));
231
+ const newRoute = this.createLocalizedRoute(page, localeCodesWithoutCustomPaths, originalChildren, false, "", customRegex);
232
+ if (newRoute)
233
+ additionalRoutes.push(newRoute);
222
234
  }
223
235
  this.addCustomLocalizedRoutes(page, normalizedFullPath, originalChildren, additionalRoutes);
224
236
  this.adjustRouteForDefaultLocale(page, originalChildren);
@@ -262,10 +274,14 @@ class PageManager {
262
274
  if (isDefaultLocale) {
263
275
  page.children = this.createLocalizedChildren(originalChildren, "", [locale.code], false);
264
276
  } else {
265
- additionalRoutes.push(this.createLocalizedRoute(page, [locale.code], originalChildren, true, customPath, customRegex));
277
+ const newRoute = this.createLocalizedRoute(page, [locale.code], originalChildren, true, customPath, customRegex);
278
+ if (newRoute)
279
+ additionalRoutes.push(newRoute);
266
280
  }
267
281
  if (isPrefixAndDefaultStrategy(this.strategy) && locale === this.defaultLocale) {
268
- additionalRoutes.push(this.createLocalizedRoute(page, [locale.code], originalChildren, true, customPath, customRegex, true));
282
+ const newRoute = this.createLocalizedRoute(page, [locale.code], originalChildren, true, customPath, customRegex, true);
283
+ if (newRoute)
284
+ additionalRoutes.push(newRoute);
269
285
  }
270
286
  });
271
287
  }
@@ -281,6 +297,8 @@ class PageManager {
281
297
  }
282
298
  createLocalizedRoute(page, localeCodes, originalChildren, isCustom, customPath = "", customRegex, force = false) {
283
299
  const routePath = this.buildRoutePath(localeCodes, page.path, encodeURI(customPath), isCustom, customRegex, force);
300
+ if (!routePath || routePath == page.path)
301
+ return null;
284
302
  const routeName = buildRouteName(buildRouteNameFromRoute(page.name, page.path), localeCodes[0], isCustom);
285
303
  return {
286
304
  ...page,
@@ -308,6 +326,9 @@ class PageManager {
308
326
  return modifyName && !isLocaleDefault(locale, this.defaultLocale, isPrefixStrategy(this.strategy) || isPrefixAndDefaultStrategy(this.strategy)) ? `localized-${baseName}-${locale}` : baseName;
309
327
  }
310
328
  buildRoutePath(localeCodes, originalPath, customPath, isCustom, customRegex, force = false) {
329
+ if (isNoPrefixStrategy(this.strategy)) {
330
+ return buildFullPathNoPrefix(isCustom ? customPath : originalPath);
331
+ }
311
332
  if (isCustom) {
312
333
  return force || isPrefixStrategy(this.strategy) || !localeCodes.includes(this.defaultLocale.code) ? buildFullPath(localeCodes, customPath, customRegex) : normalizePath(customPath);
313
334
  }
@@ -565,11 +586,11 @@ const module = defineNuxtModule({
565
586
  }
566
587
  prerenderRoutes.push(`/${apiBaseUrl}/general/${locale.code}/data.json`);
567
588
  });
589
+ if (!options.disableWatcher) {
590
+ localeManager.ensureTranslationFilesExist(pagesNames, options.translationDir, nuxt.options.rootDir);
591
+ }
592
+ pageManager.extendPages(pages, options.customRegexMatcher, isCloudflarePages);
568
593
  if (!isNoPrefixStrategy(options.strategy)) {
569
- if (!options.disableWatcher) {
570
- localeManager.ensureTranslationFilesExist(pagesNames, options.translationDir, nuxt.options.rootDir);
571
- }
572
- pageManager.extendPages(pages, options.customRegexMatcher, isCloudflarePages);
573
594
  if (isPrefixStrategy(options.strategy) && !isCloudflarePages) {
574
595
  const fallbackRoute = {
575
596
  path: "/:pathMatch(.*)*",
@@ -43,7 +43,7 @@ function switchLocaleRoute(fromLocale, toLocale, route, router, i18nConfig, i18n
43
43
  const routeName = getRouteName(route, fromLocale);
44
44
  if (router.hasRoute(`localized-${routeName}-${toLocale}`)) {
45
45
  const newParams2 = { ...route.params, ...i18nRouteParams?.[toLocale] };
46
- newParams2.locale = toLocale;
46
+ if (!isNoPrefixStrategy(i18nConfig.strategy)) newParams2.locale = toLocale;
47
47
  const newRoute2 = {
48
48
  name: `localized-${routeName}-${toLocale}`,
49
49
  params: newParams2
@@ -62,14 +62,23 @@ function switchLocaleRoute(fromLocale, toLocale, route, router, i18nConfig, i18n
62
62
  } else {
63
63
  newRouteName = toLocale !== i18nConfig.defaultLocale || withPrefixStrategy(i18nConfig.strategy) ? `localized-${routeName}` : routeName;
64
64
  }
65
- if (toLocale !== i18nConfig.defaultLocale || withPrefixStrategy(i18nConfig.strategy)) {
66
- newParams.locale = toLocale;
65
+ if (!isNoPrefixStrategy(i18nConfig.strategy)) {
66
+ if (toLocale !== i18nConfig.defaultLocale || withPrefixStrategy(i18nConfig.strategy)) {
67
+ newParams.locale = toLocale;
68
+ }
67
69
  }
68
70
  }
69
71
  const newRoute = {
70
72
  name: newRouteName,
71
73
  params: newParams
72
74
  };
75
+ if (isNoPrefixStrategy(i18nConfig.strategy)) {
76
+ i18nConfig.locales?.forEach((locale, _index) => {
77
+ if (newRoute.name.endsWith(`-${locale.code}`)) {
78
+ newRoute.name = newRoute.name.slice(0, -locale.code - 1);
79
+ }
80
+ });
81
+ }
73
82
  if (currentLocale?.baseUrl) {
74
83
  return getFullPathWithBaseUrl(newRoute);
75
84
  }
@@ -116,7 +125,7 @@ function getLocalizedRoute(to, router, route, i18nConfig, locale, hashLocale, no
116
125
  }
117
126
  const defaultRouteName = getRouteName(resolvedTo, defaultLocale);
118
127
  const newParams2 = resolveParams(resolvedTo);
119
- newParams2.locale = defaultLocale;
128
+ if (!isNoPrefixStrategy(i18nConfig.strategy)) newParams2.locale = defaultLocale;
120
129
  if (router.hasRoute(`localized-${defaultRouteName}`)) {
121
130
  to = router.resolve({
122
131
  name: `localized-${defaultRouteName}`,
@@ -148,7 +157,7 @@ function getLocalizedRoute(to, router, route, i18nConfig, locale, hashLocale, no
148
157
  }
149
158
  if (router.hasRoute(`localized-${routeName}-${currentLocale}`)) {
150
159
  const newParams2 = resolveParams(selectRoute);
151
- newParams2.locale = currentLocale;
160
+ if (!isNoPrefixStrategy(i18nConfig.strategy)) newParams2.locale = currentLocale;
152
161
  return router.resolve({
153
162
  name: `localized-${routeName}-${currentLocale}`,
154
163
  params: newParams2,
@@ -172,8 +181,10 @@ function getLocalizedRoute(to, router, route, i18nConfig, locale, hashLocale, no
172
181
  }
173
182
  const newParams = resolveParams(to);
174
183
  delete newParams.locale;
175
- if (currentLocale !== i18nConfig.defaultLocale || withPrefixStrategy(i18nConfig.strategy)) {
176
- newParams.locale = currentLocale;
184
+ if (!isNoPrefixStrategy(i18nConfig.strategy)) {
185
+ if (currentLocale !== i18nConfig.defaultLocale || withPrefixStrategy(i18nConfig.strategy)) {
186
+ newParams.locale = currentLocale;
187
+ }
177
188
  }
178
189
  return router.resolve({
179
190
  name: newRouteName,
@@ -1,4 +1,4 @@
1
- import { isPrefixStrategy } from "../helpers.js";
1
+ import { isNoPrefixStrategy, isPrefixStrategy } from "../helpers.js";
2
2
  import { defineNuxtPlugin, navigateTo, useNuxtApp, useRuntimeConfig } from "#app";
3
3
  import { useRoute, useRouter } from "#imports";
4
4
  export default defineNuxtPlugin(async (_nuxtApp) => {
@@ -31,7 +31,9 @@ export default defineNuxtPlugin(async (_nuxtApp) => {
31
31
  return;
32
32
  }
33
33
  const newParams = { ...to.params };
34
- newParams.locale = i18nConfig.defaultLocale;
34
+ if (!isNoPrefixStrategy(i18nConfig.strategy)) {
35
+ newParams.locale = i18nConfig.defaultLocale;
36
+ }
35
37
  return navigateTo({ name: defaultRouteName, params: newParams }, { redirectCode: 301, external: true });
36
38
  }
37
39
  };
@@ -42,8 +42,10 @@ export default defineNuxtPlugin(async (nuxtApp) => {
42
42
  const newRouteName = isPrefixStrategy(i18nConfig.strategy) || newLocale !== defaultLocale ? `localized-${routeName}` : routeName;
43
43
  const newParams = { ...route.params };
44
44
  delete newParams.locale;
45
- if (isPrefixStrategy(i18nConfig.strategy) || newLocale !== defaultLocale) {
46
- newParams.locale = newLocale;
45
+ if (!isNoPrefixStrategy(i18nConfig.strategy)) {
46
+ if (isPrefixStrategy(i18nConfig.strategy) || newLocale !== defaultLocale) {
47
+ newParams.locale = newLocale;
48
+ }
47
49
  }
48
50
  const newRoute = router.resolve({
49
51
  name: newRouteName,
package/dist/utils.d.mts CHANGED
@@ -11,5 +11,6 @@ declare const buildRouteName: (baseName: string, localeCode: string, isCustom: b
11
11
  declare const shouldAddLocalePrefix: (locale: string, defaultLocale: Locale, addLocalePrefix: boolean, includeDefaultLocaleRoute: boolean) => boolean;
12
12
  declare const isLocaleDefault: (locale: string | Locale, defaultLocale: Locale, includeDefaultLocaleRoute: boolean) => boolean;
13
13
  declare const buildFullPath: (locale: string | string[], basePath: string, customRegex?: string | RegExp) => string;
14
+ declare const buildFullPathNoPrefix: (basePath: string) => string;
14
15
 
15
- export { buildFullPath, buildRouteName, cloneArray, extractLocaleRoutes, isLocaleDefault, isPageRedirectOnly, normalizePath, removeLeadingSlash, shouldAddLocalePrefix, validateDefineI18nRouteConfig };
16
+ export { buildFullPath, buildFullPathNoPrefix, buildRouteName, cloneArray, extractLocaleRoutes, isLocaleDefault, isPageRedirectOnly, normalizePath, removeLeadingSlash, shouldAddLocalePrefix, validateDefineI18nRouteConfig };
package/dist/utils.d.ts CHANGED
@@ -11,5 +11,6 @@ declare const buildRouteName: (baseName: string, localeCode: string, isCustom: b
11
11
  declare const shouldAddLocalePrefix: (locale: string, defaultLocale: Locale, addLocalePrefix: boolean, includeDefaultLocaleRoute: boolean) => boolean;
12
12
  declare const isLocaleDefault: (locale: string | Locale, defaultLocale: Locale, includeDefaultLocaleRoute: boolean) => boolean;
13
13
  declare const buildFullPath: (locale: string | string[], basePath: string, customRegex?: string | RegExp) => string;
14
+ declare const buildFullPathNoPrefix: (basePath: string) => string;
14
15
 
15
- export { buildFullPath, buildRouteName, cloneArray, extractLocaleRoutes, isLocaleDefault, isPageRedirectOnly, normalizePath, removeLeadingSlash, shouldAddLocalePrefix, validateDefineI18nRouteConfig };
16
+ export { buildFullPath, buildFullPathNoPrefix, buildRouteName, cloneArray, extractLocaleRoutes, isLocaleDefault, isPageRedirectOnly, normalizePath, removeLeadingSlash, shouldAddLocalePrefix, validateDefineI18nRouteConfig };
package/dist/utils.mjs CHANGED
@@ -51,10 +51,13 @@ const buildFullPath = (locale, basePath, customRegex) => {
51
51
  const localeParam = regexString ? regexString : Array.isArray(locale) ? locale.join("|") : locale;
52
52
  return normalizePath(path.posix.join("/", `:locale(${localeParam})`, basePath));
53
53
  };
54
+ const buildFullPathNoPrefix = (basePath) => {
55
+ return normalizePath(basePath);
56
+ };
54
57
  const normalizeRegex = (toNorm) => {
55
58
  if (typeof toNorm === "undefined")
56
59
  return void 0;
57
60
  return toNorm.startsWith("/") && toNorm.endsWith("/") ? toNorm?.slice(1, -1) : toNorm;
58
61
  };
59
62
 
60
- export { buildFullPath, buildRouteName, cloneArray, extractLocaleRoutes, isLocaleDefault, isPageRedirectOnly, normalizePath, removeLeadingSlash, shouldAddLocalePrefix, validateDefineI18nRouteConfig };
63
+ export { buildFullPath, buildFullPathNoPrefix, buildRouteName, cloneArray, extractLocaleRoutes, isLocaleDefault, isPageRedirectOnly, normalizePath, removeLeadingSlash, shouldAddLocalePrefix, validateDefineI18nRouteConfig };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-i18n-micro",
3
- "version": "1.63.2",
3
+ "version": "1.64.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",
@@ -1 +0,0 @@
1
- {"id":"4fb36a07-acc6-4000-9c26-f521b5d784b5","timestamp":1737032288794,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}