nuxt-i18n-micro 2.7.0 → 2.8.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/CBxwnKtU.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.BqKd8Zt-.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BYEpoBUk.js">
11
- <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/XZXfxmri.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},1762430716730,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"e84c9eb7-2c0b-4741-b5c3-f8a613bfb352",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
11
+ <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/XZXfxmri.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},1763453693479,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"9a1fb0d2-6a76-47f9-959f-57ea625d621e",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
@@ -8,5 +8,5 @@
8
8
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/CBxwnKtU.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.BqKd8Zt-.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BYEpoBUk.js">
11
- <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/XZXfxmri.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},1762430716731,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"e84c9eb7-2c0b-4741-b5c3-f8a613bfb352",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
11
+ <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/XZXfxmri.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},1763453693479,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"9a1fb0d2-6a76-47f9-959f-57ea625d621e",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
@@ -1 +1 @@
1
- {"id":"e84c9eb7-2c0b-4741-b5c3-f8a613bfb352","timestamp":1762430710401}
1
+ {"id":"9a1fb0d2-6a76-47f9-959f-57ea625d621e","timestamp":1763453685364}
@@ -0,0 +1 @@
1
+ {"id":"9a1fb0d2-6a76-47f9-959f-57ea625d621e","timestamp":1763453685364,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
@@ -8,5 +8,5 @@
8
8
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/CBxwnKtU.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.BqKd8Zt-.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BYEpoBUk.js">
11
- <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/XZXfxmri.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},1762430716731,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"e84c9eb7-2c0b-4741-b5c3-f8a613bfb352",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
11
+ <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/XZXfxmri.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},1763453693479,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"9a1fb0d2-6a76-47f9-959f-57ea625d621e",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": "2.7.0",
4
+ "version": "2.8.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
@@ -3,63 +3,69 @@
3
3
  </template>
4
4
 
5
5
  <script setup>
6
- import { useRoute, useI18n, createError, navigateTo, useRuntimeConfig } from "#imports";
6
+ import { useRoute, useRouter, useI18n, createError, navigateTo, useRuntimeConfig } from "#imports";
7
7
  import { isInternalPath } from "../utils/path-utils";
8
+ import { isPrefixStrategy, isPrefixExceptDefaultStrategy } from "nuxt-i18n-micro-core";
8
9
  const route = useRoute();
10
+ const router = useRouter();
9
11
  const { $getLocales, $defaultLocale } = useI18n();
10
12
  const config = useRuntimeConfig();
13
+ const i18nConfig = config.public.i18nConfig;
14
+ const strategy = i18nConfig?.strategy || "prefix_except_default";
11
15
  const locales = $getLocales().map((locale) => locale.code);
12
16
  const defaultLocale = $defaultLocale() || "en";
13
17
  const pathSegments = route.fullPath.split("/");
14
18
  const firstSegment = pathSegments[1];
15
- const excludePatterns = config.public.i18nConfig?.excludePatterns;
16
- if (isInternalPath(route.fullPath, excludePatterns)) {
19
+ if (isInternalPath(route.fullPath, i18nConfig?.excludePatterns)) {
17
20
  throw createError({
18
21
  statusCode: 404,
19
22
  statusMessage: "Static file - should not be processed by i18n"
20
23
  });
21
24
  }
22
- const generateRouteName = (segments) => {
23
- return segments.slice(1).map((segment) => segment.replace(/:/g, "")).join("-");
24
- };
25
- const generateLocaleRouteName = (segments) => {
26
- return segments.filter((segment) => segment && segment.trim() !== "").slice(1).map((segment) => segment.replace(/:/g, "")).join("-");
27
- };
28
- const currentPageName = generateRouteName(pathSegments);
29
- const currentLocalePageName = generateLocaleRouteName(pathSegments);
30
- const globalLocaleRoutes = route.meta.globalLocaleRoutes ?? {};
31
25
  const handleRedirect = (path) => {
26
+ const finalPath = route.query && Object.keys(route.query).length > 0 ? `${path}?${new URLSearchParams(route.query).toString()}` : path;
32
27
  if (import.meta.client) {
33
- window.history.replaceState(null, "", path);
34
- location.assign(path);
28
+ window.history.replaceState(null, "", finalPath);
29
+ location.assign(finalPath);
35
30
  } else {
36
- navigateTo(path, { redirectCode: 301, external: true });
31
+ navigateTo(finalPath, { redirectCode: 301, external: true });
37
32
  }
38
33
  };
39
- if (globalLocaleRoutes && globalLocaleRoutes[currentPageName]) {
40
- const localizedRoutes = globalLocaleRoutes[currentPageName];
41
- if (localizedRoutes && localizedRoutes[defaultLocale]) {
42
- const localizedPath = localizedRoutes[defaultLocale];
43
- if (route.fullPath !== localizedPath) {
44
- handleRedirect(localizedPath);
45
- }
34
+ const routeExists = (path) => {
35
+ try {
36
+ const resolved = router.resolve(path);
37
+ return resolved.name && resolved.name !== "custom-fallback-route" && resolved.matched.length > 0;
38
+ } catch {
39
+ return false;
46
40
  }
47
- } else if (!locales.includes(firstSegment)) {
48
- const newPath = `/${defaultLocale}${route.fullPath}`;
49
- if (route.fullPath !== newPath) {
50
- handleRedirect(newPath);
41
+ };
42
+ const globalLocaleRoutes = route.meta.globalLocaleRoutes ?? {};
43
+ const currentPageName = route.path.split("/").filter(Boolean).join("-");
44
+ if (locales.includes(firstSegment)) {
45
+ const pathWithoutPrefix = "/" + pathSegments.slice(2).join("/");
46
+ if (isPrefixExceptDefaultStrategy(strategy) && firstSegment === defaultLocale) {
47
+ throw createError({
48
+ statusCode: 404,
49
+ statusMessage: `Page not found for default locale with prefix ('${firstSegment}')`
50
+ });
51
51
  }
52
- } else if (locales.includes(firstSegment) && globalLocaleRoutes && globalLocaleRoutes[currentLocalePageName]) {
53
- const localizedRoutes = globalLocaleRoutes[currentLocalePageName];
54
- if (localizedRoutes && localizedRoutes[firstSegment]) {
55
- const localizedPath = `/${firstSegment}/${localizedRoutes[firstSegment]}`;
56
- if (route.fullPath !== localizedPath) {
57
- handleRedirect(localizedPath);
58
- }
52
+ const customPath = globalLocaleRoutes[currentPageName]?.[firstSegment];
53
+ if (customPath && customPath !== pathWithoutPrefix) {
54
+ handleRedirect(`/${firstSegment}${customPath}`);
59
55
  }
60
56
  } else {
61
- throw createError({
62
- statusCode: 404
63
- });
57
+ const customPath = globalLocaleRoutes[currentPageName]?.[defaultLocale];
58
+ if (customPath && customPath !== route.fullPath) {
59
+ const targetPath = isPrefixStrategy(strategy) ? `/${defaultLocale}${customPath}` : customPath;
60
+ handleRedirect(targetPath);
61
+ } else if (isPrefixStrategy(strategy)) {
62
+ const newPathWithPrefix = `/${defaultLocale}${route.fullPath}`;
63
+ if (routeExists(newPathWithPrefix)) {
64
+ handleRedirect(newPathWithPrefix);
65
+ }
66
+ }
64
67
  }
68
+ throw createError({
69
+ statusCode: 404
70
+ });
65
71
  </script>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-i18n-micro",
3
- "version": "2.7.0",
3
+ "version": "2.8.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":"e84c9eb7-2c0b-4741-b5c3-f8a613bfb352","timestamp":1762430710401,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}