nuxt-i18n-micro 1.54.2 → 1.55.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/BzXxbhIZ.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.DWqKq_Wn.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/B85fdbn4.js">
11
- <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BhDLGWZB.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},1735770973734,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"56373574-c482-42c6-83fa-99b488b146b3",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
11
+ <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BhDLGWZB.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},1735902518699,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"af1dab1c-c3cf-4127-b3f8-8cfc1bb495ea",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
@@ -8,5 +8,5 @@
8
8
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BzXxbhIZ.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.DWqKq_Wn.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/B85fdbn4.js">
11
- <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BhDLGWZB.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},1735770973734,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"56373574-c482-42c6-83fa-99b488b146b3",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
11
+ <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BhDLGWZB.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},1735902518700,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"af1dab1c-c3cf-4127-b3f8-8cfc1bb495ea",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
@@ -1 +1 @@
1
- {"id":"56373574-c482-42c6-83fa-99b488b146b3","timestamp":1735770968652}
1
+ {"id":"af1dab1c-c3cf-4127-b3f8-8cfc1bb495ea","timestamp":1735902513062}
@@ -0,0 +1 @@
1
+ {"id":"af1dab1c-c3cf-4127-b3f8-8cfc1bb495ea","timestamp":1735902513062,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
@@ -8,5 +8,5 @@
8
8
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BzXxbhIZ.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.DWqKq_Wn.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/B85fdbn4.js">
11
- <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BhDLGWZB.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},1735770973735,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"56373574-c482-42c6-83fa-99b488b146b3",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
11
+ <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BhDLGWZB.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},1735902518700,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"af1dab1c-c3cf-4127-b3f8-8cfc1bb495ea",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.54.2",
4
+ "version": "1.55.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "2.0.0"
@@ -15,12 +15,21 @@ const firstSegment = pathSegments[1]
15
15
 
16
16
  const generateRouteName = (segments) => {
17
17
  return segments
18
- .filter(segment => segment)
18
+ .slice(1)
19
+ .map(segment => segment.replace(/:/g, ''))
20
+ .join('-')
21
+ }
22
+
23
+ const generateLocaleRouteName = (segments) => {
24
+ return segments
25
+ .filter(segment => segment && segment.trim() !== '')
26
+ .slice(1)
19
27
  .map(segment => segment.replace(/:/g, ''))
20
28
  .join('-')
21
29
  }
22
30
 
23
31
  const currentPageName = generateRouteName(pathSegments)
32
+ const currentLocalePageName = generateLocaleRouteName(pathSegments)
24
33
  const globalLocaleRoutes = route.meta.globalLocaleRoutes ?? {}
25
34
 
26
35
  if (globalLocaleRoutes && globalLocaleRoutes[currentPageName]) {
@@ -34,6 +43,13 @@ else if (!locales.includes(firstSegment)) {
34
43
  const newPath = `/${defaultLocale}${route.fullPath}`
35
44
  navigateTo(newPath, { redirectCode: 301, external: true })
36
45
  }
46
+ else if (locales.includes(firstSegment) && globalLocaleRoutes && globalLocaleRoutes[currentLocalePageName]) {
47
+ const localizedRoutes = globalLocaleRoutes[currentLocalePageName]
48
+ if (localizedRoutes && localizedRoutes[firstSegment]) {
49
+ const localizedPath = `/${firstSegment}${localizedRoutes[firstSegment]}`
50
+ navigateTo(localizedPath, { redirectCode: 301, external: true })
51
+ }
52
+ }
37
53
  else {
38
54
  throw createError({
39
55
  statusCode: 404,
@@ -60,7 +60,11 @@ function switchLocaleRoute(fromLocale, toLocale, route, router, i18nConfig, i18n
60
60
  const newParams = { ...route.params, ...i18nRouteParams?.[toLocale] };
61
61
  delete newParams.locale;
62
62
  if (!isNoPrefixStrategy(i18nConfig.strategy)) {
63
- newRouteName = toLocale !== i18nConfig.defaultLocale || withPrefixStrategy(i18nConfig.strategy) ? `localized-${routeName}` : routeName;
63
+ if (routeName === "custom-fallback-route") {
64
+ newRouteName = routeName;
65
+ } else {
66
+ newRouteName = toLocale !== i18nConfig.defaultLocale || withPrefixStrategy(i18nConfig.strategy) ? `localized-${routeName}` : routeName;
67
+ }
64
68
  if (toLocale !== i18nConfig.defaultLocale || withPrefixStrategy(i18nConfig.strategy)) {
65
69
  newParams.locale = toLocale;
66
70
  }
@@ -347,18 +351,38 @@ export default defineNuxtPlugin(async (nuxtApp) => {
347
351
  switchLocale(fromLocale, toLocale, route, router, i18nConfig, i18nRouteParams.value);
348
352
  },
349
353
  switchRoute: (route, toLocale) => {
354
+ const currentRoute = router.currentRoute.value;
355
+ const fromLocale = getCurrentLocale(currentRoute, i18nConfig, hashLocale, noPrefixDefault);
356
+ const currentLocale = toLocale ?? fromLocale;
350
357
  if (typeof route === "string") {
351
- route = router.resolve(route);
358
+ if (currentLocale !== i18nConfig.defaultLocale || withPrefixStrategy(i18nConfig.strategy)) {
359
+ const currentRoute2 = router.currentRoute.value;
360
+ const fromLocale2 = getCurrentLocale(currentRoute2, i18nConfig, hashLocale, noPrefixDefault);
361
+ route = router.resolve("/" + fromLocale2 + route);
362
+ } else {
363
+ route = router.resolve(route);
364
+ }
352
365
  }
353
- const fromLocale = getCurrentLocale(route, i18nConfig, hashLocale, noPrefixDefault);
354
366
  if (i18nConfig.hashMode) {
355
367
  hashLocale = toLocale ?? fromLocale;
356
368
  }
357
369
  switchLocale(fromLocale, toLocale ?? fromLocale, route, router, i18nConfig, i18nRouteParams.value);
358
370
  },
359
371
  localeRoute: (to, locale) => {
372
+ const currentRoute = router.currentRoute.value;
373
+ const fromLocale = getCurrentLocale(currentRoute, i18nConfig, hashLocale, noPrefixDefault);
374
+ const currentLocale = locale ?? fromLocale;
375
+ if (typeof to === "string") {
376
+ if (currentLocale !== i18nConfig.defaultLocale || withPrefixStrategy(i18nConfig.strategy)) {
377
+ const currentRoute2 = router.currentRoute.value;
378
+ const fromLocale2 = getCurrentLocale(currentRoute2, i18nConfig, hashLocale, noPrefixDefault);
379
+ to = router.resolve("/" + fromLocale2 + to);
380
+ } else {
381
+ to = router.resolve(to);
382
+ }
383
+ }
360
384
  const route = router.currentRoute.value;
361
- return getLocalizedRoute(to, router, route, i18nConfig, locale, hashLocale);
385
+ return getLocalizedRoute(to, router, route, i18nConfig, currentLocale, hashLocale);
362
386
  },
363
387
  localePath: (to, locale) => {
364
388
  const route = router.currentRoute.value;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-i18n-micro",
3
- "version": "1.54.2",
3
+ "version": "1.55.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":"56373574-c482-42c6-83fa-99b488b146b3","timestamp":1735770968652,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}