nuxt-i18n-micro 1.96.0 → 1.97.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.
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
  [![Donate](https://img.shields.io/badge/Donate-Donationalerts-ff4081?style=for-the-badge)](https://www.donationalerts.com/r/s00d88)
5
5
 
6
6
  <p align="center">
7
- <img src="https://github.com/s00d/nuxt-i18n-micro/blob/main/logo.png?raw=true" alt="logo">
7
+ <img src="https://github.com/s00d/nuxt-i18n-micro/blob/main/branding/logo_full.png?raw=true" alt="logo">
8
8
  </p>
9
9
 
10
10
  # Nuxt I18n Micro
@@ -8,5 +8,5 @@
8
8
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BrUpQP6I.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.DGwSTbEi.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/C0zq22yw.js">
11
- <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/ivw-WKkv.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},1758176687705,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"2bd7945f-6cbd-45d4-9b72-30c2c2aeb875",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
11
+ <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/ivw-WKkv.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},1758813952163,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"6376a03b-f005-4f0f-b051-3b017577666c",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
@@ -8,5 +8,5 @@
8
8
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BrUpQP6I.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.DGwSTbEi.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/C0zq22yw.js">
11
- <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/ivw-WKkv.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},1758176687705,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"2bd7945f-6cbd-45d4-9b72-30c2c2aeb875",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
11
+ <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/ivw-WKkv.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},1758813952163,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"6376a03b-f005-4f0f-b051-3b017577666c",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
@@ -1 +1 @@
1
- {"id":"2bd7945f-6cbd-45d4-9b72-30c2c2aeb875","timestamp":1758176680760}
1
+ {"id":"6376a03b-f005-4f0f-b051-3b017577666c","timestamp":1758813945370}
@@ -0,0 +1 @@
1
+ {"id":"6376a03b-f005-4f0f-b051-3b017577666c","timestamp":1758813945370,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
@@ -8,5 +8,5 @@
8
8
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/BrUpQP6I.js">
9
9
  <link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.DGwSTbEi.css">
10
10
  <link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/C0zq22yw.js">
11
- <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/ivw-WKkv.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},1758176687705,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"2bd7945f-6cbd-45d4-9b72-30c2c2aeb875",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
11
+ <script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/ivw-WKkv.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},1758813952165,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"6376a03b-f005-4f0f-b051-3b017577666c",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.96.0",
4
+ "version": "1.97.0",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -108,7 +108,46 @@ function setupDevToolsUI(options, resolve2) {
108
108
  });
109
109
  }
110
110
 
111
- const isInternalPath = (p) => /(?:^|\/)__[^/]+/.test(p);
111
+ const DEFAULT_STATIC_PATTERNS = [
112
+ /^\/sitemap.*\.xml$/,
113
+ /^\/sitemap\.xml$/,
114
+ /^\/robots\.txt$/,
115
+ /^\/favicon\.ico$/,
116
+ /^\/apple-touch-icon.*\.png$/,
117
+ /^\/manifest\.json$/,
118
+ /^\/sw\.js$/,
119
+ /^\/workbox-.*\.js$/,
120
+ /\.(xml|txt|ico|json|js|css|png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)$/
121
+ ];
122
+ const isInternalPath = (path2, excludePatterns) => {
123
+ if (/(?:^|\/)__[^/]+/.test(path2)) {
124
+ return true;
125
+ }
126
+ for (const pattern of DEFAULT_STATIC_PATTERNS) {
127
+ if (pattern.test(path2)) {
128
+ return true;
129
+ }
130
+ }
131
+ if (excludePatterns) {
132
+ for (const pattern of excludePatterns) {
133
+ if (typeof pattern === "string") {
134
+ if (pattern.includes("*") || pattern.includes("?")) {
135
+ const regex = new RegExp(pattern.replace(/\*/g, ".*").replace(/\?/g, "."));
136
+ if (regex.test(path2)) {
137
+ return true;
138
+ }
139
+ } else if (path2 === pattern || path2.startsWith(pattern)) {
140
+ return true;
141
+ }
142
+ } else if (pattern instanceof RegExp) {
143
+ if (pattern.test(path2)) {
144
+ return true;
145
+ }
146
+ }
147
+ }
148
+ }
149
+ return false;
150
+ };
112
151
  function extractLocaleRoutes(content, filePath) {
113
152
  const defineMatch = content.match(/\$?\bdefineI18nRoute\s*\(\s*\{[\s\S]*?\}\s*\)/);
114
153
  if (defineMatch) {
@@ -177,11 +216,13 @@ class PageManager {
177
216
  activeLocaleCodes;
178
217
  globalLocaleRoutes;
179
218
  noPrefixRedirect;
180
- constructor(locales, defaultLocaleCode, strategy, globalLocaleRoutes, noPrefixRedirect) {
219
+ excludePatterns;
220
+ constructor(locales, defaultLocaleCode, strategy, globalLocaleRoutes, noPrefixRedirect, excludePatterns) {
181
221
  this.locales = locales;
182
222
  this.defaultLocale = this.findLocaleByCode(defaultLocaleCode) || { code: defaultLocaleCode };
183
223
  this.strategy = strategy;
184
224
  this.noPrefixRedirect = noPrefixRedirect;
225
+ this.excludePatterns = excludePatterns;
185
226
  this.activeLocaleCodes = this.computeActiveLocaleCodes();
186
227
  this.globalLocaleRoutes = globalLocaleRoutes || {};
187
228
  }
@@ -200,7 +241,7 @@ class PageManager {
200
241
  this.localizedPaths = this.extractLocalizedPaths(pages);
201
242
  const additionalRoutes = [];
202
243
  for (const page of [...pages]) {
203
- if (page.path && isInternalPath(page.path)) {
244
+ if (page.path && isInternalPath(page.path, this.excludePatterns)) {
204
245
  continue;
205
246
  }
206
247
  if (!page.name && page.file?.endsWith(".vue")) {
@@ -222,7 +263,7 @@ class PageManager {
222
263
  if (!page) continue;
223
264
  const pagePath = page.path ?? "";
224
265
  const pageName = page.name ?? "";
225
- if (isInternalPath(pagePath)) continue;
266
+ if (isInternalPath(pagePath, this.excludePatterns)) continue;
226
267
  if (this.globalLocaleRoutes[pageName] === false) continue;
227
268
  if (!/^\/:locale/.test(pagePath) && pagePath !== "/") {
228
269
  pages.splice(i, 1);
@@ -578,7 +619,8 @@ const module = defineNuxtModule({
578
619
  if (!selectedForm) return null;
579
620
  return selectedForm.trim().replace("{count}", count.toString());
580
621
  },
581
- customRegexMatcher: void 0
622
+ customRegexMatcher: void 0,
623
+ excludePatterns: void 0
582
624
  },
583
625
  async setup(options, nuxt) {
584
626
  const defaultLocale = process.env.DEFAULT_LOCALE ?? options.defaultLocale ?? "en";
@@ -596,7 +638,7 @@ const module = defineNuxtModule({
596
638
  const resolver = createResolver(import.meta.url);
597
639
  const rootDirs = nuxt.options._layers.map((layer) => layer.config.rootDir).reverse();
598
640
  const localeManager = new LocaleManager(options, rootDirs);
599
- const pageManager = new PageManager(localeManager.locales, defaultLocale, options.strategy, options.globalLocaleRoutes, options.noPrefixRedirect);
641
+ const pageManager = new PageManager(localeManager.locales, defaultLocale, options.strategy, options.globalLocaleRoutes, options.noPrefixRedirect, options.excludePatterns);
600
642
  addTemplate({
601
643
  filename: "i18n.plural.mjs",
602
644
  write: true,
@@ -620,7 +662,8 @@ const module = defineNuxtModule({
620
662
  apiBaseUrl,
621
663
  isSSG,
622
664
  disablePageLocales: options.disablePageLocales ?? false,
623
- canonicalQueryWhitelist: options.canonicalQueryWhitelist ?? []
665
+ canonicalQueryWhitelist: options.canonicalQueryWhitelist ?? [],
666
+ excludePatterns: options.excludePatterns ?? []
624
667
  };
625
668
  if (typeof options.customRegexMatcher !== "undefined") {
626
669
  const localeCodes = localeManager.locales.map((l) => l.code);
@@ -734,7 +777,7 @@ const module = defineNuxtModule({
734
777
  const processPageWithChildren = (page, parentPath = "") => {
735
778
  if (!page.path) return;
736
779
  const fullPath = path.posix.normalize(`${parentPath}/${page.path}`);
737
- if (isInternalPath(fullPath)) {
780
+ if (isInternalPath(fullPath, options.excludePatterns)) {
738
781
  return;
739
782
  }
740
783
  const routeRule = routeRules[fullPath];
@@ -753,13 +796,13 @@ const module = defineNuxtModule({
753
796
  if (localizedRouteRule && localizedRouteRule.prerender === false) {
754
797
  return;
755
798
  }
756
- if (!isInternalPath(localizedPath)) {
799
+ if (!isInternalPath(localizedPath, options.excludePatterns)) {
757
800
  prerenderRoutes.push(localizedPath);
758
801
  }
759
802
  }
760
803
  });
761
804
  } else {
762
- if (!isInternalPath(fullPath)) {
805
+ if (!isInternalPath(fullPath, options.excludePatterns)) {
763
806
  prerenderRoutes.push(fullPath);
764
807
  }
765
808
  }
@@ -883,7 +926,7 @@ const module = defineNuxtModule({
883
926
  const routesSet = prerenderRoutes.routes;
884
927
  const routesToRemove = [];
885
928
  routesSet.forEach((route) => {
886
- if (isInternalPath(route)) {
929
+ if (isInternalPath(route, options.excludePatterns)) {
887
930
  routesToRemove.push(route);
888
931
  }
889
932
  });
@@ -891,7 +934,7 @@ const module = defineNuxtModule({
891
934
  const additionalRoutes = /* @__PURE__ */ new Set();
892
935
  const routeRules = nuxt.options.routeRules || {};
893
936
  routesSet.forEach((route) => {
894
- if (!/\.[a-z0-9]+$/i.test(route) && !isInternalPath(route)) {
937
+ if (!/\.[a-z0-9]+$/i.test(route) && !isInternalPath(route, options.excludePatterns)) {
895
938
  localeManager.locales.forEach((locale) => {
896
939
  const shouldGenerate = locale.code !== defaultLocale || withPrefixStrategy(options.strategy);
897
940
  if (shouldGenerate) {
@@ -3,13 +3,22 @@
3
3
  </template>
4
4
 
5
5
  <script setup>
6
- import { useRoute, useI18n, createError, navigateTo } from "#imports";
6
+ import { useRoute, useI18n, createError, navigateTo, useRuntimeConfig } from "#imports";
7
+ import { isInternalPath } from "../../utils";
7
8
  const route = useRoute();
8
9
  const { $getLocales, $defaultLocale } = useI18n();
10
+ const config = useRuntimeConfig();
9
11
  const locales = $getLocales().map((locale) => locale.code);
10
12
  const defaultLocale = $defaultLocale() || "en";
11
13
  const pathSegments = route.fullPath.split("/");
12
14
  const firstSegment = pathSegments[1];
15
+ const excludePatterns = config.public.i18nConfig?.excludePatterns;
16
+ if (isInternalPath(route.fullPath, excludePatterns)) {
17
+ throw createError({
18
+ statusCode: 404,
19
+ statusMessage: "Static file - should not be processed by i18n"
20
+ });
21
+ }
13
22
  const generateRouteName = (segments) => {
14
23
  return segments.slice(1).map((segment) => segment.replace(/:/g, "")).join("-");
15
24
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-i18n-micro",
3
- "version": "1.96.0",
3
+ "version": "1.97.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",
@@ -63,7 +63,7 @@
63
63
  "ufo": "^1.5.4",
64
64
  "nuxt-i18n-micro-core": "1.0.18",
65
65
  "nuxt-i18n-micro-test-utils": "1.0.6",
66
- "nuxt-i18n-micro-types": "1.0.6"
66
+ "nuxt-i18n-micro-types": "1.0.7"
67
67
  },
68
68
  "devDependencies": {
69
69
  "@nuxt/devtools": "^2.6.3",
@@ -1 +0,0 @@
1
- {"id":"2bd7945f-6cbd-45d4-9b72-30c2c2aeb875","timestamp":1758176680760,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}