nuxt-i18n-micro 1.51.0 → 1.53.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/dist/client/200.html +2 -2
- package/dist/client/404.html +2 -2
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/33b6c2af-a908-4038-ae84-385d111f4c3c.json +1 -0
- package/dist/client/index.html +2 -2
- package/dist/module.d.mts +3 -54
- package/dist/module.d.ts +3 -54
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -63
- package/dist/runtime/server/middleware/i18n-loader.js +9 -0
- package/dist/shared/nuxt-i18n-micro.1d0c1665.d.mts +54 -0
- package/dist/shared/nuxt-i18n-micro.1d0c1665.d.ts +54 -0
- package/dist/types.d.mts +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/utils.d.mts +15 -0
- package/dist/utils.d.ts +15 -0
- package/dist/utils.mjs +60 -0
- package/package.json +18 -6
- package/dist/client/_nuxt/builds/meta/396cb1f6-6d31-4c38-9706-881150be01b6.json +0 -1
package/dist/client/200.html
CHANGED
|
@@ -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},
|
|
12
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"
|
|
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},1735194667448,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"33b6c2af-a908-4038-ae84-385d111f4c3c",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/client/404.html
CHANGED
|
@@ -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},
|
|
12
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"
|
|
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},1735194667449,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"33b6c2af-a908-4038-ae84-385d111f4c3c",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"33b6c2af-a908-4038-ae84-385d111f4c3c","timestamp":1735194660704}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"33b6c2af-a908-4038-ae84-385d111f4c3c","timestamp":1735194660704,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|
package/dist/client/index.html
CHANGED
|
@@ -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},
|
|
12
|
-
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"
|
|
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},1735194667449,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"33b6c2af-a908-4038-ae84-385d111f4c3c",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
|
|
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
|
|
31
|
+
export { type ModuleHooks, ModuleOptions, _default as default };
|
package/dist/module.json
CHANGED
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
|
};
|
|
@@ -481,12 +425,6 @@ const module = defineNuxtModule({
|
|
|
481
425
|
if (isCloudflarePages && !isPrefixStrategy(options.strategy)) {
|
|
482
426
|
throw new Error('Nuxt-i18n-micro: "includeDefaultLocaleRoute" must be set to true when using Cloudflare Pages.');
|
|
483
427
|
}
|
|
484
|
-
try {
|
|
485
|
-
const storagePahh = path.join(nuxt.options.rootDir, "./server/assets");
|
|
486
|
-
fs__default.rmdirSync(storagePahh);
|
|
487
|
-
logger.log(`Cleanup storage: ${storagePahh}`);
|
|
488
|
-
} catch {
|
|
489
|
-
}
|
|
490
428
|
const resolver = createResolver(import.meta.url);
|
|
491
429
|
const rootDirs = nuxt.options._layers.map((layer) => layer.config.rootDir).reverse();
|
|
492
430
|
const localeManager = new LocaleManager(options, rootDirs);
|
|
@@ -2,6 +2,7 @@ import { resolve } from "node:path";
|
|
|
2
2
|
import { readFile } from "node:fs/promises";
|
|
3
3
|
import { defineEventHandler } from "h3";
|
|
4
4
|
import { useRuntimeConfig, createError, useStorage } from "#imports";
|
|
5
|
+
let storageInit = false;
|
|
5
6
|
function deepMerge(target, source) {
|
|
6
7
|
for (const key of Object.keys(source)) {
|
|
7
8
|
if (key === "__proto__" || key === "constructor") {
|
|
@@ -51,6 +52,14 @@ export default defineEventHandler(async (event) => {
|
|
|
51
52
|
});
|
|
52
53
|
let translations = {};
|
|
53
54
|
const serverStorage = await useStorage("assets:server");
|
|
55
|
+
if (!storageInit) {
|
|
56
|
+
if (debug) {
|
|
57
|
+
console.log("[nuxt-i18n-micro] clear storage cache");
|
|
58
|
+
}
|
|
59
|
+
const handlerKeys = await serverStorage.getKeys();
|
|
60
|
+
await Promise.all(handlerKeys.map((element) => serverStorage.removeItem(element)));
|
|
61
|
+
storageInit = true;
|
|
62
|
+
}
|
|
54
63
|
for (const { translationPath, name } of paths) {
|
|
55
64
|
try {
|
|
56
65
|
if (debug) {
|
|
@@ -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
package/dist/types.d.ts
CHANGED
package/dist/utils.d.mts
ADDED
|
@@ -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 };
|
package/dist/utils.d.ts
ADDED
|
@@ -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.
|
|
3
|
+
"version": "1.53.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",
|
|
@@ -29,12 +29,19 @@
|
|
|
29
29
|
"exports": {
|
|
30
30
|
".": {
|
|
31
31
|
"types": "./dist/types.d.ts",
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
"default": "./dist/module.mjs"
|
|
33
|
+
},
|
|
34
|
+
"./utils": "./dist/utils.mjs"
|
|
35
35
|
},
|
|
36
36
|
"main": "./dist/module.cjs",
|
|
37
|
-
"
|
|
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.
|
|
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":"396cb1f6-6d31-4c38-9706-881150be01b6","timestamp":1734945126942,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|