nuxt-i18n-micro 3.13.0 → 3.13.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.
- 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/18b0ed8a-b21e-4af9-8577-9f18b9cd7286.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 +27 -11
- package/dist/runtime/plugins/01.plugin.js +2 -3
- package/dist/runtime/plugins/02.meta.js +2 -1
- package/dist/runtime/plugins/05.hooks.js +2 -4
- package/dist/runtime/plugins/06.redirect.js +11 -8
- package/package.json +5 -5
- package/dist/client/_nuxt/builds/meta/056a640f-3e09-43e9-8877-18232dba0813.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:"18b0ed8a-b21e-4af9-8577-9f18b9cd7286",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1773134438477,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:"18b0ed8a-b21e-4af9-8577-9f18b9cd7286",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1773134438478,false]</script></body></html>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"id":"
|
|
1
|
+
{"id":"18b0ed8a-b21e-4af9-8577-9f18b9cd7286","timestamp":1773134435178}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"id":"18b0ed8a-b21e-4af9-8577-9f18b9cd7286","timestamp":1773134435178,"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:"18b0ed8a-b21e-4af9-8577-9f18b9cd7286",buildAssetsDir:"/_nuxt/",cdnURL:""}}</script><script type="application/json" data-nuxt-data="nuxt-app" data-ssr="false" id="__NUXT_DATA__">[{"prerenderedAt":1,"serverRendered":2},1773134438478,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: [],
|
|
@@ -21,21 +29,22 @@ export const useLocaleHead = ({ addDirAttribute = true, identifierAttribute = "i
|
|
|
21
29
|
return withQuery(pathname, filtered);
|
|
22
30
|
}
|
|
23
31
|
function updateMeta() {
|
|
24
|
-
const route = useRoute();
|
|
25
32
|
if (route.matched.length === 0 || route.matched.some((record) => record.name === "custom-fallback-route")) {
|
|
26
33
|
metaObject.value = { htmlAttrs: {}, link: [], meta: [] };
|
|
27
34
|
return;
|
|
28
35
|
}
|
|
29
|
-
const i18nConfig =
|
|
36
|
+
const i18nConfig = nuxtApp.$getI18nConfig();
|
|
30
37
|
const { canonicalQueryWhitelist, routeLocales, localizedRouteNamePrefix } = i18nConfig;
|
|
31
38
|
const strategy = i18nConfig.strategy;
|
|
32
39
|
const localizedRouteNamePrefixResolved = localizedRouteNamePrefix || "localized-";
|
|
33
|
-
const { $getLocales, $getLocale, $switchLocalePath } =
|
|
34
|
-
|
|
35
|
-
const
|
|
36
|
-
const
|
|
40
|
+
const { $getLocales, $getLocale, $switchLocalePath } = nuxtApp;
|
|
41
|
+
const allLocales = ($getLocales ? unref($getLocales()) : i18nConfig.locales) ?? [];
|
|
42
|
+
const firstSegment = route.path.replace(/^\//, "").split("/").filter(Boolean)[0];
|
|
43
|
+
const fallbackLocale = allLocales.find((loc) => loc.code === firstSegment)?.code || i18nConfig.defaultLocale || "en";
|
|
44
|
+
const locale = ($getLocale ? unref($getLocale()) : fallbackLocale) || fallbackLocale;
|
|
45
|
+
const switchLocalePath = $switchLocalePath || (() => "");
|
|
37
46
|
const routeName = (route.name ?? "").toString();
|
|
38
|
-
const currentLocale =
|
|
47
|
+
const currentLocale = allLocales.find((loc) => loc.code === locale);
|
|
39
48
|
if (!currentLocale) return;
|
|
40
49
|
const currentRouteLocales = findAllowedLocalesForRoute(route, routeLocales, localizedRouteNamePrefixResolved);
|
|
41
50
|
const enabledLocales = allLocales.filter((loc) => !loc.disabled);
|
|
@@ -90,7 +99,7 @@ export const useLocaleHead = ({ addDirAttribute = true, identifierAttribute = "i
|
|
|
90
99
|
};
|
|
91
100
|
const defaultLocale = i18nConfig.defaultLocale || "en";
|
|
92
101
|
const alternateLinks = isNoPrefixStrategy(strategy) ? [] : alternateLocales.flatMap((loc) => {
|
|
93
|
-
const switchedPath =
|
|
102
|
+
const switchedPath = switchLocalePath(loc.code);
|
|
94
103
|
if (!switchedPath) {
|
|
95
104
|
return [];
|
|
96
105
|
}
|
|
@@ -120,7 +129,7 @@ export const useLocaleHead = ({ addDirAttribute = true, identifierAttribute = "i
|
|
|
120
129
|
});
|
|
121
130
|
let xDefaultLink = null;
|
|
122
131
|
if (!isNoPrefixStrategy(strategy)) {
|
|
123
|
-
const defaultSwitchedPath =
|
|
132
|
+
const defaultSwitchedPath = switchLocalePath(defaultLocale);
|
|
124
133
|
if (defaultSwitchedPath) {
|
|
125
134
|
let xDefaultHref;
|
|
126
135
|
if (defaultSwitchedPath.startsWith("http://") || defaultSwitchedPath.startsWith("https://")) {
|
|
@@ -139,5 +148,12 @@ export const useLocaleHead = ({ addDirAttribute = true, identifierAttribute = "i
|
|
|
139
148
|
metaObject.value.meta = [ogLocaleMeta, ogUrlMeta, ...alternateOgLocalesMeta];
|
|
140
149
|
metaObject.value.link = [canonicalLink, ...alternateLinks, ...xDefaultLink ? [xDefaultLink] : []];
|
|
141
150
|
}
|
|
151
|
+
if (autoUpdate) {
|
|
152
|
+
watch(
|
|
153
|
+
() => [route.fullPath, route.name, route.matched.length],
|
|
154
|
+
() => updateMeta(),
|
|
155
|
+
{ immediate: true }
|
|
156
|
+
);
|
|
157
|
+
}
|
|
142
158
|
return { metaObject, updateMeta };
|
|
143
159
|
};
|
|
@@ -161,12 +161,11 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
163
|
}
|
|
164
|
-
router.beforeEach(async (to, from
|
|
164
|
+
router.beforeEach(async (to, from) => {
|
|
165
165
|
if (to.name !== from.name) {
|
|
166
166
|
i18nRouteParams.value = {};
|
|
167
167
|
}
|
|
168
168
|
if (to.path === from.path && !isNoPrefixStrategy(i18nConfig.strategy)) {
|
|
169
|
-
if (next) next();
|
|
170
169
|
return;
|
|
171
170
|
}
|
|
172
171
|
try {
|
|
@@ -181,7 +180,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
181
180
|
} catch (e) {
|
|
182
181
|
if (isDev) console.error("[i18n] Navigation error:", e);
|
|
183
182
|
}
|
|
184
|
-
|
|
183
|
+
return;
|
|
185
184
|
});
|
|
186
185
|
const tFast = (key, params, defaultValue, route) => {
|
|
187
186
|
if (!key) return "";
|
|
@@ -23,7 +23,7 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
23
23
|
},
|
|
24
24
|
locale
|
|
25
25
|
);
|
|
26
|
-
router.beforeEach(async (to, from
|
|
26
|
+
router.beforeEach(async (to, from) => {
|
|
27
27
|
if (to.path !== from.path || isNoPrefixStrategy(i18nConfig.strategy)) {
|
|
28
28
|
const locale2 = $getLocale(to);
|
|
29
29
|
const routeName2 = $getRouteName(to);
|
|
@@ -36,8 +36,6 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|
|
36
36
|
locale2
|
|
37
37
|
);
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
next();
|
|
41
|
-
}
|
|
39
|
+
return;
|
|
42
40
|
});
|
|
43
41
|
});
|
|
@@ -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.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",
|
|
@@ -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/core": "1.2.0",
|
|
78
|
-
"@i18n-micro/test-utils": "1.2.0",
|
|
79
|
-
"@i18n-micro/route-strategy": "1.1.4",
|
|
80
77
|
"@i18n-micro/path-strategy": "1.3.0",
|
|
81
|
-
"@i18n-micro/
|
|
78
|
+
"@i18n-micro/test-utils": "1.2.0",
|
|
79
|
+
"@i18n-micro/core": "1.2.0",
|
|
80
|
+
"@i18n-micro/types": "1.1.6",
|
|
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":"056a640f-3e09-43e9-8877-18232dba0813","timestamp":1772198473287,"matcher":{"static":{},"wildcard":{},"dynamic":{}},"prerendered":[]}
|