nuxt-i18n-micro 1.52.0 → 1.53.2

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},1735030489134,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"3086ca3a-1f67-491b-a81d-22fa2fedfc38",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},1735326990745,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"1ab47290-de16-4dde-bcb8-21cd8741e18a",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},1735030489134,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"3086ca3a-1f67-491b-a81d-22fa2fedfc38",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},1735326990745,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"1ab47290-de16-4dde-bcb8-21cd8741e18a",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
@@ -1 +1 @@
1
- {"id":"3086ca3a-1f67-491b-a81d-22fa2fedfc38","timestamp":1735030484548}
1
+ {"id":"1ab47290-de16-4dde-bcb8-21cd8741e18a","timestamp":1735326985777}
@@ -0,0 +1 @@
1
+ {"id":"1ab47290-de16-4dde-bcb8-21cd8741e18a","timestamp":1735326985777,"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},1735030489134,false]</script>
12
- <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"3086ca3a-1f67-491b-a81d-22fa2fedfc38",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},1735326990745,false]</script>
12
+ <script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"1ab47290-de16-4dde-bcb8-21cd8741e18a",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
package/dist/module.d.mts CHANGED
@@ -1,60 +1,9 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
2
  import { HookResult } from '@nuxt/schema';
3
+ import { M as ModulePrivateOptionsExtend, b as ModuleOptionsExtend, c as ModuleOptions } from './shared/nuxt-i18n-micro.1d0c1665.mjs';
4
+ export { d as Getter, G as GlobalLocaleRoutes, a as Locale, L as LocaleCode, P as PluralFunc } from './shared/nuxt-i18n-micro.1d0c1665.mjs';
3
5
  export { PluginsInjections } from '../dist/runtime/plugins/01.plugin.js';
4
6
 
5
- type LocaleCode = string;
6
- interface Locale {
7
- code: LocaleCode;
8
- disabled?: boolean;
9
- iso?: string;
10
- dir?: 'ltr' | 'rtl' | 'auto';
11
- displayName?: string;
12
- baseUrl?: string;
13
- baseDefault?: boolean;
14
- }
15
- type Params = Record<string, string | number | boolean>;
16
- type Getter = (key: string, params?: Record<string, string | number | boolean>, defaultValue?: string) => unknown;
17
- type PluralFunc = (key: string, count: number, params: Params, locale: string, getter: Getter) => string | null;
18
- type GlobalLocaleRoutes = Record<string, Record<LocaleCode, string> | false | boolean> | null | undefined;
19
- type Strategies = 'no_prefix' | 'prefix_except_default' | 'prefix' | 'prefix_and_default';
20
- interface ModuleOptions {
21
- locales?: Locale[];
22
- meta?: boolean;
23
- strategy?: Strategies;
24
- metaBaseUrl?: string;
25
- define?: boolean;
26
- defaultLocale?: string;
27
- apiBaseUrl?: string;
28
- translationDir?: string;
29
- autoDetectLanguage?: boolean;
30
- autoDetectPath?: string;
31
- disableWatcher?: boolean;
32
- types?: boolean;
33
- includeDefaultLocaleRoute?: boolean;
34
- routesLocaleLinks?: {
35
- [key: string]: string;
36
- };
37
- plural?: string | PluralFunc;
38
- disablePageLocales?: boolean;
39
- fallbackLocale?: string;
40
- localeCookie?: string;
41
- debug?: boolean;
42
- globalLocaleRoutes?: GlobalLocaleRoutes;
43
- customRegexMatcher?: string | RegExp;
44
- }
45
- interface ModuleOptionsExtend extends ModuleOptions {
46
- dateBuild: number;
47
- hashMode: boolean;
48
- isSSG: boolean;
49
- apiBaseUrl: string;
50
- disablePageLocales: boolean;
51
- }
52
- interface ModulePrivateOptionsExtend extends ModuleOptions {
53
- rootDir: string;
54
- rootDirs: string[];
55
- debug: boolean;
56
- }
57
-
58
7
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
59
8
 
60
9
  interface ModuleHooks {
@@ -79,4 +28,4 @@ declare module '@nuxt/schema' {
79
28
  }
80
29
  }
81
30
 
82
- export { type Getter, type GlobalLocaleRoutes, type Locale, type LocaleCode, type ModuleHooks, type ModuleOptions, type PluralFunc, _default as default };
31
+ export { type ModuleHooks, ModuleOptions, _default as default };
package/dist/module.d.ts CHANGED
@@ -1,60 +1,9 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
2
  import { HookResult } from '@nuxt/schema';
3
+ import { M as ModulePrivateOptionsExtend, b as ModuleOptionsExtend, c as ModuleOptions } from './shared/nuxt-i18n-micro.1d0c1665.js';
4
+ export { d as Getter, G as GlobalLocaleRoutes, a as Locale, L as LocaleCode, P as PluralFunc } from './shared/nuxt-i18n-micro.1d0c1665.js';
3
5
  export { PluginsInjections } from '../dist/runtime/plugins/01.plugin.js';
4
6
 
5
- type LocaleCode = string;
6
- interface Locale {
7
- code: LocaleCode;
8
- disabled?: boolean;
9
- iso?: string;
10
- dir?: 'ltr' | 'rtl' | 'auto';
11
- displayName?: string;
12
- baseUrl?: string;
13
- baseDefault?: boolean;
14
- }
15
- type Params = Record<string, string | number | boolean>;
16
- type Getter = (key: string, params?: Record<string, string | number | boolean>, defaultValue?: string) => unknown;
17
- type PluralFunc = (key: string, count: number, params: Params, locale: string, getter: Getter) => string | null;
18
- type GlobalLocaleRoutes = Record<string, Record<LocaleCode, string> | false | boolean> | null | undefined;
19
- type Strategies = 'no_prefix' | 'prefix_except_default' | 'prefix' | 'prefix_and_default';
20
- interface ModuleOptions {
21
- locales?: Locale[];
22
- meta?: boolean;
23
- strategy?: Strategies;
24
- metaBaseUrl?: string;
25
- define?: boolean;
26
- defaultLocale?: string;
27
- apiBaseUrl?: string;
28
- translationDir?: string;
29
- autoDetectLanguage?: boolean;
30
- autoDetectPath?: string;
31
- disableWatcher?: boolean;
32
- types?: boolean;
33
- includeDefaultLocaleRoute?: boolean;
34
- routesLocaleLinks?: {
35
- [key: string]: string;
36
- };
37
- plural?: string | PluralFunc;
38
- disablePageLocales?: boolean;
39
- fallbackLocale?: string;
40
- localeCookie?: string;
41
- debug?: boolean;
42
- globalLocaleRoutes?: GlobalLocaleRoutes;
43
- customRegexMatcher?: string | RegExp;
44
- }
45
- interface ModuleOptionsExtend extends ModuleOptions {
46
- dateBuild: number;
47
- hashMode: boolean;
48
- isSSG: boolean;
49
- apiBaseUrl: string;
50
- disablePageLocales: boolean;
51
- }
52
- interface ModulePrivateOptionsExtend extends ModuleOptions {
53
- rootDir: string;
54
- rootDirs: string[];
55
- debug: boolean;
56
- }
57
-
58
7
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
59
8
 
60
9
  interface ModuleHooks {
@@ -79,4 +28,4 @@ declare module '@nuxt/schema' {
79
28
  }
80
29
  }
81
30
 
82
- export { type Getter, type GlobalLocaleRoutes, type Locale, type LocaleCode, type ModuleHooks, type ModuleOptions, type PluralFunc, _default as default };
31
+ export { type ModuleHooks, ModuleOptions, _default as default };
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-i18n-micro",
3
3
  "configKey": "i18n",
4
- "version": "1.52.0",
4
+ "version": "1.53.2",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "0.8.4",
7
7
  "unbuild": "2.0.0"
package/dist/module.mjs CHANGED
@@ -6,6 +6,7 @@ import { watch } from 'chokidar';
6
6
  import { fileURLToPath } from 'node:url';
7
7
  import { onDevToolsInitialized, extendServerRpc } from '@nuxt/devtools-kit';
8
8
  import sirv from 'sirv';
9
+ import { extractLocaleRoutes, normalizePath, isLocaleDefault, isPageRedirectOnly, cloneArray, buildRouteName, removeLeadingSlash, shouldAddLocalePrefix, buildFullPath } from './utils.mjs';
9
10
  import { isPrefixAndDefaultStrategy, isPrefixStrategy, isNoPrefixStrategy, withPrefixStrategy } from '../dist/runtime/helpers.js';
10
11
 
11
12
  const DEVTOOLS_UI_PORT = 3030;
@@ -110,63 +111,6 @@ function setupDevToolsUI(options, resolve2) {
110
111
  });
111
112
  }
112
113
 
113
- function extractLocaleRoutes(content, filePath) {
114
- const defineMatch = content.match(/\$?\bdefineI18nRoute\s*\(\s*\{[\s\S]*?\}\s*\)/);
115
- if (defineMatch) {
116
- const localeRoutesMatch = defineMatch[0].match(/localeRoutes:\s*(\{[\s\S]*?\})/);
117
- if (localeRoutesMatch && localeRoutesMatch[1]) {
118
- try {
119
- const parsedLocaleRoutes = Function('"use strict";return (' + localeRoutesMatch[1] + ")")();
120
- if (typeof parsedLocaleRoutes === "object" && parsedLocaleRoutes !== null) {
121
- if (validateDefineI18nRouteConfig(parsedLocaleRoutes)) {
122
- return parsedLocaleRoutes;
123
- }
124
- } else {
125
- console.error("localeRoutes found but it is not a valid object in file:", filePath);
126
- }
127
- } catch (error) {
128
- console.error("Failed to parse localeRoutes:", error, "in file:", filePath);
129
- }
130
- }
131
- }
132
- return null;
133
- }
134
- function validateDefineI18nRouteConfig(obj) {
135
- if (typeof obj !== "object")
136
- return false;
137
- for (const routeKey in obj.localeRoutes) {
138
- if (typeof obj.localeRoutes[routeKey] !== "string")
139
- return false;
140
- }
141
- return true;
142
- }
143
- const normalizePath = (routePath) => {
144
- if (!routePath) {
145
- return "";
146
- }
147
- const normalized = path.posix.normalize(routePath).replace(/\/+$/, "");
148
- return normalized === "." ? "" : normalized;
149
- };
150
- const cloneArray = (array) => [...array];
151
- const isPageRedirectOnly = (page) => !!(page.redirect && !page.file);
152
- const removeLeadingSlash = (routePath) => routePath.startsWith("/") ? routePath.slice(1) : routePath;
153
- const buildRouteName = (baseName, localeCode, isCustom) => isCustom ? `localized-${baseName}-${localeCode}` : `localized-${baseName}`;
154
- const shouldAddLocalePrefix = (locale, defaultLocale, addLocalePrefix, includeDefaultLocaleRoute) => addLocalePrefix && !(locale === defaultLocale.code && !includeDefaultLocaleRoute);
155
- const isLocaleDefault = (locale, defaultLocale, includeDefaultLocaleRoute) => {
156
- const localeCode = typeof locale === "string" ? locale : locale.code;
157
- return localeCode === defaultLocale.code && !includeDefaultLocaleRoute;
158
- };
159
- const buildFullPath = (locale, basePath, customRegex) => {
160
- const regexString = normalizeRegex(customRegex?.toString());
161
- const localeParam = Array.isArray(locale) ? regexString ? regexString : locale.join("|") : locale;
162
- return normalizePath(path.posix.join("/", `:locale(${localeParam})`, basePath));
163
- };
164
- const normalizeRegex = (toNorm) => {
165
- if (typeof toNorm === "undefined")
166
- return void 0;
167
- return toNorm.startsWith("/") && toNorm.endsWith("/") ? toNorm?.slice(1, -1) : toNorm;
168
- };
169
-
170
114
  const buildRouteNameFromRoute = (name, path2) => {
171
115
  return name ?? (path2 ?? "").replace(/[^a-z0-9]/gi, "-").replace(/^-+|-+$/g, "");
172
116
  };
@@ -1,4 +1,4 @@
1
- import type { RouteLocationNormalizedLoaded, RouteLocationRaw, RouteLocationResolved, RouteLocationResolvedGeneric } from 'vue-router';
1
+ import type { RouteLocationAsPath, RouteLocationAsRelative, RouteLocationAsString, RouteLocationNormalizedLoaded, RouteLocationRaw, RouteLocationResolved, RouteLocationResolvedGeneric } from 'vue-router';
2
2
  import type { Translation, Translations } from 'nuxt-i18n-micro-core';
3
3
  import type { Locale, I18nRouteParams, Params } from '../../types.js';
4
4
  declare const _default: import("#app").Plugin<{
@@ -20,8 +20,8 @@ declare const _default: import("#app").Plugin<{
20
20
  switchLocalePath: (toLocale: string) => string;
21
21
  switchLocale: (toLocale: string) => void;
22
22
  switchRoute: (route: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric | string, toLocale?: string) => void;
23
- localeRoute: (to: RouteLocationRaw, locale?: string) => RouteLocationResolved;
24
- localePath: (to: RouteLocationRaw, locale?: string) => string;
23
+ localeRoute: (to: RouteLocationAsString | RouteLocationAsRelative | RouteLocationAsPath, locale?: string) => RouteLocationResolved;
24
+ localePath: (to: RouteLocationAsString | RouteLocationAsRelative | RouteLocationAsPath, locale?: string) => string;
25
25
  setI18nRouteParams: (value: I18nRouteParams) => I18nRouteParams;
26
26
  }> & import("#app").ObjectPlugin<{
27
27
  i18n: undefined;
@@ -42,8 +42,8 @@ declare const _default: import("#app").Plugin<{
42
42
  switchLocalePath: (toLocale: string) => string;
43
43
  switchLocale: (toLocale: string) => void;
44
44
  switchRoute: (route: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric | string, toLocale?: string) => void;
45
- localeRoute: (to: RouteLocationRaw, locale?: string) => RouteLocationResolved;
46
- localePath: (to: RouteLocationRaw, locale?: string) => string;
45
+ localeRoute: (to: RouteLocationAsString | RouteLocationAsRelative | RouteLocationAsPath, locale?: string) => RouteLocationResolved;
46
+ localePath: (to: RouteLocationAsString | RouteLocationAsRelative | RouteLocationAsPath, locale?: string) => string;
47
47
  setI18nRouteParams: (value: I18nRouteParams) => I18nRouteParams;
48
48
  }>;
49
49
  export default _default;
@@ -64,7 +64,7 @@ export interface PluginsInjections {
64
64
  $switchLocalePath: (locale: string) => string;
65
65
  $switchLocale: (locale: string) => void;
66
66
  $switchRoute: (route: RouteLocationNormalizedLoaded | RouteLocationResolvedGeneric | string, toLocale?: string) => void;
67
- $localeRoute: (to: RouteLocationRaw, locale?: string) => RouteLocationResolved;
68
- $localePath: (to: RouteLocationRaw, locale?: string) => string;
67
+ $localeRoute: (to: RouteLocationAsString | RouteLocationAsRelative | RouteLocationAsPath, locale?: string) => RouteLocationResolved;
68
+ $localePath: (to: RouteLocationAsString | RouteLocationAsRelative | RouteLocationAsPath, locale?: string) => string;
69
69
  $setI18nRouteParams: (value: I18nRouteParams) => I18nRouteParams;
70
70
  }
@@ -0,0 +1,54 @@
1
+ type LocaleCode = string;
2
+ interface Locale {
3
+ code: LocaleCode;
4
+ disabled?: boolean;
5
+ iso?: string;
6
+ dir?: 'ltr' | 'rtl' | 'auto';
7
+ displayName?: string;
8
+ baseUrl?: string;
9
+ baseDefault?: boolean;
10
+ }
11
+ type Params = Record<string, string | number | boolean>;
12
+ type Getter = (key: string, params?: Record<string, string | number | boolean>, defaultValue?: string) => unknown;
13
+ type PluralFunc = (key: string, count: number, params: Params, locale: string, getter: Getter) => string | null;
14
+ type GlobalLocaleRoutes = Record<string, Record<LocaleCode, string> | false | boolean> | null | undefined;
15
+ type Strategies = 'no_prefix' | 'prefix_except_default' | 'prefix' | 'prefix_and_default';
16
+ interface ModuleOptions {
17
+ locales?: Locale[];
18
+ meta?: boolean;
19
+ strategy?: Strategies;
20
+ metaBaseUrl?: string;
21
+ define?: boolean;
22
+ defaultLocale?: string;
23
+ apiBaseUrl?: string;
24
+ translationDir?: string;
25
+ autoDetectLanguage?: boolean;
26
+ autoDetectPath?: string;
27
+ disableWatcher?: boolean;
28
+ types?: boolean;
29
+ includeDefaultLocaleRoute?: boolean;
30
+ routesLocaleLinks?: {
31
+ [key: string]: string;
32
+ };
33
+ plural?: string | PluralFunc;
34
+ disablePageLocales?: boolean;
35
+ fallbackLocale?: string;
36
+ localeCookie?: string;
37
+ debug?: boolean;
38
+ globalLocaleRoutes?: GlobalLocaleRoutes;
39
+ customRegexMatcher?: string | RegExp;
40
+ }
41
+ interface ModuleOptionsExtend extends ModuleOptions {
42
+ dateBuild: number;
43
+ hashMode: boolean;
44
+ isSSG: boolean;
45
+ apiBaseUrl: string;
46
+ disablePageLocales: boolean;
47
+ }
48
+ interface ModulePrivateOptionsExtend extends ModuleOptions {
49
+ rootDir: string;
50
+ rootDirs: string[];
51
+ debug: boolean;
52
+ }
53
+
54
+ export type { GlobalLocaleRoutes as G, LocaleCode as L, ModulePrivateOptionsExtend as M, PluralFunc as P, Locale as a, ModuleOptionsExtend as b, ModuleOptions as c, Getter as d };
@@ -0,0 +1,54 @@
1
+ type LocaleCode = string;
2
+ interface Locale {
3
+ code: LocaleCode;
4
+ disabled?: boolean;
5
+ iso?: string;
6
+ dir?: 'ltr' | 'rtl' | 'auto';
7
+ displayName?: string;
8
+ baseUrl?: string;
9
+ baseDefault?: boolean;
10
+ }
11
+ type Params = Record<string, string | number | boolean>;
12
+ type Getter = (key: string, params?: Record<string, string | number | boolean>, defaultValue?: string) => unknown;
13
+ type PluralFunc = (key: string, count: number, params: Params, locale: string, getter: Getter) => string | null;
14
+ type GlobalLocaleRoutes = Record<string, Record<LocaleCode, string> | false | boolean> | null | undefined;
15
+ type Strategies = 'no_prefix' | 'prefix_except_default' | 'prefix' | 'prefix_and_default';
16
+ interface ModuleOptions {
17
+ locales?: Locale[];
18
+ meta?: boolean;
19
+ strategy?: Strategies;
20
+ metaBaseUrl?: string;
21
+ define?: boolean;
22
+ defaultLocale?: string;
23
+ apiBaseUrl?: string;
24
+ translationDir?: string;
25
+ autoDetectLanguage?: boolean;
26
+ autoDetectPath?: string;
27
+ disableWatcher?: boolean;
28
+ types?: boolean;
29
+ includeDefaultLocaleRoute?: boolean;
30
+ routesLocaleLinks?: {
31
+ [key: string]: string;
32
+ };
33
+ plural?: string | PluralFunc;
34
+ disablePageLocales?: boolean;
35
+ fallbackLocale?: string;
36
+ localeCookie?: string;
37
+ debug?: boolean;
38
+ globalLocaleRoutes?: GlobalLocaleRoutes;
39
+ customRegexMatcher?: string | RegExp;
40
+ }
41
+ interface ModuleOptionsExtend extends ModuleOptions {
42
+ dateBuild: number;
43
+ hashMode: boolean;
44
+ isSSG: boolean;
45
+ apiBaseUrl: string;
46
+ disablePageLocales: boolean;
47
+ }
48
+ interface ModulePrivateOptionsExtend extends ModuleOptions {
49
+ rootDir: string;
50
+ rootDirs: string[];
51
+ debug: boolean;
52
+ }
53
+
54
+ export type { GlobalLocaleRoutes as G, LocaleCode as L, ModulePrivateOptionsExtend as M, PluralFunc as P, Locale as a, ModuleOptionsExtend as b, ModuleOptions as c, Getter as d };
package/dist/types.d.mts CHANGED
@@ -4,4 +4,4 @@ declare module '@nuxt/schema' {
4
4
  interface NuxtHooks extends ModuleHooks {}
5
5
  }
6
6
 
7
- export { type PluginsInjections } from './module.js'
7
+ export { type Getter, type GlobalLocaleRoutes, type Locale, type LocaleCode, type PluralFunc } from './module.js'
package/dist/types.d.ts CHANGED
@@ -4,4 +4,4 @@ declare module '@nuxt/schema' {
4
4
  interface NuxtHooks extends ModuleHooks {}
5
5
  }
6
6
 
7
- export { type PluginsInjections } from './module'
7
+ export { type Getter, type GlobalLocaleRoutes, type Locale, type LocaleCode, type PluralFunc } from './module'
@@ -0,0 +1,15 @@
1
+ import { NuxtPage } from '@nuxt/schema';
2
+ import { L as LocaleCode, a as Locale } from './shared/nuxt-i18n-micro.1d0c1665.mjs';
3
+
4
+ declare function extractLocaleRoutes(content: string, filePath: string): Record<string, string> | null;
5
+ declare function validateDefineI18nRouteConfig(obj: Record<LocaleCode, Record<string, string>>): boolean;
6
+ declare const normalizePath: (routePath: string) => string;
7
+ declare const cloneArray: <T>(array: T[]) => T[];
8
+ declare const isPageRedirectOnly: (page: NuxtPage) => boolean;
9
+ declare const removeLeadingSlash: (routePath: string) => string;
10
+ declare const buildRouteName: (baseName: string, localeCode: string, isCustom: boolean) => string;
11
+ declare const shouldAddLocalePrefix: (locale: string, defaultLocale: Locale, addLocalePrefix: boolean, includeDefaultLocaleRoute: boolean) => boolean;
12
+ declare const isLocaleDefault: (locale: string | Locale, defaultLocale: Locale, includeDefaultLocaleRoute: boolean) => boolean;
13
+ declare const buildFullPath: (locale: string | string[], basePath: string, customRegex?: string | RegExp) => string;
14
+
15
+ export { buildFullPath, buildRouteName, cloneArray, extractLocaleRoutes, isLocaleDefault, isPageRedirectOnly, normalizePath, removeLeadingSlash, shouldAddLocalePrefix, validateDefineI18nRouteConfig };
@@ -0,0 +1,15 @@
1
+ import { NuxtPage } from '@nuxt/schema';
2
+ import { L as LocaleCode, a as Locale } from './shared/nuxt-i18n-micro.1d0c1665.js';
3
+
4
+ declare function extractLocaleRoutes(content: string, filePath: string): Record<string, string> | null;
5
+ declare function validateDefineI18nRouteConfig(obj: Record<LocaleCode, Record<string, string>>): boolean;
6
+ declare const normalizePath: (routePath: string) => string;
7
+ declare const cloneArray: <T>(array: T[]) => T[];
8
+ declare const isPageRedirectOnly: (page: NuxtPage) => boolean;
9
+ declare const removeLeadingSlash: (routePath: string) => string;
10
+ declare const buildRouteName: (baseName: string, localeCode: string, isCustom: boolean) => string;
11
+ declare const shouldAddLocalePrefix: (locale: string, defaultLocale: Locale, addLocalePrefix: boolean, includeDefaultLocaleRoute: boolean) => boolean;
12
+ declare const isLocaleDefault: (locale: string | Locale, defaultLocale: Locale, includeDefaultLocaleRoute: boolean) => boolean;
13
+ declare const buildFullPath: (locale: string | string[], basePath: string, customRegex?: string | RegExp) => string;
14
+
15
+ export { buildFullPath, buildRouteName, cloneArray, extractLocaleRoutes, isLocaleDefault, isPageRedirectOnly, normalizePath, removeLeadingSlash, shouldAddLocalePrefix, validateDefineI18nRouteConfig };
package/dist/utils.mjs ADDED
@@ -0,0 +1,60 @@
1
+ import path from 'node:path';
2
+
3
+ function extractLocaleRoutes(content, filePath) {
4
+ const defineMatch = content.match(/\$?\bdefineI18nRoute\s*\(\s*\{[\s\S]*?\}\s*\)/);
5
+ if (defineMatch) {
6
+ const localeRoutesMatch = defineMatch[0].match(/localeRoutes:\s*(\{[\s\S]*?\})/);
7
+ if (localeRoutesMatch && localeRoutesMatch[1]) {
8
+ try {
9
+ const parsedLocaleRoutes = Function('"use strict";return (' + localeRoutesMatch[1] + ")")();
10
+ if (typeof parsedLocaleRoutes === "object" && parsedLocaleRoutes !== null) {
11
+ if (validateDefineI18nRouteConfig(parsedLocaleRoutes)) {
12
+ return parsedLocaleRoutes;
13
+ }
14
+ } else {
15
+ console.error("localeRoutes found but it is not a valid object in file:", filePath);
16
+ }
17
+ } catch (error) {
18
+ console.error("Failed to parse localeRoutes:", error, "in file:", filePath);
19
+ }
20
+ }
21
+ }
22
+ return null;
23
+ }
24
+ function validateDefineI18nRouteConfig(obj) {
25
+ if (typeof obj !== "object")
26
+ return false;
27
+ for (const routeKey in obj.localeRoutes) {
28
+ if (typeof obj.localeRoutes[routeKey] !== "string")
29
+ return false;
30
+ }
31
+ return true;
32
+ }
33
+ const normalizePath = (routePath) => {
34
+ if (!routePath) {
35
+ return "";
36
+ }
37
+ const normalized = path.posix.normalize(routePath).replace(/\/+$/, "");
38
+ return normalized === "." ? "" : normalized;
39
+ };
40
+ const cloneArray = (array) => [...array];
41
+ const isPageRedirectOnly = (page) => !!(page.redirect && !page.file);
42
+ const removeLeadingSlash = (routePath) => routePath.startsWith("/") ? routePath.slice(1) : routePath;
43
+ const buildRouteName = (baseName, localeCode, isCustom) => isCustom ? `localized-${baseName}-${localeCode}` : `localized-${baseName}`;
44
+ const shouldAddLocalePrefix = (locale, defaultLocale, addLocalePrefix, includeDefaultLocaleRoute) => addLocalePrefix && !(locale === defaultLocale.code && !includeDefaultLocaleRoute);
45
+ const isLocaleDefault = (locale, defaultLocale, includeDefaultLocaleRoute) => {
46
+ const localeCode = typeof locale === "string" ? locale : locale.code;
47
+ return localeCode === defaultLocale.code && !includeDefaultLocaleRoute;
48
+ };
49
+ const buildFullPath = (locale, basePath, customRegex) => {
50
+ const regexString = normalizeRegex(customRegex?.toString());
51
+ const localeParam = Array.isArray(locale) ? regexString ? regexString : locale.join("|") : locale;
52
+ return normalizePath(path.posix.join("/", `:locale(${localeParam})`, basePath));
53
+ };
54
+ const normalizeRegex = (toNorm) => {
55
+ if (typeof toNorm === "undefined")
56
+ return void 0;
57
+ return toNorm.startsWith("/") && toNorm.endsWith("/") ? toNorm?.slice(1, -1) : toNorm;
58
+ };
59
+
60
+ export { buildFullPath, 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.52.0",
3
+ "version": "1.53.2",
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",
@@ -29,12 +29,19 @@
29
29
  "exports": {
30
30
  ".": {
31
31
  "types": "./dist/types.d.ts",
32
- "import": "./dist/module.mjs",
33
- "require": "./dist/module.cjs"
34
- }
32
+ "default": "./dist/module.mjs"
33
+ },
34
+ "./utils": "./dist/utils.mjs"
35
35
  },
36
36
  "main": "./dist/module.cjs",
37
- "types": "./dist/types.d.ts",
37
+ "typesVersions": {
38
+ "*": {
39
+ "*": [
40
+ "./dist/*",
41
+ "./*"
42
+ ]
43
+ }
44
+ },
38
45
  "files": [
39
46
  "dist",
40
47
  "internals.d.ts"
@@ -52,7 +59,7 @@
52
59
  "@types/jest": "^29.5.14",
53
60
  "@nuxt/devtools": "^1.6.4",
54
61
  "@nuxt/devtools-ui-kit": "^1.6.4",
55
- "@nuxt/eslint-config": "0.7.3",
62
+ "@nuxt/eslint-config": "0.7.4",
56
63
  "@nuxt/module-builder": "^0.8.4",
57
64
  "@nuxt/schema": "3.13.2",
58
65
  "@nuxt/test-utils": "^3.15.1",
@@ -76,6 +83,11 @@
76
83
  "client",
77
84
  "test/fixtures/**/*"
78
85
  ],
86
+ "build": {
87
+ "entries": [
88
+ "./src/utils"
89
+ ]
90
+ },
79
91
  "scripts": {
80
92
  "dev": "nuxi dev playground",
81
93
  "dev:build": "nuxi build playground",
@@ -1 +0,0 @@
1
- {"id":"3086ca3a-1f67-491b-a81d-22fa2fedfc38","timestamp":1735030484548,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}