nuxt-i18n-micro 1.30.1 → 1.31.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.
@@ -1 +1 @@
1
- {"id":"afd22cd8-fdee-49d4-9541-5a6f75690f13","timestamp":1729770728847}
1
+ {"id":"905aebfb-7659-4ec4-86aa-8f4e4ded54d9","timestamp":1729794403479}
@@ -0,0 +1 @@
1
+ {"id":"905aebfb-7659-4ec4-86aa-8f4e4ded54d9","timestamp":1729794403479,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
@@ -1,12 +1,12 @@
1
1
  <!DOCTYPE html><html data-capo=""><head><meta charset="utf-8">
2
2
  <meta name="viewport" content="width=device-width, initial-scale=1">
3
3
  <link rel="stylesheet" href="/__nuxt-i18n-micro/_nuxt/entry.BqOlM4b6.css">
4
- <link rel="modulepreload" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/BVj0VN8T.js">
4
+ <link rel="modulepreload" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/Czi4MokJ.js">
5
5
  <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/B6E6ObS_.js">
6
6
  <link rel="prefetch" as="style" crossorigin href="/__nuxt-i18n-micro/_nuxt/error-404.C_4C5G96.css">
7
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/Tv92-dPW.js">
8
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/zWEC3ICT.js">
7
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/BfH8Q6Ot.js">
8
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/0GmYR_kR.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__nuxt-i18n-micro/_nuxt/error-500.CBAEdpZV.css">
10
- <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/C4U-Ow4Y.js">
11
- <script type="module" src="/__nuxt-i18n-micro/_nuxt/BVj0VN8T.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},1729770742142,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"afd22cd8-fdee-49d4-9541-5a6f75690f13",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
10
+ <link rel="prefetch" as="script" crossorigin href="/__nuxt-i18n-micro/_nuxt/2C6ahHCU.js">
11
+ <script type="module" src="/__nuxt-i18n-micro/_nuxt/Czi4MokJ.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},1729794418117,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__nuxt-i18n-micro",buildId:"905aebfb-7659-4ec4-86aa-8f4e4ded54d9",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.30.1",
4
+ "version": "1.31.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "2.0.0"
package/dist/module.mjs CHANGED
@@ -181,14 +181,12 @@ class PageManager {
181
181
  });
182
182
  if (this.includeDefaultLocaleRoute) {
183
183
  for (let i = pages.length - 1; i >= 0; i--) {
184
- const defaultLocalePath = this.localizedPaths[pages[i].path]?.[this.defaultLocale.code];
185
- if (defaultLocalePath !== null) {
184
+ const page = pages[i];
185
+ const pagePath = page.path ?? "";
186
+ const pageName = page.name ?? "";
187
+ if (this.globalLocaleRoutes[pageName] === false)
186
188
  continue;
187
- }
188
- if (this.globalLocaleRoutes[pages[i].name ?? ""] !== null) {
189
- continue;
190
- }
191
- if (!/^\/:locale/.test(pages[i].path) && pages[i].path !== "/") {
189
+ if (!/^\/:locale/.test(pagePath) && pagePath !== "/") {
192
190
  pages.splice(i, 1);
193
191
  }
194
192
  }
@@ -527,6 +525,17 @@ const module = defineNuxtModule({
527
525
  localeManager.ensureTranslationFilesExist(pagesNames, options.translationDir, nuxt.options.rootDir);
528
526
  }
529
527
  pageManager.extendPages(pages, nuxt.options.rootDir, options.customRegexMatcher);
528
+ if (options.includeDefaultLocaleRoute) {
529
+ const fallbackRoute = {
530
+ path: "/:pathMatch(.*)*",
531
+ name: "custom-fallback-route",
532
+ file: resolver.resolve("./runtime/components/locale-redirect.vue"),
533
+ meta: {
534
+ globalLocaleRoutes: options.globalLocaleRoutes
535
+ }
536
+ };
537
+ pages.push(fallbackRoute);
538
+ }
530
539
  nuxt.options.generate.routes = Array.isArray(nuxt.options.generate.routes) ? nuxt.options.generate.routes : [];
531
540
  const prerenderRoutes = [];
532
541
  localeManager.locales.forEach((locale) => {
@@ -0,0 +1,42 @@
1
+ <template>
2
+ <div />
3
+ </template>
4
+
5
+ <script setup>
6
+ import { useRoute, useI18n, createError, navigateTo } from '#imports'
7
+
8
+ const route = useRoute()
9
+ const { $getLocales, $defaultLocale } = useI18n()
10
+
11
+ const locales = $getLocales().map(locale => locale.code)
12
+ const defaultLocale = $defaultLocale() || 'en'
13
+ const pathSegments = route.fullPath.split('/')
14
+ const firstSegment = pathSegments[1]
15
+
16
+ const generateRouteName = (segments) => {
17
+ return segments
18
+ .filter(segment => segment)
19
+ .map(segment => segment.replace(/:/g, ''))
20
+ .join('-')
21
+ }
22
+
23
+ const currentPageName = generateRouteName(pathSegments)
24
+ const globalLocaleRoutes = route.meta.globalLocaleRoutes ?? {}
25
+
26
+ if (globalLocaleRoutes && globalLocaleRoutes[currentPageName]) {
27
+ const localizedRoutes = globalLocaleRoutes[currentPageName]
28
+ if (localizedRoutes && localizedRoutes[defaultLocale]) {
29
+ const localizedPath = localizedRoutes[defaultLocale]
30
+ navigateTo(localizedPath, { redirectCode: 301, external: true })
31
+ }
32
+ }
33
+ else if (!locales.includes(firstSegment)) {
34
+ const newPath = `/${defaultLocale}${route.fullPath}`
35
+ navigateTo(newPath, { redirectCode: 301, external: true })
36
+ }
37
+ else {
38
+ throw createError({
39
+ statusCode: 404,
40
+ })
41
+ }
42
+ </script>
@@ -87,7 +87,7 @@ function getLocalizedRoute(to, router, route, i18nConfig, locale, hashLocale) {
87
87
  resolvedTo = router.resolve("/" + defaultLocale + to);
88
88
  }
89
89
  const defaultRouteName = getRouteName(resolvedTo, defaultLocale);
90
- const newParams2 = resolveParams(to);
90
+ const newParams2 = resolveParams(resolvedTo);
91
91
  newParams2.locale = defaultLocale;
92
92
  if (router.hasRoute(`localized-${defaultRouteName}`)) {
93
93
  to = router.resolve({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-i18n-micro",
3
- "version": "1.30.1",
3
+ "version": "1.31.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":"afd22cd8-fdee-49d4-9541-5a6f75690f13","timestamp":1729770728847,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}