nuxt-i18n-micro 1.84.1 → 1.86.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/9b03c3ea-26a1-4619-b39e-b42f797680ba.json +1 -0
- package/dist/client/index.html +2 -2
- package/dist/module.json +1 -1
- package/dist/module.mjs +110 -80
- package/dist/runtime/plugins/03.define.js +17 -61
- package/dist/runtime/plugins/06.redirect.d.ts +2 -0
- package/dist/runtime/plugins/06.redirect.js +38 -0
- package/dist/utils.d.mts +1 -1
- package/dist/utils.d.ts +1 -1
- package/dist/utils.mjs +1 -1
- package/package.json +3 -3
- package/dist/client/_nuxt/builds/meta/f7c3d9d2-1f61-4a23-92e5-e82bc6d21f4d.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/BBbCCCx2.js">
|
|
9
9
|
<link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.BRj5A2lo.css">
|
|
10
10
|
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/CfVvufsh.js">
|
|
11
|
-
<script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/MjlAM4Ld.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/MjlAM4Ld.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},1745997671706,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"9b03c3ea-26a1-4619-b39e-b42f797680ba",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/BBbCCCx2.js">
|
|
9
9
|
<link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.BRj5A2lo.css">
|
|
10
10
|
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/CfVvufsh.js">
|
|
11
|
-
<script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/MjlAM4Ld.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/MjlAM4Ld.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},1745997671707,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"9b03c3ea-26a1-4619-b39e-b42f797680ba",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"9b03c3ea-26a1-4619-b39e-b42f797680ba","timestamp":1745997666200}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"9b03c3ea-26a1-4619-b39e-b42f797680ba","timestamp":1745997666200,"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/BBbCCCx2.js">
|
|
9
9
|
<link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.BRj5A2lo.css">
|
|
10
10
|
<link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/CfVvufsh.js">
|
|
11
|
-
<script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/MjlAM4Ld.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/MjlAM4Ld.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},1745997671707,false]</script>
|
|
12
|
+
<script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"9b03c3ea-26a1-4619-b39e-b42f797680ba",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script></body></html>
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -7,7 +7,7 @@ import { isPrefixAndDefaultStrategy, isPrefixStrategy, isNoPrefixStrategy, isPre
|
|
|
7
7
|
import { fileURLToPath } from 'node:url';
|
|
8
8
|
import { onDevToolsInitialized, extendServerRpc } from '@nuxt/devtools-kit';
|
|
9
9
|
import sirv from 'sirv';
|
|
10
|
-
import { extractLocaleRoutes, normalizePath, isLocaleDefault,
|
|
10
|
+
import { extractLocaleRoutes, normalizePath, isLocaleDefault, cloneArray, isPageRedirectOnly, removeLeadingSlash, shouldAddLocalePrefix, buildFullPath, buildRouteName, buildFullPathNoPrefix } from './utils.mjs';
|
|
11
11
|
|
|
12
12
|
const DEVTOOLS_UI_PORT = 3030;
|
|
13
13
|
const DEVTOOLS_UI_ROUTE = "/__nuxt-i18n-micro";
|
|
@@ -135,23 +135,28 @@ class PageManager {
|
|
|
135
135
|
computeActiveLocaleCodes() {
|
|
136
136
|
return this.locales.filter((locale) => locale.code !== this.defaultLocale.code || isPrefixAndDefaultStrategy(this.strategy) || isPrefixStrategy(this.strategy)).map((locale) => locale.code);
|
|
137
137
|
}
|
|
138
|
+
// private isAlreadyLocalized(p: string) {
|
|
139
|
+
// const codes = this.locales.map(l => l.code).join('|') // en|de|ru…
|
|
140
|
+
// return p.startsWith('/:locale(') // динамический префикс
|
|
141
|
+
// || new RegExp(`^/(${codes})(/|$)`).test(p) // статический /de/…
|
|
142
|
+
// }
|
|
138
143
|
extendPages(pages, customRegex, isCloudflarePages) {
|
|
139
144
|
this.localizedPaths = this.extractLocalizedPaths(pages);
|
|
140
145
|
const additionalRoutes = [];
|
|
141
|
-
|
|
146
|
+
for (const page of [...pages]) {
|
|
142
147
|
if (!page.name && page.file?.endsWith(".vue")) {
|
|
143
148
|
console.warn(`[nuxt-i18n-next] Page name is missing for the file: ${page.file}`);
|
|
144
149
|
}
|
|
145
|
-
const customRoute = this.globalLocaleRoutes[page.name ?? ""]
|
|
150
|
+
const customRoute = this.globalLocaleRoutes[page.name ?? ""];
|
|
146
151
|
if (customRoute === false) {
|
|
147
|
-
|
|
152
|
+
continue;
|
|
148
153
|
}
|
|
149
|
-
if (
|
|
154
|
+
if (typeof customRoute === "object" && customRoute !== null) {
|
|
150
155
|
this.addCustomGlobalLocalizedRoutes(page, customRoute, additionalRoutes, customRegex);
|
|
151
156
|
} else {
|
|
152
157
|
this.localizePage(page, additionalRoutes, customRegex);
|
|
153
158
|
}
|
|
154
|
-
}
|
|
159
|
+
}
|
|
155
160
|
if (isPrefixStrategy(this.strategy) && !isCloudflarePages) {
|
|
156
161
|
for (let i = pages.length - 1; i >= 0; i--) {
|
|
157
162
|
const page = pages[i];
|
|
@@ -194,28 +199,30 @@ class PageManager {
|
|
|
194
199
|
addCustomGlobalLocalizedRoutes(page, customRoutePaths, additionalRoutes, customRegex) {
|
|
195
200
|
this.locales.forEach((locale) => {
|
|
196
201
|
const customPath = customRoutePaths[locale.code];
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
if (newRoute) {
|
|
203
|
-
additionalRoutes.push(newRoute);
|
|
204
|
-
if (this.noPrefixRedirect && isNoPrefixStrategy(this.strategy))
|
|
205
|
-
page.redirect = newRoute.path;
|
|
206
|
-
}
|
|
207
|
-
} else {
|
|
208
|
-
if (isDefaultLocale) {
|
|
209
|
-
page.path = normalizePath(customPath);
|
|
210
|
-
} else {
|
|
211
|
-
const newRoute = this.createLocalizedRoute(page, [locale.code], page.children ?? [], true, customPath, customRegex);
|
|
212
|
-
if (newRoute)
|
|
202
|
+
const isDefaultLocale = isLocaleDefault(locale, this.defaultLocale, isPrefixStrategy(this.strategy) || isPrefixAndDefaultStrategy(this.strategy));
|
|
203
|
+
if (customPath) {
|
|
204
|
+
if (isNoPrefixStrategy(this.strategy)) {
|
|
205
|
+
const newRoute = this.createLocalizedRoute(page, [locale.code], page.children ?? [], true, customPath, customRegex, false, locale.code);
|
|
206
|
+
if (newRoute) {
|
|
213
207
|
additionalRoutes.push(newRoute);
|
|
208
|
+
if (this.noPrefixRedirect)
|
|
209
|
+
page.redirect = newRoute.path;
|
|
210
|
+
}
|
|
211
|
+
} else {
|
|
212
|
+
if (isDefaultLocale) {
|
|
213
|
+
page.path = normalizePath(customPath);
|
|
214
|
+
} else {
|
|
215
|
+
const newRoute = this.createLocalizedRoute(page, [locale.code], page.children ?? [], true, customPath, customRegex, false, locale.code);
|
|
216
|
+
if (newRoute)
|
|
217
|
+
additionalRoutes.push(newRoute);
|
|
218
|
+
}
|
|
214
219
|
}
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
220
|
+
} else {
|
|
221
|
+
const localeCodes = [locale.code];
|
|
222
|
+
const originalChildren = cloneArray(page.children ?? []);
|
|
223
|
+
const newRoute = this.createLocalizedRoute(page, localeCodes, originalChildren, false, "", customRegex, false, locale.code);
|
|
224
|
+
if (newRoute) {
|
|
225
|
+
additionalRoutes.push(newRoute);
|
|
219
226
|
}
|
|
220
227
|
}
|
|
221
228
|
});
|
|
@@ -227,7 +234,7 @@ class PageManager {
|
|
|
227
234
|
const normalizedFullPath = normalizePath(page.path);
|
|
228
235
|
const localeCodesWithoutCustomPaths = this.filterLocaleCodesWithoutCustomPaths(normalizedFullPath);
|
|
229
236
|
if (localeCodesWithoutCustomPaths.length) {
|
|
230
|
-
const newRoute = this.createLocalizedRoute(page, localeCodesWithoutCustomPaths, originalChildren, false, "", customRegex);
|
|
237
|
+
const newRoute = this.createLocalizedRoute(page, localeCodesWithoutCustomPaths, originalChildren, false, "", customRegex, false, true);
|
|
231
238
|
if (newRoute)
|
|
232
239
|
additionalRoutes.push(newRoute);
|
|
233
240
|
}
|
|
@@ -245,10 +252,17 @@ class PageManager {
|
|
|
245
252
|
if (defaultLocalePath) {
|
|
246
253
|
page.path = normalizePath(defaultLocalePath);
|
|
247
254
|
}
|
|
248
|
-
const currentChildren = page.children ? [...page.children] : [];
|
|
249
255
|
if (originalChildren.length) {
|
|
250
256
|
const newName = normalizePath(path.posix.join("/", buildRouteNameFromRoute(page.name, page.path)));
|
|
251
|
-
const
|
|
257
|
+
const currentChildren = page.children ? [...page.children] : [];
|
|
258
|
+
const localizedChildren = this.createLocalizedChildren(
|
|
259
|
+
originalChildren,
|
|
260
|
+
newName,
|
|
261
|
+
[this.defaultLocale.code],
|
|
262
|
+
true,
|
|
263
|
+
false,
|
|
264
|
+
false
|
|
265
|
+
);
|
|
252
266
|
const childrenMap = new Map(currentChildren.map((child) => [child.name, child]));
|
|
253
267
|
localizedChildren.forEach((localizedChild) => {
|
|
254
268
|
if (childrenMap.has(localizedChild.name)) {
|
|
@@ -263,10 +277,6 @@ class PageManager {
|
|
|
263
277
|
page.children = currentChildren;
|
|
264
278
|
}
|
|
265
279
|
}
|
|
266
|
-
mergeChildren(originalChildren, parentPath, localeCodes) {
|
|
267
|
-
const localizedChildren = this.createLocalizedChildren(originalChildren, parentPath, localeCodes, false);
|
|
268
|
-
return [...originalChildren, ...localizedChildren];
|
|
269
|
-
}
|
|
270
280
|
addCustomLocalizedRoutes(page, fullPath, originalChildren, additionalRoutes, customRegex) {
|
|
271
281
|
this.locales.forEach((locale) => {
|
|
272
282
|
const customPath = this.localizedPaths[fullPath]?.[locale.code];
|
|
@@ -276,18 +286,18 @@ class PageManager {
|
|
|
276
286
|
if (isDefaultLocale) {
|
|
277
287
|
page.children = this.createLocalizedChildren(originalChildren, "", [locale.code], false);
|
|
278
288
|
} else {
|
|
279
|
-
const newRoute = this.createLocalizedRoute(page, [locale.code], originalChildren, true, customPath, customRegex);
|
|
289
|
+
const newRoute = this.createLocalizedRoute(page, [locale.code], originalChildren, true, customPath, customRegex, false, locale.code);
|
|
280
290
|
if (newRoute)
|
|
281
291
|
additionalRoutes.push(newRoute);
|
|
282
292
|
}
|
|
283
293
|
if (isPrefixAndDefaultStrategy(this.strategy) && locale === this.defaultLocale) {
|
|
284
|
-
const newRoute = this.createLocalizedRoute(page, [locale.code], originalChildren, true, customPath, customRegex, true);
|
|
294
|
+
const newRoute = this.createLocalizedRoute(page, [locale.code], originalChildren, true, customPath, customRegex, true, locale.code);
|
|
285
295
|
if (newRoute)
|
|
286
296
|
additionalRoutes.push(newRoute);
|
|
287
297
|
}
|
|
288
298
|
});
|
|
289
299
|
}
|
|
290
|
-
createLocalizedChildren(routes, parentPath, localeCodes, modifyName = true, addLocalePrefix = false,
|
|
300
|
+
createLocalizedChildren(routes, parentPath, localeCodes, modifyName = true, addLocalePrefix = false, parentLocale = false, localizedParentPaths = {}) {
|
|
291
301
|
return routes.flatMap(
|
|
292
302
|
(route) => this.createLocalizedVariants(
|
|
293
303
|
route,
|
|
@@ -295,95 +305,106 @@ class PageManager {
|
|
|
295
305
|
localeCodes,
|
|
296
306
|
modifyName,
|
|
297
307
|
addLocalePrefix,
|
|
298
|
-
|
|
308
|
+
parentLocale,
|
|
299
309
|
localizedParentPaths
|
|
300
310
|
)
|
|
301
311
|
);
|
|
302
312
|
}
|
|
303
|
-
createLocalizedVariants(route, parentPath, localeCodes, modifyName, addLocalePrefix,
|
|
313
|
+
createLocalizedVariants(route, parentPath, localeCodes, modifyName, addLocalePrefix, parentLocale = false, localizedParentPaths) {
|
|
304
314
|
const routePath = normalizePath(route.path);
|
|
305
|
-
const isDynamic = /(?:^|\/):/.test(routePath);
|
|
306
315
|
const fullPath = normalizePath(path.posix.join(parentPath, routePath));
|
|
307
|
-
const customLocalePaths = this.localizedPaths[fullPath];
|
|
308
|
-
|
|
316
|
+
const customLocalePaths = this.localizedPaths[fullPath] ?? this.localizedPaths[normalizePath(route.path)];
|
|
317
|
+
const isCustomLocalized = !!customLocalePaths;
|
|
318
|
+
const result = [];
|
|
319
|
+
if (!isCustomLocalized) {
|
|
320
|
+
const finalPathForRoute = removeLeadingSlash(routePath);
|
|
309
321
|
const localizedChildren = this.createLocalizedChildren(
|
|
310
|
-
route.children ?? [],
|
|
311
|
-
|
|
322
|
+
cloneArray(route.children ?? []),
|
|
323
|
+
path.posix.join(parentPath, routePath),
|
|
312
324
|
localeCodes,
|
|
313
325
|
modifyName,
|
|
314
326
|
addLocalePrefix,
|
|
315
|
-
|
|
327
|
+
parentLocale,
|
|
316
328
|
localizedParentPaths
|
|
317
329
|
);
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
];
|
|
330
|
+
const newName = this.buildChildRouteName(route.name, parentLocale);
|
|
331
|
+
result.push({
|
|
332
|
+
...route,
|
|
333
|
+
name: newName,
|
|
334
|
+
path: finalPathForRoute,
|
|
335
|
+
children: localizedChildren
|
|
336
|
+
});
|
|
337
|
+
return result;
|
|
327
338
|
}
|
|
328
|
-
const result = [];
|
|
329
339
|
for (const locale of localeCodes) {
|
|
330
|
-
const
|
|
331
|
-
const
|
|
340
|
+
const parentLocalizedPath = localizedParentPaths?.[locale];
|
|
341
|
+
const hasParentLocalized = !!parentLocalizedPath;
|
|
342
|
+
const customPath = customLocalePaths?.[locale];
|
|
343
|
+
const basePath = customPath ? normalizePath(customPath) : normalizePath(route.path);
|
|
344
|
+
const finalRoutePath = shouldAddLocalePrefix(
|
|
345
|
+
locale,
|
|
346
|
+
this.defaultLocale,
|
|
347
|
+
addLocalePrefix,
|
|
348
|
+
isPrefixStrategy(this.strategy)
|
|
349
|
+
) ? buildFullPath(locale, basePath) : basePath;
|
|
350
|
+
const isChildRoute = parentPath !== "";
|
|
351
|
+
const finalPathForRoute = isChildRoute && hasParentLocalized ? normalizePath(route.path) : removeLeadingSlash(finalRoutePath);
|
|
352
|
+
const nextParentPath = customPath ? normalizePath(customPath) : hasParentLocalized ? parentLocalizedPath : normalizePath(path.posix.join(parentPath, routePath));
|
|
332
353
|
const localizedChildren = this.createLocalizedChildren(
|
|
333
|
-
route.children ?? [],
|
|
334
|
-
|
|
354
|
+
cloneArray(route.children ?? []),
|
|
355
|
+
nextParentPath,
|
|
335
356
|
[locale],
|
|
336
357
|
modifyName,
|
|
337
358
|
addLocalePrefix,
|
|
338
|
-
|
|
339
|
-
|
|
359
|
+
locale,
|
|
360
|
+
{
|
|
361
|
+
...localizedParentPaths,
|
|
362
|
+
[locale]: nextParentPath
|
|
363
|
+
}
|
|
340
364
|
);
|
|
341
365
|
const routeName = this.buildLocalizedRouteName(
|
|
342
366
|
buildRouteNameFromRoute(route.name, route.path),
|
|
343
367
|
locale,
|
|
344
368
|
modifyName,
|
|
345
|
-
|
|
346
|
-
);
|
|
347
|
-
const finalPath = this.buildLocalizedRoutePath(
|
|
348
|
-
routePath,
|
|
349
|
-
locale,
|
|
350
|
-
customLocalePaths,
|
|
351
|
-
addLocalePrefix
|
|
369
|
+
!!customLocalePaths
|
|
352
370
|
);
|
|
353
371
|
result.push({
|
|
354
372
|
...route,
|
|
355
373
|
name: routeName,
|
|
356
|
-
path:
|
|
374
|
+
path: finalPathForRoute,
|
|
357
375
|
children: localizedChildren
|
|
358
376
|
});
|
|
359
377
|
}
|
|
360
378
|
return result;
|
|
361
379
|
}
|
|
362
|
-
|
|
380
|
+
buildChildRouteName(baseName, parentLocale) {
|
|
381
|
+
if (parentLocale === true) {
|
|
382
|
+
return `localized-${baseName}`;
|
|
383
|
+
}
|
|
384
|
+
if (typeof parentLocale === "string") {
|
|
385
|
+
return `localized-${baseName}-${parentLocale}`;
|
|
386
|
+
}
|
|
387
|
+
return baseName;
|
|
388
|
+
}
|
|
389
|
+
createLocalizedRoute(page, localeCodes, originalChildren, isCustom, customPath = "", customRegex, force = false, parentLocale = false) {
|
|
363
390
|
const routePath = this.buildRoutePath(localeCodes, page.path, encodeURI(customPath), isCustom, customRegex, force);
|
|
364
391
|
if (!routePath || routePath == page.path)
|
|
365
392
|
return null;
|
|
366
393
|
const routeName = buildRouteName(buildRouteNameFromRoute(page.name, page.path), localeCodes[0], isCustom);
|
|
367
394
|
return {
|
|
368
395
|
...page,
|
|
369
|
-
children: this.createLocalizedChildren(originalChildren, page.path, localeCodes, true, false,
|
|
396
|
+
children: this.createLocalizedChildren(originalChildren, page.path, localeCodes, true, false, parentLocale),
|
|
370
397
|
path: routePath,
|
|
371
398
|
name: routeName
|
|
372
399
|
};
|
|
373
400
|
}
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
const normalizedBasePath = encodeURI(normalizePath(basePath));
|
|
377
|
-
return shouldAddLocalePrefix(locale, this.defaultLocale, addLocalePrefix, isPrefixStrategy(this.strategy)) ? buildFullPath(locale, normalizedBasePath) : normalizedBasePath;
|
|
378
|
-
}
|
|
379
|
-
buildLocalizedRouteName(baseName, locale, modifyName, forceLocaleSuffix = false) {
|
|
380
|
-
if (!modifyName) {
|
|
401
|
+
buildLocalizedRouteName(baseName, locale, modifyName, forceLocaleSuffixOrCustom = false) {
|
|
402
|
+
if (!modifyName)
|
|
381
403
|
return baseName;
|
|
382
|
-
|
|
383
|
-
if (forceLocaleSuffix) {
|
|
404
|
+
if (forceLocaleSuffixOrCustom) {
|
|
384
405
|
return `localized-${baseName}-${locale}`;
|
|
385
406
|
}
|
|
386
|
-
const shouldAddLocaleSuffix = locale && !isLocaleDefault(locale, this.defaultLocale,
|
|
407
|
+
const shouldAddLocaleSuffix = locale && !isLocaleDefault(locale, this.defaultLocale, isPrefixAndDefaultStrategy(this.strategy));
|
|
387
408
|
return shouldAddLocaleSuffix ? `localized-${baseName}-${locale}` : `localized-${baseName}`;
|
|
388
409
|
}
|
|
389
410
|
buildRoutePath(localeCodes, originalPath, customPath, isCustom, customRegex, force = false) {
|
|
@@ -472,6 +493,7 @@ const module = defineNuxtModule({
|
|
|
472
493
|
meta: true,
|
|
473
494
|
debug: false,
|
|
474
495
|
define: true,
|
|
496
|
+
redirects: true,
|
|
475
497
|
plugin: true,
|
|
476
498
|
hooks: true,
|
|
477
499
|
types: true,
|
|
@@ -598,6 +620,14 @@ const module = defineNuxtModule({
|
|
|
598
620
|
order: 4
|
|
599
621
|
});
|
|
600
622
|
}
|
|
623
|
+
if (options.redirects) {
|
|
624
|
+
addPlugin({
|
|
625
|
+
src: resolver.resolve("./runtime/plugins/06.redirect"),
|
|
626
|
+
name: "i18n-plugin-redirect",
|
|
627
|
+
mode: "all",
|
|
628
|
+
order: 6
|
|
629
|
+
});
|
|
630
|
+
}
|
|
601
631
|
addServerHandler({
|
|
602
632
|
route: `/${apiBaseUrl}/:page/:locale/data.json`,
|
|
603
633
|
handler: resolver.resolve("./runtime/server/routes/get")
|
|
@@ -1,68 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return locales.reduce((acc, locale) => {
|
|
11
|
-
acc[locale] = {};
|
|
12
|
-
return acc;
|
|
13
|
-
}, {});
|
|
14
|
-
} else if (typeof locales === "object" && locales !== null) {
|
|
15
|
-
return locales;
|
|
16
|
-
}
|
|
17
|
-
return {};
|
|
18
|
-
};
|
|
19
|
-
const handleRedirect = async (to) => {
|
|
20
|
-
const currentLocale = nuxtApp.$getLocale().toString();
|
|
21
|
-
const { name } = to;
|
|
22
|
-
let defaultRouteName = name?.toString().replace("localized-", "").replace(new RegExp(`-${currentLocale}$`), "");
|
|
23
|
-
if (!to.params.locale) {
|
|
24
|
-
if (router.hasRoute(`localized-${to.name?.toString()}-${currentLocale}`)) {
|
|
25
|
-
defaultRouteName = `localized-${to.name?.toString()}-${currentLocale}`;
|
|
26
|
-
} else {
|
|
27
|
-
defaultRouteName = `localized-${to.name?.toString()}`;
|
|
28
|
-
}
|
|
29
|
-
if (!router.hasRoute(defaultRouteName)) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
const newParams = { ...to.params };
|
|
33
|
-
if (!isNoPrefixStrategy(i18nConfig.strategy)) {
|
|
34
|
-
newParams.locale = i18nConfig.defaultLocale;
|
|
35
|
-
}
|
|
36
|
-
return navigateTo({ name: defaultRouteName, params: newParams }, { redirectCode: 301, external: true });
|
|
37
|
-
}
|
|
38
|
-
};
|
|
39
|
-
if (import.meta.server) {
|
|
40
|
-
if (isPrefixStrategy(i18nConfig.strategy) || isNoPrefixStrategy(i18nConfig.strategy)) {
|
|
41
|
-
await handleRedirect(route);
|
|
42
|
-
}
|
|
1
|
+
import { defineNuxtPlugin, useNuxtApp, computed, watch, onUnmounted, unref } from "#imports";
|
|
2
|
+
const normalizeLocales = (locales) => {
|
|
3
|
+
if (Array.isArray(locales)) {
|
|
4
|
+
return locales.reduce((acc, locale) => {
|
|
5
|
+
acc[locale] = {};
|
|
6
|
+
return acc;
|
|
7
|
+
}, {});
|
|
8
|
+
} else if (typeof locales === "object" && locales !== null) {
|
|
9
|
+
return locales;
|
|
43
10
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
if (next) {
|
|
49
|
-
next();
|
|
50
|
-
}
|
|
51
|
-
});
|
|
11
|
+
return {};
|
|
12
|
+
};
|
|
13
|
+
export default defineNuxtPlugin(() => {
|
|
52
14
|
const defineI18nRoute = async (routeDefinition) => {
|
|
53
|
-
const { $getLocale } = useNuxtApp();
|
|
15
|
+
const { $getLocale, $mergeGlobalTranslations } = useNuxtApp();
|
|
54
16
|
let currentLocale = computed(() => $getLocale());
|
|
55
17
|
const normalizedLocales = normalizeLocales(routeDefinition.locales);
|
|
56
18
|
const updateTranslations = () => {
|
|
57
|
-
const
|
|
58
|
-
if (
|
|
59
|
-
|
|
60
|
-
const translation = normalizedLocales[currentLocaleValue];
|
|
61
|
-
const { $mergeGlobalTranslations } = useNuxtApp();
|
|
62
|
-
if ($mergeGlobalTranslations) {
|
|
63
|
-
$mergeGlobalTranslations(translation);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
19
|
+
const localeValue = unref(currentLocale);
|
|
20
|
+
if (localeValue && normalizedLocales[localeValue]) {
|
|
21
|
+
$mergeGlobalTranslations?.(normalizedLocales[localeValue]);
|
|
66
22
|
}
|
|
67
23
|
};
|
|
68
24
|
updateTranslations();
|
|
@@ -71,8 +27,8 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
71
27
|
onUnmounted(() => {
|
|
72
28
|
if (stopWatcher) {
|
|
73
29
|
stopWatcher();
|
|
74
|
-
currentLocale = null;
|
|
75
30
|
stopWatcher = null;
|
|
31
|
+
currentLocale = null;
|
|
76
32
|
}
|
|
77
33
|
});
|
|
78
34
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { isNoPrefixStrategy, isPrefixStrategy } from "nuxt-i18n-micro-core";
|
|
2
|
+
import { defineNuxtPlugin, useRuntimeConfig, useRoute, useRouter, navigateTo } from "#imports";
|
|
3
|
+
export default defineNuxtPlugin(async (nuxtApp) => {
|
|
4
|
+
const config = useRuntimeConfig();
|
|
5
|
+
const i18nConfig = config.public.i18nConfig;
|
|
6
|
+
const route = useRoute();
|
|
7
|
+
const router = useRouter();
|
|
8
|
+
const handleRedirect = async (to) => {
|
|
9
|
+
const currentLocale = nuxtApp.$getLocale().toString();
|
|
10
|
+
const name = to.name?.toString();
|
|
11
|
+
let defaultRouteName = name?.toString().replace("localized-", "").replace(new RegExp(`-${currentLocale}$`), "");
|
|
12
|
+
if (!to.params.locale) {
|
|
13
|
+
if (router.hasRoute(`localized-${name}-${currentLocale}`)) {
|
|
14
|
+
defaultRouteName = `localized-${name}-${currentLocale}`;
|
|
15
|
+
} else {
|
|
16
|
+
defaultRouteName = `localized-${name}`;
|
|
17
|
+
}
|
|
18
|
+
if (!router.hasRoute(defaultRouteName)) return;
|
|
19
|
+
const newParams = { ...to.params };
|
|
20
|
+
if (!isNoPrefixStrategy(i18nConfig.strategy)) {
|
|
21
|
+
newParams.locale = i18nConfig.defaultLocale;
|
|
22
|
+
}
|
|
23
|
+
return navigateTo({ name: defaultRouteName, params: newParams }, {
|
|
24
|
+
redirectCode: 301,
|
|
25
|
+
external: true
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
if (import.meta.server && (isPrefixStrategy(i18nConfig.strategy) || isNoPrefixStrategy(i18nConfig.strategy))) {
|
|
30
|
+
await handleRedirect(route);
|
|
31
|
+
}
|
|
32
|
+
router.beforeEach(async (to, from, next) => {
|
|
33
|
+
if (isPrefixStrategy(i18nConfig.strategy) || isNoPrefixStrategy(i18nConfig.strategy)) {
|
|
34
|
+
await handleRedirect(to);
|
|
35
|
+
}
|
|
36
|
+
next?.();
|
|
37
|
+
});
|
|
38
|
+
});
|
package/dist/utils.d.mts
CHANGED
|
@@ -4,7 +4,7 @@ import { LocaleCode, Locale } from 'nuxt-i18n-micro-types';
|
|
|
4
4
|
declare function extractLocaleRoutes(content: string, filePath: string): Record<string, string> | null;
|
|
5
5
|
declare function validateDefineI18nRouteConfig(obj: Record<LocaleCode, Record<string, string>>): boolean;
|
|
6
6
|
declare const normalizePath: (routePath: string) => string;
|
|
7
|
-
declare const cloneArray: <T>(array: T[]) => T[];
|
|
7
|
+
declare const cloneArray: <T extends object>(array: T[]) => T[];
|
|
8
8
|
declare const isPageRedirectOnly: (page: NuxtPage) => boolean;
|
|
9
9
|
declare const removeLeadingSlash: (routePath: string) => string;
|
|
10
10
|
declare const buildRouteName: (baseName: string, localeCode: string, isCustom: boolean) => string;
|
package/dist/utils.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { LocaleCode, Locale } from 'nuxt-i18n-micro-types';
|
|
|
4
4
|
declare function extractLocaleRoutes(content: string, filePath: string): Record<string, string> | null;
|
|
5
5
|
declare function validateDefineI18nRouteConfig(obj: Record<LocaleCode, Record<string, string>>): boolean;
|
|
6
6
|
declare const normalizePath: (routePath: string) => string;
|
|
7
|
-
declare const cloneArray: <T>(array: T[]) => T[];
|
|
7
|
+
declare const cloneArray: <T extends object>(array: T[]) => T[];
|
|
8
8
|
declare const isPageRedirectOnly: (page: NuxtPage) => boolean;
|
|
9
9
|
declare const removeLeadingSlash: (routePath: string) => string;
|
|
10
10
|
declare const buildRouteName: (baseName: string, localeCode: string, isCustom: boolean) => string;
|
package/dist/utils.mjs
CHANGED
|
@@ -37,7 +37,7 @@ const normalizePath = (routePath) => {
|
|
|
37
37
|
const normalized = path.posix.normalize(routePath).replace(/\/+$/, "");
|
|
38
38
|
return normalized === "." ? "" : normalized;
|
|
39
39
|
};
|
|
40
|
-
const cloneArray = (array) =>
|
|
40
|
+
const cloneArray = (array) => array.map((item) => ({ ...item }));
|
|
41
41
|
const isPageRedirectOnly = (page) => !!(page.redirect && !page.file);
|
|
42
42
|
const removeLeadingSlash = (routePath) => routePath.startsWith("/") ? routePath.slice(1) : routePath;
|
|
43
43
|
const buildRouteName = (baseName, localeCode, isCustom) => isCustom ? `localized-${baseName}-${localeCode}` : `localized-${baseName}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-i18n-micro",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.86.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",
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"sirv": "^2.0.4",
|
|
61
61
|
"ufo": "^1.5.4",
|
|
62
62
|
"nuxt-i18n-micro-test-utils": "1.0.6",
|
|
63
|
-
"nuxt-i18n-micro-
|
|
64
|
-
"nuxt-i18n-micro-
|
|
63
|
+
"nuxt-i18n-micro-types": "1.0.5",
|
|
64
|
+
"nuxt-i18n-micro-core": "1.0.18"
|
|
65
65
|
},
|
|
66
66
|
"devDependencies": {
|
|
67
67
|
"@nuxt/devtools": "^2.1.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"id":"f7c3d9d2-1f61-4a23-92e5-e82bc6d21f4d","timestamp":1745580283138,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|