nuxt-i18n-micro 3.13.1 → 3.13.3
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 +1 -1
- package/dist/client/404.html +1 -1
- package/dist/client/_nuxt/builds/latest.json +1 -1
- package/dist/client/_nuxt/builds/meta/51d89894-442f-4831-a26e-08ee723351a8.json +1 -0
- package/dist/client/index.html +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +3 -2
- package/dist/runtime/composables/useI18nLocale.js +7 -1
- package/dist/runtime/composables/useLocaleHead.d.ts +8 -6
- package/dist/runtime/composables/useLocaleHead.js +43 -15
- package/dist/runtime/plugins/02.meta.js +2 -1
- package/dist/runtime/plugins/06.redirect.js +11 -8
- package/package.json +4 -4
- package/dist/client/_nuxt/builds/meta/de63387b-c983-467c-bbe3-fc436e608ff1.json +0 -1
package/dist/client/200.html
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/entry.Kj_DYE7z.css" crossorigin><link rel="modulepreload" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/D_aXYej0.js"><script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/D_aXYej0.js" crossorigin></script><link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-404.CyBDSRXN.css"><link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/Brscz0ku.js"><link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/Dt5GiM1K.js"><link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.DJtCwW7w.css"><link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/CXlkzKTu.js"></head><body><div id="__nuxt"></div><div id="teleports"></div><script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"
|
|
1
|
+
<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/entry.Kj_DYE7z.css" crossorigin><link rel="modulepreload" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/D_aXYej0.js"><script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/D_aXYej0.js" crossorigin></script><link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-404.CyBDSRXN.css"><link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/Brscz0ku.js"><link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/Dt5GiM1K.js"><link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.DJtCwW7w.css"><link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/CXlkzKTu.js"></head><body><div id="__nuxt"></div><div id="teleports"></div><script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"51d89894-442f-4831-a26e-08ee723351a8",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1773670890129,false]</script></body></html>
|
package/dist/client/404.html
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/entry.Kj_DYE7z.css" crossorigin><link rel="modulepreload" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/D_aXYej0.js"><script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/D_aXYej0.js" crossorigin></script><link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-404.CyBDSRXN.css"><link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/Brscz0ku.js"><link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/Dt5GiM1K.js"><link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.DJtCwW7w.css"><link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/CXlkzKTu.js"></head><body><div id="__nuxt"></div><div id="teleports"></div><script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"
|
|
1
|
+
<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/entry.Kj_DYE7z.css" crossorigin><link rel="modulepreload" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/D_aXYej0.js"><script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/D_aXYej0.js" crossorigin></script><link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-404.CyBDSRXN.css"><link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/Brscz0ku.js"><link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/Dt5GiM1K.js"><link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.DJtCwW7w.css"><link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/CXlkzKTu.js"></head><body><div id="__nuxt"></div><div id="teleports"></div><script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"51d89894-442f-4831-a26e-08ee723351a8",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1773670890129,false]</script></body></html>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"51d89894-442f-4831-a26e-08ee723351a8","timestamp":1773670886958}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"51d89894-442f-4831-a26e-08ee723351a8","timestamp":1773670886958,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|
package/dist/client/index.html
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/entry.Kj_DYE7z.css" crossorigin><link rel="modulepreload" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/D_aXYej0.js"><script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/D_aXYej0.js" crossorigin></script><link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-404.CyBDSRXN.css"><link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/Brscz0ku.js"><link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/Dt5GiM1K.js"><link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.DJtCwW7w.css"><link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/CXlkzKTu.js"></head><body><div id="__nuxt"></div><div id="teleports"></div><script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"
|
|
1
|
+
<!DOCTYPE html><html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/entry.Kj_DYE7z.css" crossorigin><link rel="modulepreload" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/D_aXYej0.js"><script type="module" src="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/D_aXYej0.js" crossorigin></script><link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-404.CyBDSRXN.css"><link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/Brscz0ku.js"><link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/Dt5GiM1K.js"><link rel="prefetch" as="style" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/error-500.DJtCwW7w.css"><link rel="prefetch" as="script" crossorigin href="/__NUXT_DEVTOOLS_I18N_BASE__/_nuxt/CXlkzKTu.js"></head><body><div id="__nuxt"></div><div id="teleports"></div><script>window.__NUXT__={};window.__NUXT__.config={public:{},app:{baseURL:"/__NUXT_DEVTOOLS_I18N_BASE__/",buildId:"51d89894-442f-4831-a26e-08ee723351a8",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1773670890130,false]</script></body></html>
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -292,6 +292,7 @@ function deepMergeTranslations(target, source) {
|
|
|
292
292
|
}
|
|
293
293
|
return output;
|
|
294
294
|
}
|
|
295
|
+
const DEFAULT_CANONICAL_QUERY_WHITELIST = ["page", "sort", "filter", "search", "q", "query", "tag"];
|
|
295
296
|
async function preMergeLocales(rootDirs, translationDirName, outputDir, locales, globalFallbackLocale, disablePageLocales) {
|
|
296
297
|
if (existsSync(outputDir)) fs__default.rmSync(outputDir, { recursive: true, force: true });
|
|
297
298
|
mkdirSync(outputDir, { recursive: true });
|
|
@@ -417,7 +418,7 @@ const module = defineNuxtModule({
|
|
|
417
418
|
apiBaseServerHost: void 0,
|
|
418
419
|
routesLocaleLinks: {},
|
|
419
420
|
globalLocaleRoutes: {},
|
|
420
|
-
canonicalQueryWhitelist:
|
|
421
|
+
canonicalQueryWhitelist: void 0,
|
|
421
422
|
plural: defaultPlural,
|
|
422
423
|
customRegexMatcher: void 0,
|
|
423
424
|
excludePatterns: void 0,
|
|
@@ -544,7 +545,7 @@ const module = defineNuxtModule({
|
|
|
544
545
|
apiBaseServerHost,
|
|
545
546
|
isSSG,
|
|
546
547
|
disablePageLocales: options.disablePageLocales ?? false,
|
|
547
|
-
canonicalQueryWhitelist: options.canonicalQueryWhitelist ??
|
|
548
|
+
canonicalQueryWhitelist: options.canonicalQueryWhitelist ?? DEFAULT_CANONICAL_QUERY_WHITELIST,
|
|
548
549
|
excludePatterns: options.excludePatterns ?? [],
|
|
549
550
|
routeLocales,
|
|
550
551
|
routeDisableMeta,
|
|
@@ -39,7 +39,13 @@ export function useI18nLocale() {
|
|
|
39
39
|
let locale = localeState.value;
|
|
40
40
|
if (!locale && options.serverLocale) locale = options.serverLocale;
|
|
41
41
|
if (!locale) locale = options.getLocaleFromRoute(options.route);
|
|
42
|
-
if (locale && !localeState.value)
|
|
42
|
+
if (locale && !localeState.value) {
|
|
43
|
+
if (import.meta.server) {
|
|
44
|
+
localeState.value = locale;
|
|
45
|
+
} else {
|
|
46
|
+
setLocale(locale);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
43
49
|
return locale ?? "";
|
|
44
50
|
};
|
|
45
51
|
const isValidLocale = (locale) => !!locale && validLocales.includes(locale);
|
|
@@ -17,12 +17,14 @@ interface MetaObject {
|
|
|
17
17
|
link: MetaLink[];
|
|
18
18
|
meta: MetaTag[];
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
addDirAttribute?: boolean
|
|
22
|
-
identifierAttribute?: string
|
|
23
|
-
addSeoAttributes?: boolean
|
|
24
|
-
baseUrl?: string
|
|
25
|
-
|
|
20
|
+
interface UseLocaleHeadOptions {
|
|
21
|
+
addDirAttribute?: boolean;
|
|
22
|
+
identifierAttribute?: string;
|
|
23
|
+
addSeoAttributes?: boolean;
|
|
24
|
+
baseUrl?: string;
|
|
25
|
+
autoUpdate?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare const useLocaleHead: ({ addDirAttribute, identifierAttribute, addSeoAttributes, baseUrl, autoUpdate, }?: UseLocaleHeadOptions) => {
|
|
26
28
|
metaObject: import("vue").Ref<{
|
|
27
29
|
htmlAttrs: {
|
|
28
30
|
lang?: string | undefined;
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
import { isNoPrefixStrategy } from "@i18n-micro/core";
|
|
2
2
|
import { joinURL, parseURL, withQuery } from "ufo";
|
|
3
|
-
import { ref, unref } from "vue";
|
|
3
|
+
import { ref, unref, watch } from "vue";
|
|
4
4
|
import { useNuxtApp, useRoute } from "#imports";
|
|
5
5
|
import { findAllowedLocalesForRoute } from "../utils/route-utils.js";
|
|
6
|
-
export const useLocaleHead = ({
|
|
6
|
+
export const useLocaleHead = ({
|
|
7
|
+
addDirAttribute = true,
|
|
8
|
+
identifierAttribute = "id",
|
|
9
|
+
addSeoAttributes = true,
|
|
10
|
+
baseUrl = "/",
|
|
11
|
+
autoUpdate = true
|
|
12
|
+
} = {}) => {
|
|
13
|
+
const nuxtApp = useNuxtApp();
|
|
14
|
+
const route = useRoute();
|
|
7
15
|
const metaObject = ref({
|
|
8
16
|
htmlAttrs: {},
|
|
9
17
|
link: [],
|
|
@@ -20,22 +28,32 @@ export const useLocaleHead = ({ addDirAttribute = true, identifierAttribute = "i
|
|
|
20
28
|
}
|
|
21
29
|
return withQuery(pathname, filtered);
|
|
22
30
|
}
|
|
31
|
+
function filterLocalizedHref(pathOrUrl, whitelist) {
|
|
32
|
+
if (!pathOrUrl) return "";
|
|
33
|
+
const parsed = parseURL(pathOrUrl);
|
|
34
|
+
const filteredPath = filterQuery(pathOrUrl, whitelist);
|
|
35
|
+
if (parsed.protocol && parsed.host) {
|
|
36
|
+
return `${parsed.protocol}//${parsed.host}${filteredPath}`;
|
|
37
|
+
}
|
|
38
|
+
return filteredPath;
|
|
39
|
+
}
|
|
23
40
|
function updateMeta() {
|
|
24
|
-
const route = useRoute();
|
|
25
41
|
if (route.matched.length === 0 || route.matched.some((record) => record.name === "custom-fallback-route")) {
|
|
26
42
|
metaObject.value = { htmlAttrs: {}, link: [], meta: [] };
|
|
27
43
|
return;
|
|
28
44
|
}
|
|
29
|
-
const i18nConfig =
|
|
45
|
+
const i18nConfig = nuxtApp.$getI18nConfig();
|
|
30
46
|
const { canonicalQueryWhitelist, routeLocales, localizedRouteNamePrefix } = i18nConfig;
|
|
31
47
|
const strategy = i18nConfig.strategy;
|
|
32
48
|
const localizedRouteNamePrefixResolved = localizedRouteNamePrefix || "localized-";
|
|
33
|
-
const { $getLocales, $getLocale, $switchLocalePath } =
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
const
|
|
49
|
+
const { $getLocales, $getLocale, $switchLocalePath } = nuxtApp;
|
|
50
|
+
const allLocales = ($getLocales ? unref($getLocales()) : i18nConfig.locales) ?? [];
|
|
51
|
+
const firstSegment = route.path.replace(/^\//, "").split("/").filter(Boolean)[0];
|
|
52
|
+
const fallbackLocale = allLocales.find((loc) => loc.code === firstSegment)?.code || i18nConfig.defaultLocale || "en";
|
|
53
|
+
const locale = ($getLocale ? unref($getLocale()) : fallbackLocale) || fallbackLocale;
|
|
54
|
+
const switchLocalePath = $switchLocalePath || (() => "");
|
|
37
55
|
const routeName = (route.name ?? "").toString();
|
|
38
|
-
const currentLocale =
|
|
56
|
+
const currentLocale = allLocales.find((loc) => loc.code === locale);
|
|
39
57
|
if (!currentLocale) return;
|
|
40
58
|
const currentRouteLocales = findAllowedLocalesForRoute(route, routeLocales, localizedRouteNamePrefixResolved);
|
|
41
59
|
const enabledLocales = allLocales.filter((loc) => !loc.disabled);
|
|
@@ -89,16 +107,18 @@ export const useLocaleHead = ({ addDirAttribute = true, identifierAttribute = "i
|
|
|
89
107
|
href: ogUrl
|
|
90
108
|
};
|
|
91
109
|
const defaultLocale = i18nConfig.defaultLocale || "en";
|
|
110
|
+
const whitelist = canonicalQueryWhitelist ?? [];
|
|
92
111
|
const alternateLinks = isNoPrefixStrategy(strategy) ? [] : alternateLocales.flatMap((loc) => {
|
|
93
|
-
const switchedPath =
|
|
112
|
+
const switchedPath = switchLocalePath(loc.code);
|
|
94
113
|
if (!switchedPath) {
|
|
95
114
|
return [];
|
|
96
115
|
}
|
|
97
116
|
let href;
|
|
98
117
|
if (switchedPath.startsWith("http://") || switchedPath.startsWith("https://")) {
|
|
99
|
-
href = switchedPath;
|
|
118
|
+
href = filterLocalizedHref(switchedPath, whitelist);
|
|
100
119
|
} else {
|
|
101
|
-
|
|
120
|
+
const filteredPath = filterLocalizedHref(switchedPath, whitelist);
|
|
121
|
+
href = joinURL(unref(baseUrl), filteredPath.startsWith("/") ? filteredPath : `/${filteredPath}`);
|
|
102
122
|
}
|
|
103
123
|
const links = [
|
|
104
124
|
{
|
|
@@ -120,13 +140,14 @@ export const useLocaleHead = ({ addDirAttribute = true, identifierAttribute = "i
|
|
|
120
140
|
});
|
|
121
141
|
let xDefaultLink = null;
|
|
122
142
|
if (!isNoPrefixStrategy(strategy)) {
|
|
123
|
-
const defaultSwitchedPath =
|
|
143
|
+
const defaultSwitchedPath = switchLocalePath(defaultLocale);
|
|
124
144
|
if (defaultSwitchedPath) {
|
|
125
145
|
let xDefaultHref;
|
|
126
146
|
if (defaultSwitchedPath.startsWith("http://") || defaultSwitchedPath.startsWith("https://")) {
|
|
127
|
-
xDefaultHref = defaultSwitchedPath;
|
|
147
|
+
xDefaultHref = filterLocalizedHref(defaultSwitchedPath, whitelist);
|
|
128
148
|
} else {
|
|
129
|
-
|
|
149
|
+
const filteredPath = filterLocalizedHref(defaultSwitchedPath, whitelist);
|
|
150
|
+
xDefaultHref = joinURL(unref(baseUrl), filteredPath.startsWith("/") ? filteredPath : `/${filteredPath}`);
|
|
130
151
|
}
|
|
131
152
|
xDefaultLink = {
|
|
132
153
|
[identifierAttribute]: "i18n-xd",
|
|
@@ -139,5 +160,12 @@ export const useLocaleHead = ({ addDirAttribute = true, identifierAttribute = "i
|
|
|
139
160
|
metaObject.value.meta = [ogLocaleMeta, ogUrlMeta, ...alternateOgLocalesMeta];
|
|
140
161
|
metaObject.value.link = [canonicalLink, ...alternateLinks, ...xDefaultLink ? [xDefaultLink] : []];
|
|
141
162
|
}
|
|
163
|
+
if (autoUpdate) {
|
|
164
|
+
watch(
|
|
165
|
+
() => [route.fullPath, route.name, route.matched.length],
|
|
166
|
+
() => updateMeta(),
|
|
167
|
+
{ immediate: true }
|
|
168
|
+
);
|
|
169
|
+
}
|
|
142
170
|
return { metaObject, updateMeta };
|
|
143
171
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getCookie, getHeader, getRequestURL,
|
|
1
|
+
import { getCookie, getHeader, getRequestURL, setCookie } from "h3";
|
|
2
2
|
import { createI18nStrategy, getI18nConfig } from "#build/i18n.strategy.mjs";
|
|
3
3
|
import { createError, defineNuxtPlugin, navigateTo, useRequestEvent, useRoute, useRouter, useState } from "#imports";
|
|
4
4
|
import { useI18nLocale } from "../composables/useI18nLocale.js";
|
|
@@ -63,12 +63,8 @@ export default defineNuxtPlugin({
|
|
|
63
63
|
if (!event) return;
|
|
64
64
|
const url = getRequestURL(event);
|
|
65
65
|
const path = url.pathname;
|
|
66
|
-
const isPrerender = !!getHeader(event, "x-nitro-prerender");
|
|
67
66
|
const performRedirect = (targetUrl, code = 302) => {
|
|
68
|
-
|
|
69
|
-
return navigateTo(targetUrl, { redirectCode: code });
|
|
70
|
-
}
|
|
71
|
-
return sendRedirect(event, targetUrl, code);
|
|
67
|
+
return navigateTo(targetUrl, { redirectCode: code });
|
|
72
68
|
};
|
|
73
69
|
if (path.startsWith("/api") || path.startsWith("/_nuxt") || path.startsWith("/_locales") || path.startsWith("/__")) return;
|
|
74
70
|
if (path.includes(".") && !path.endsWith(".html")) return;
|
|
@@ -93,7 +89,8 @@ export default defineNuxtPlugin({
|
|
|
93
89
|
throw createError({ statusCode: 404, statusMessage: "Page Not Found" });
|
|
94
90
|
}
|
|
95
91
|
const hasLocalePrefix = Boolean(firstSegment && validLocales.includes(firstSegment));
|
|
96
|
-
|
|
92
|
+
const shouldDeferCookieSync = i18nConfig.redirects !== false && autoDetectPath === "*";
|
|
93
|
+
if (hasLocalePrefix && cookieName && !shouldDeferCookieSync) {
|
|
97
94
|
const currentLocale = firstSegment;
|
|
98
95
|
const { watch: _w, ...cookieOpts } = getLocaleCookieOptions();
|
|
99
96
|
setCookie(event, cookieName, currentLocale, cookieOpts);
|
|
@@ -131,6 +128,9 @@ export default defineNuxtPlugin({
|
|
|
131
128
|
}
|
|
132
129
|
}
|
|
133
130
|
}
|
|
131
|
+
if (autoDetectPath === "*" && !hasLocalePrefix) {
|
|
132
|
+
preferredLocale = defaultLocale;
|
|
133
|
+
}
|
|
134
134
|
if (autoDetectPath === "*" && hasLocalePrefix && firstSegment !== preferredLocale) {
|
|
135
135
|
const rest = pathSegments.slice(1).join("/");
|
|
136
136
|
let targetPath;
|
|
@@ -157,13 +157,16 @@ export default defineNuxtPlugin({
|
|
|
157
157
|
if (import.meta.client && i18nConfig.redirects !== false) {
|
|
158
158
|
const runRedirect = () => {
|
|
159
159
|
const { getPreferredLocale } = useI18nLocale();
|
|
160
|
-
|
|
160
|
+
let preferredLocale = getPreferredLocale();
|
|
161
161
|
if (!preferredLocale) return;
|
|
162
162
|
const route = useRoute();
|
|
163
163
|
const path = route.path || "/";
|
|
164
164
|
const pathSegments = path.replace(/^\//, "").split("/").filter(Boolean);
|
|
165
165
|
const firstSegment = pathSegments[0];
|
|
166
166
|
const hasLocalePrefix = Boolean(firstSegment && validLocales.includes(firstSegment));
|
|
167
|
+
if (autoDetectPath === "*" && !hasLocalePrefix) {
|
|
168
|
+
preferredLocale = defaultLocale;
|
|
169
|
+
}
|
|
167
170
|
if (autoDetectPath === "*" && hasLocalePrefix && firstSegment !== preferredLocale) {
|
|
168
171
|
const rest = pathSegments.slice(1).join("/");
|
|
169
172
|
let targetPath;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nuxt-i18n-micro",
|
|
3
|
-
"version": "3.13.
|
|
3
|
+
"version": "3.13.3",
|
|
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",
|
|
@@ -74,11 +74,11 @@
|
|
|
74
74
|
"chokidar": "^3.6.0",
|
|
75
75
|
"globby": "^14.1.0",
|
|
76
76
|
"ufo": "^1.5.4",
|
|
77
|
-
"@i18n-micro/
|
|
77
|
+
"@i18n-micro/core": "1.2.0",
|
|
78
|
+
"@i18n-micro/path-strategy": "1.3.0",
|
|
78
79
|
"@i18n-micro/test-utils": "1.2.0",
|
|
79
80
|
"@i18n-micro/types": "1.1.6",
|
|
80
|
-
"@i18n-micro/
|
|
81
|
-
"@i18n-micro/path-strategy": "1.3.0"
|
|
81
|
+
"@i18n-micro/route-strategy": "1.1.4"
|
|
82
82
|
},
|
|
83
83
|
"devDependencies": {
|
|
84
84
|
"@biomejs/biome": "^2.3.14",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"id":"de63387b-c983-467c-bbe3-fc436e608ff1","timestamp":1772269226925,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|