@fluenti/nuxt 0.2.0 → 0.3.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/detectors-BnmzZTww.cjs +2 -0
- package/dist/detectors-BnmzZTww.cjs.map +1 -0
- package/dist/detectors-CAqp_VCN.js +100 -0
- package/dist/detectors-CAqp_VCN.js.map +1 -0
- package/dist/devtools.d.ts +31 -0
- package/dist/devtools.d.ts.map +1 -0
- package/dist/isr-validation.d.ts +14 -0
- package/dist/isr-validation.d.ts.map +1 -0
- package/dist/locale-head-BuSO-fCZ.js +88 -0
- package/dist/locale-head-BuSO-fCZ.js.map +1 -0
- package/dist/locale-head-D1NAUQc8.cjs +2 -0
- package/dist/locale-head-D1NAUQc8.cjs.map +1 -0
- package/dist/module.cjs +1 -1
- package/dist/module.cjs.map +1 -1
- package/dist/module.d.ts +18 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +231 -46
- package/dist/module.js.map +1 -1
- package/dist/page-extend-BrPO2RhM.js +36 -0
- package/dist/page-extend-BrPO2RhM.js.map +1 -0
- package/dist/page-extend-tRXsujtK.cjs +2 -0
- package/dist/page-extend-tRXsujtK.cjs.map +1 -0
- package/dist/page-meta-transform.d.ts +17 -0
- package/dist/page-meta-transform.d.ts.map +1 -0
- package/dist/runtime/client.cjs +1 -1
- package/dist/runtime/client.cjs.map +1 -1
- package/dist/runtime/client.js +2 -2
- package/dist/runtime/components/NuxtLinkLocale.cjs +1 -1
- package/dist/runtime/components/NuxtLinkLocale.cjs.map +1 -1
- package/dist/runtime/composables.cjs +1 -1
- package/dist/runtime/composables.cjs.map +1 -1
- package/dist/runtime/composables.d.ts +46 -0
- package/dist/runtime/composables.d.ts.map +1 -1
- package/dist/runtime/composables.js +55 -13
- package/dist/runtime/composables.js.map +1 -1
- package/dist/runtime/define-i18n-route.cjs +2 -0
- package/dist/runtime/define-i18n-route.cjs.map +1 -0
- package/dist/runtime/define-i18n-route.d.ts +27 -0
- package/dist/runtime/define-i18n-route.d.ts.map +1 -0
- package/dist/runtime/define-i18n-route.js +6 -0
- package/dist/runtime/define-i18n-route.js.map +1 -0
- package/dist/runtime/detectors/cookie.d.ts.map +1 -1
- package/dist/runtime/detectors/domain.cjs +2 -0
- package/dist/runtime/detectors/domain.cjs.map +1 -0
- package/dist/runtime/detectors/domain.d.ts +9 -0
- package/dist/runtime/detectors/domain.d.ts.map +1 -0
- package/dist/runtime/detectors/domain.js +15 -0
- package/dist/runtime/detectors/domain.js.map +1 -0
- package/dist/runtime/detectors/header.d.ts.map +1 -1
- package/dist/runtime/detectors/index.d.ts +1 -1
- package/dist/runtime/detectors/index.d.ts.map +1 -1
- package/dist/runtime/detectors/query.d.ts.map +1 -1
- package/dist/runtime/index.cjs +1 -1
- package/dist/runtime/index.d.ts +1 -1
- package/dist/runtime/index.d.ts.map +1 -1
- package/dist/runtime/index.js +5 -5
- package/dist/runtime/locale-head.d.ts +3 -0
- package/dist/runtime/locale-head.d.ts.map +1 -1
- package/dist/runtime/middleware/locale-redirect.cjs +1 -1
- package/dist/runtime/middleware/locale-redirect.cjs.map +1 -1
- package/dist/runtime/middleware/locale-redirect.js +1 -1
- package/dist/runtime/page-extend.d.ts +21 -5
- package/dist/runtime/page-extend.d.ts.map +1 -1
- package/dist/runtime/plugin.cjs +1 -1
- package/dist/runtime/plugin.cjs.map +1 -1
- package/dist/runtime/plugin.d.ts.map +1 -1
- package/dist/runtime/plugin.js +55 -23
- package/dist/runtime/plugin.js.map +1 -1
- package/dist/runtime/server/locale-redirect.cjs +2 -0
- package/dist/runtime/server/locale-redirect.cjs.map +1 -0
- package/dist/runtime/server/locale-redirect.d.ts +12 -0
- package/dist/runtime/server/locale-redirect.d.ts.map +1 -0
- package/dist/runtime/server/locale-redirect.js +51 -0
- package/dist/runtime/server/locale-redirect.js.map +1 -0
- package/dist/runtime/standalone-composables.cjs +2 -0
- package/dist/runtime/standalone-composables.cjs.map +1 -0
- package/dist/runtime/standalone-composables.d.ts +6 -0
- package/dist/runtime/standalone-composables.d.ts.map +1 -1
- package/dist/runtime/standalone-composables.js +34 -0
- package/dist/runtime/standalone-composables.js.map +1 -0
- package/dist/sitemap.d.ts +24 -0
- package/dist/sitemap.d.ts.map +1 -0
- package/dist/types.d.ts +210 -13
- package/dist/types.d.ts.map +1 -1
- package/llms-full.txt +411 -0
- package/llms-migration.txt +201 -0
- package/llms.txt +103 -0
- package/package.json +5 -4
- package/dist/detectors-CFJvuwzi.cjs +0 -2
- package/dist/detectors-CFJvuwzi.cjs.map +0 -1
- package/dist/detectors-DhkfHBHr.js +0 -84
- package/dist/detectors-DhkfHBHr.js.map +0 -1
- package/dist/locale-head-BfsESdd7.cjs +0 -2
- package/dist/locale-head-BfsESdd7.cjs.map +0 -1
- package/dist/locale-head-CqUlvy3O.js +0 -38
- package/dist/locale-head-CqUlvy3O.js.map +0 -1
- package/dist/page-extend-DJ7wpuVj.js +0 -25
- package/dist/page-extend-DJ7wpuVj.js.map +0 -1
- package/dist/page-extend-OvV-ZhFB.cjs +0 -2
- package/dist/page-extend-OvV-ZhFB.cjs.map +0 -1
package/dist/runtime/plugin.js
CHANGED
|
@@ -1,30 +1,62 @@
|
|
|
1
|
-
import { n as e, t } from "../path-utils-BcvXLCGi.js";
|
|
2
|
-
import { t as
|
|
3
|
-
import { ref as
|
|
4
|
-
import { defineNuxtPlugin as
|
|
1
|
+
import { n as e, r as t, t as n } from "../path-utils-BcvXLCGi.js";
|
|
2
|
+
import { t as r } from "../detectors-CAqp_VCN.js";
|
|
3
|
+
import { ref as i, watch as a } from "vue";
|
|
4
|
+
import { defineNuxtPlugin as o, useCookie as s, useRequestHeaders as c, useRoute as l, useRuntimeConfig as u } from "#imports";
|
|
5
5
|
//#region src/runtime/plugin.ts
|
|
6
|
-
var
|
|
7
|
-
let
|
|
8
|
-
if (import.meta.server)
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
let { locale: e } = t(u.path, l.locales);
|
|
14
|
-
m = e || (p && p.value && l.locales.includes(p.value) ? p.value : l.defaultLocale);
|
|
6
|
+
var d = o(async (o) => {
|
|
7
|
+
let d = u().public.fluenti, f = l(), p = d.detectBrowserLanguage?.useCookie ? d.detectBrowserLanguage : null, m = p?.cookieKey ?? "fluenti_locale", h = p ? s(m) : null, g, _;
|
|
8
|
+
if (import.meta.server) try {
|
|
9
|
+
let e = c(["host", "accept-language"]);
|
|
10
|
+
_ = e["accept-language"], d.strategy === "domains" && (g = e.host);
|
|
11
|
+
} catch (e) {
|
|
12
|
+
import.meta.dev && console.debug("[fluenti] Header read failed:", e);
|
|
15
13
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
else if (d.strategy === "domains") try {
|
|
15
|
+
g = window.location.host;
|
|
16
|
+
} catch (e) {
|
|
17
|
+
import.meta.dev && console.debug("[fluenti] Domain detection failed:", e);
|
|
18
|
+
}
|
|
19
|
+
let v;
|
|
20
|
+
if (import.meta.server) {
|
|
21
|
+
v = await r(f.path, d, void 0, async (e) => {
|
|
22
|
+
await o.callHook("fluenti:detect-locale", e);
|
|
23
|
+
}, g, h?.value ?? void 0, _), o.payload.fluentiLocale = v;
|
|
24
|
+
try {
|
|
25
|
+
let e = o.ssrContext?.event;
|
|
26
|
+
e && (e.context.locale = v);
|
|
27
|
+
} catch (e) {
|
|
28
|
+
import.meta.dev && console.debug("[fluenti] Event context not available:", e);
|
|
29
|
+
}
|
|
30
|
+
} else if (o.payload.fluentiLocale) v = o.payload.fluentiLocale;
|
|
31
|
+
else if (d.strategy === "domains" && g && d.domains?.length) {
|
|
32
|
+
let e = g.toLowerCase().replace(/:\d+$/, ""), t = d.domains.find((t) => t.domain.toLowerCase() === e);
|
|
33
|
+
v = t ? t.locale : d.defaultLocale;
|
|
34
|
+
} else {
|
|
35
|
+
let { locale: e } = n(f.path, d.locales);
|
|
36
|
+
v = e || (h && h.value && d.locales.includes(h.value) ? h.value : d.defaultLocale);
|
|
37
|
+
}
|
|
38
|
+
let y = i(v);
|
|
39
|
+
if (d.strategy !== "no_prefix" && d.strategy !== "domains" && a(() => f.path, (e) => {
|
|
40
|
+
let { locale: t } = n(e, d.locales);
|
|
41
|
+
t ? y.value = t : d.strategy === "prefix_except_default" && (y.value = d.defaultLocale);
|
|
42
|
+
}), h && a(y, (e) => {
|
|
43
|
+
h.value = e;
|
|
44
|
+
}), d.injectGlobalProperties) {
|
|
45
|
+
let n = o.vueApp.config.globalProperties;
|
|
46
|
+
n.$localePath = (t, n) => e(t, n ?? y.value, d.defaultLocale, d.strategy), n.$switchLocalePath = (e) => t(f.path, e, d.locales, d.defaultLocale, d.strategy);
|
|
47
|
+
try {
|
|
48
|
+
let { useI18n: e } = await import("@fluenti/vue"), t = e();
|
|
49
|
+
n.$t ||= t.t, n.$d ||= t.d, n.$n ||= t.n;
|
|
50
|
+
} catch (e) {
|
|
51
|
+
import.meta.dev && console.debug("[fluenti] Vue plugin not yet installed, skipping $t/$d/$n injection:", e);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
return { provide: {
|
|
55
|
+
fluentiLocale: y,
|
|
56
|
+
fluentiConfig: d
|
|
25
57
|
} };
|
|
26
58
|
});
|
|
27
59
|
//#endregion
|
|
28
|
-
export {
|
|
60
|
+
export { d as default };
|
|
29
61
|
|
|
30
62
|
//# sourceMappingURL=plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","names":[],"sources":["../../src/runtime/plugin.ts"],"sourcesContent":["import { defineNuxtPlugin, useRuntimeConfig, useRoute, useCookie } from '#imports'\nimport { ref, watch } from 'vue'\nimport { localePath, extractLocaleFromPath } from './path-utils'\nimport { runDetectors } from './detectors'\nimport type { FluentNuxtRuntimeConfig, LocaleDetectContext } from '../types'\n\n/**\n * Nuxt runtime plugin that:\n * 1. Server: runs the locale detection chain, stores locale in payload for hydration\n * 2. Client: reads locale from payload to avoid hydration mismatch\n * 3. Provides reactive locale state and global helpers\n */\nexport default defineNuxtPlugin(async (nuxtApp) => {\n const config = useRuntimeConfig().public['fluenti'] as FluentNuxtRuntimeConfig\n const route = useRoute()\n\n // Hoist useCookie calls BEFORE any await to avoid losing the Nuxt\n // composable context (async local storage is dropped after await).\n const cookieCfg = config.detectBrowserLanguage?.useCookie\n ? config.detectBrowserLanguage\n : null\n const cookieKey = cookieCfg?.cookieKey ?? 'fluenti_locale'\n const localeCookie = cookieCfg ? useCookie(cookieKey) : null\n\n let detectedLocale: string\n\n if (import.meta.server) {\n // --- Server (SSR / SSG / ISR): run full detection chain ---\n detectedLocale = await runDetectors(\n route.path,\n config,\n undefined,\n async (ctx: LocaleDetectContext) => {\n await (nuxtApp.callHook as Function)('fluenti:detect-locale', ctx)\n },\n )\n // Store in payload — Nuxt serializes this to HTML automatically.\n // The client reads it back to ensure hydration uses the same locale.\n nuxtApp.payload['fluentiLocale'] = detectedLocale\n } else if (nuxtApp.payload['fluentiLocale']) {\n // --- Client (SSR hydration): read from payload to avoid mismatch ---\n detectedLocale = nuxtApp.payload['fluentiLocale'] as string\n } else {\n // --- Client (SPA mode / no payload): detect from path and cookie ---\n const { locale: pathLocale } = extractLocaleFromPath(route.path, config.locales)\n
|
|
1
|
+
{"version":3,"file":"plugin.js","names":[],"sources":["../../src/runtime/plugin.ts"],"sourcesContent":["import { defineNuxtPlugin, useRuntimeConfig, useRoute, useCookie, useRequestHeaders } from '#imports'\nimport { ref, watch } from 'vue'\nimport { localePath, extractLocaleFromPath, switchLocalePath } from './path-utils'\nimport { runDetectors } from './detectors'\nimport type { FluentNuxtRuntimeConfig, LocaleDetectContext } from '../types'\n\n/**\n * Nuxt runtime plugin that:\n * 1. Server: runs the locale detection chain, stores locale in payload for hydration\n * 2. Client: reads locale from payload to avoid hydration mismatch\n * 3. Provides reactive locale state and global helpers\n */\nexport default defineNuxtPlugin(async (nuxtApp) => {\n const config = useRuntimeConfig().public['fluenti'] as FluentNuxtRuntimeConfig\n const route = useRoute()\n\n // Hoist useCookie calls BEFORE any await to avoid losing the Nuxt\n // composable context (async local storage is dropped after await).\n const cookieCfg = config.detectBrowserLanguage?.useCookie\n ? config.detectBrowserLanguage\n : null\n const cookieKey = cookieCfg?.cookieKey ?? 'fluenti_locale'\n const localeCookie = cookieCfg ? useCookie(cookieKey) : null\n\n // Hoist all server-side header/cookie reads BEFORE any await.\n // Nuxt composables rely on async local storage that is dropped after await.\n let host: string | undefined\n let acceptLanguage: string | undefined\n if (import.meta.server) {\n try {\n const reqHeaders = useRequestHeaders(['host', 'accept-language'])\n acceptLanguage = reqHeaders['accept-language']\n if (config.strategy === 'domains') {\n host = reqHeaders['host']\n }\n } catch (err) {\n if (import.meta.dev) console.debug('[fluenti] Header read failed:', err)\n }\n } else if (config.strategy === 'domains') {\n try {\n host = window.location.host\n } catch (err) {\n if (import.meta.dev) console.debug('[fluenti] Domain detection failed:', err)\n }\n }\n\n let detectedLocale: string\n\n if (import.meta.server) {\n // --- Server (SSR / SSG / ISR): run full detection chain ---\n detectedLocale = await runDetectors(\n route.path,\n config,\n undefined,\n async (ctx: LocaleDetectContext) => {\n await (nuxtApp.callHook as Function)('fluenti:detect-locale', ctx)\n },\n host,\n localeCookie?.value ?? undefined,\n acceptLanguage,\n )\n // Store in payload — Nuxt serializes this to HTML automatically.\n // The client reads it back to ensure hydration uses the same locale.\n nuxtApp.payload['fluentiLocale'] = detectedLocale\n // Also set on event context so other plugins (e.g. i18n.ts) can read it\n try {\n const event = (nuxtApp as unknown as { ssrContext?: { event?: { context: Record<string, unknown> } } }).ssrContext?.event\n if (event) event.context['locale'] = detectedLocale\n } catch (err) {\n if (import.meta.dev) console.debug('[fluenti] Event context not available:', err)\n }\n } else if (nuxtApp.payload['fluentiLocale']) {\n // --- Client (SSR hydration): read from payload to avoid mismatch ---\n detectedLocale = nuxtApp.payload['fluentiLocale'] as string\n } else {\n // --- Client (SPA mode / no payload): detect from path and cookie ---\n if (config.strategy === 'domains' && host && config.domains?.length) {\n const cleanHost = host.toLowerCase().replace(/:\\d+$/, '')\n const domainMatch = config.domains.find((d) => d.domain.toLowerCase() === cleanHost)\n if (domainMatch) {\n detectedLocale = domainMatch.locale\n } else {\n detectedLocale = config.defaultLocale\n }\n } else {\n const { locale: pathLocale } = extractLocaleFromPath(route.path, config.locales)\n if (pathLocale) {\n detectedLocale = pathLocale\n } else if (localeCookie) {\n detectedLocale = (localeCookie.value && config.locales.includes(localeCookie.value))\n ? localeCookie.value\n : config.defaultLocale\n } else {\n detectedLocale = config.defaultLocale\n }\n }\n }\n\n const currentLocale = ref(detectedLocale)\n\n // Sync locale when route changes (path-based detection)\n if (config.strategy !== 'no_prefix' && config.strategy !== 'domains') {\n watch(() => route.path, (newPath) => {\n const { locale } = extractLocaleFromPath(newPath, config.locales)\n if (locale) {\n currentLocale.value = locale\n } else if (config.strategy === 'prefix_except_default') {\n // No locale prefix found — this means we're on a default locale route\n currentLocale.value = config.defaultLocale\n }\n })\n }\n\n // Persist locale in cookie if detectBrowserLanguage is configured\n if (localeCookie) {\n watch(currentLocale, (newLocale) => {\n localeCookie.value = newLocale\n })\n }\n\n // --- Inject global helpers ---\n if (config.injectGlobalProperties) {\n const gp = nuxtApp.vueApp.config.globalProperties\n gp.$localePath = (path: string, locale?: string) => {\n return localePath(\n path,\n locale ?? currentLocale.value,\n config.defaultLocale,\n config.strategy,\n )\n }\n gp.$switchLocalePath = (newLocale: string) => {\n return switchLocalePath(\n route.path,\n newLocale,\n config.locales,\n config.defaultLocale,\n config.strategy,\n )\n }\n\n // Inject $t, $d, $n if @fluenti/vue plugin hasn't already injected them\n // (the Vue plugin handles injection when installed directly, but in Nuxt\n // the module may load before the Vue plugin is installed)\n try {\n const { useI18n } = await import('@fluenti/vue')\n const ctx = useI18n()\n if (!gp['$t']) gp['$t'] = ctx.t\n if (!gp['$d']) gp['$d'] = ctx.d\n if (!gp['$n']) gp['$n'] = ctx.n\n } catch (err) {\n // @fluenti/vue plugin not yet installed — $t/$d/$n will be provided by it\n if (import.meta.dev) console.debug('[fluenti] Vue plugin not yet installed, skipping $t/$d/$n injection:', err)\n }\n }\n\n return {\n provide: {\n fluentiLocale: currentLocale,\n fluentiConfig: config,\n },\n }\n})\n"],"mappings":";;;;;AAYA,IAAA,IAAe,EAAiB,OAAO,MAAY;CACjD,IAAM,IAAS,GAAkB,CAAC,OAAO,SACnC,IAAQ,GAAU,EAIlB,IAAY,EAAO,uBAAuB,YAC5C,EAAO,wBACP,MACE,IAAY,GAAW,aAAa,kBACpC,IAAe,IAAY,EAAU,EAAU,GAAG,MAIpD,GACA;AACJ,KAAI,OAAO,KAAK,OACd,KAAI;EACF,IAAM,IAAa,EAAkB,CAAC,QAAQ,kBAAkB,CAAC;AAEjE,EADA,IAAiB,EAAW,oBACxB,EAAO,aAAa,cACtB,IAAO,EAAW;UAEb,GAAK;AACZ,EAAI,OAAO,KAAK,OAAK,QAAQ,MAAM,iCAAiC,EAAI;;UAEjE,EAAO,aAAa,UAC7B,KAAI;AACF,MAAO,OAAO,SAAS;UAChB,GAAK;AACZ,EAAI,OAAO,KAAK,OAAK,QAAQ,MAAM,sCAAsC,EAAI;;CAIjF,IAAI;AAEJ,KAAI,OAAO,KAAK,QAAQ;AAetB,EAbA,IAAiB,MAAM,EACrB,EAAM,MACN,GACA,KAAA,GACA,OAAO,MAA6B;AAClC,SAAO,EAAQ,SAAsB,yBAAyB,EAAI;KAEpE,GACA,GAAc,SAAS,KAAA,GACvB,EACD,EAGD,EAAQ,QAAQ,gBAAmB;AAEnC,MAAI;GACF,IAAM,IAAS,EAAyF,YAAY;AACpH,GAAI,MAAO,EAAM,QAAQ,SAAY;WAC9B,GAAK;AACZ,GAAI,OAAO,KAAK,OAAK,QAAQ,MAAM,0CAA0C,EAAI;;YAE1E,EAAQ,QAAQ,cAEzB,KAAiB,EAAQ,QAAQ;UAG7B,EAAO,aAAa,aAAa,KAAQ,EAAO,SAAS,QAAQ;EACnE,IAAM,IAAY,EAAK,aAAa,CAAC,QAAQ,SAAS,GAAG,EACnD,IAAc,EAAO,QAAQ,MAAM,MAAM,EAAE,OAAO,aAAa,KAAK,EAAU;AACpF,EAGE,IAHE,IACe,EAAY,SAEZ,EAAO;QAErB;EACL,IAAM,EAAE,QAAQ,MAAe,EAAsB,EAAM,MAAM,EAAO,QAAQ;AAChF,EAOE,IAPE,MAEO,KACS,EAAa,SAAS,EAAO,QAAQ,SAAS,EAAa,MAAM,GAC/E,EAAa,QACb,EAAO;;CAOjB,IAAM,IAAgB,EAAI,EAAe;AAuBzC,KApBI,EAAO,aAAa,eAAe,EAAO,aAAa,aACzD,QAAY,EAAM,OAAO,MAAY;EACnC,IAAM,EAAE,cAAW,EAAsB,GAAS,EAAO,QAAQ;AACjE,EAAI,IACF,EAAc,QAAQ,IACb,EAAO,aAAa,4BAE7B,EAAc,QAAQ,EAAO;GAE/B,EAIA,KACF,EAAM,IAAgB,MAAc;AAClC,IAAa,QAAQ;GACrB,EAIA,EAAO,wBAAwB;EACjC,IAAM,IAAK,EAAQ,OAAO,OAAO;AASjC,EARA,EAAG,eAAe,GAAc,MACvB,EACL,GACA,KAAU,EAAc,OACxB,EAAO,eACP,EAAO,SACR,EAEH,EAAG,qBAAqB,MACf,EACL,EAAM,MACN,GACA,EAAO,SACP,EAAO,eACP,EAAO,SACR;AAMH,MAAI;GACF,IAAM,EAAE,eAAY,MAAM,OAAO,iBAC3B,IAAM,GAAS;AAGrB,GAFA,AAAe,EAAG,OAAQ,EAAI,GAC9B,AAAe,EAAG,OAAQ,EAAI,GAC9B,AAAe,EAAG,OAAQ,EAAI;WACvB,GAAK;AAEZ,GAAI,OAAO,KAAK,OAAK,QAAQ,MAAM,wEAAwE,EAAI;;;AAInH,QAAO,EACL,SAAS;EACP,eAAe;EACf,eAAe;EAChB,EACF;EACD"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
require(`../../module.cjs`);let e=require(`h3`);var t=(0,e.defineEventHandler)(t=>{let i=t.path??`/`;if(i.startsWith(`/_nuxt/`)||i.startsWith(`/api/`)||i.startsWith(`/__nuxt`)||/\.\w{2,5}$/.test(i))return;let a=t.context.__fluenti_config??r(t);if(!a||a.strategy!==`prefix`&&a.strategy!==`prefix_and_default`)return;let o=i.split(`/`).filter(Boolean)[0];if(o&&a.locales.includes(o))return;let s=a.defaultLocale,c=a.queryParamKey??`locale`,l=(0,e.getQuery)(t)[c];if(typeof l==`string`&&a.locales.includes(l)&&(s=l),!l){let n=(0,e.getCookie)(t,a.detectBrowserLanguage?.cookieKey??`fluenti_locale`);n&&a.locales.includes(n)&&(s=n)}if(!l){let r=(0,e.getHeader)(t,`accept-language`);if(r){let e=n(r,a.locales);e&&(s=e)}}return(0,e.sendRedirect)(t,`/${s}${i===`/`?``:i}`,302)});function n(e,t){let n=e.split(`,`).map(e=>{let[t=``,n=``]=e.trim().split(`;q=`);return{lang:t.trim().toLowerCase(),quality:n?parseFloat(n):1}}).filter(e=>e.quality>0).sort((e,t)=>t.quality-e.quality);for(let e of n){let n=t.find(t=>t.toLowerCase()===e.lang);if(n)return n;let r=t.find(t=>t.toLowerCase().startsWith(e.lang)||e.lang.startsWith(t.toLowerCase()));if(r)return r}return null}function r(e){try{let t=(((e.context.nitro??e.context.__nitro)?.runtimeConfig??{}).public??{}).fluenti;return t&&(e.context.__fluenti_config=t),t}catch{return}}module.exports=t;
|
|
2
|
+
//# sourceMappingURL=locale-redirect.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale-redirect.cjs","names":[],"sources":["../../../src/runtime/server/locale-redirect.ts"],"sourcesContent":["import { defineEventHandler, sendRedirect, getHeader, getCookie, getQuery } from 'h3'\n\n/**\n * Nitro server middleware for locale-based redirects.\n *\n * Runs at the Nitro layer (before Vue Router), which is earlier in the\n * request lifecycle. This prevents any flash of wrong-locale content\n * during SSR, as the redirect happens before page rendering starts.\n *\n * Only active when strategy is 'prefix' or 'prefix_and_default'.\n */\nexport default defineEventHandler((event) => {\n const url = event.path ?? '/'\n\n // Skip non-page requests (assets, API routes, etc.)\n if (url.startsWith('/_nuxt/') || url.startsWith('/api/') || url.startsWith('/__nuxt')) {\n return\n }\n\n // Skip if URL already has a file extension (static assets)\n if (/\\.\\w{2,5}$/.test(url)) {\n return\n }\n\n // Read config from runtime config\n const config = (event.context['__fluenti_config'] ??\n useRuntimeConfigFromEvent(event)) as {\n locales: string[]\n defaultLocale: string\n strategy: string\n detectOrder?: string[]\n queryParamKey?: string\n detectBrowserLanguage?: { useCookie?: boolean; cookieKey?: string; fallbackLocale?: string }\n } | undefined\n\n if (!config) return\n\n // Only handle prefix/prefix_and_default strategies\n if (config.strategy !== 'prefix' && config.strategy !== 'prefix_and_default') {\n return\n }\n\n // Check if the URL already has a locale prefix\n const pathSegments = url.split('/').filter(Boolean)\n const firstSegment = pathSegments[0]\n\n if (firstSegment && config.locales.includes(firstSegment)) {\n // URL already has a valid locale prefix\n return\n }\n\n // For prefix_and_default, unprefixed URLs are allowed for the default locale\n // (they will be served without redirect)\n // For prefix strategy, we must redirect\n\n // Detect locale from various sources\n let detectedLocale = config.defaultLocale\n\n // 1. Query parameter\n const queryKey = config.queryParamKey ?? 'locale'\n const query = getQuery(event)\n const queryLocale = query[queryKey]\n if (typeof queryLocale === 'string' && config.locales.includes(queryLocale)) {\n detectedLocale = queryLocale\n }\n\n // 2. Cookie\n if (!queryLocale) {\n const cookieKey = config.detectBrowserLanguage?.cookieKey ?? 'fluenti_locale'\n const cookieLocale = getCookie(event, cookieKey)\n if (cookieLocale && config.locales.includes(cookieLocale)) {\n detectedLocale = cookieLocale\n }\n }\n\n // 3. Accept-Language header\n if (!queryLocale) {\n const acceptLang = getHeader(event, 'accept-language')\n if (acceptLang) {\n const preferred = parseAcceptLanguage(acceptLang, config.locales)\n if (preferred) {\n detectedLocale = preferred\n }\n }\n }\n\n // Redirect to locale-prefixed URL\n const cleanUrl = url === '/' ? '' : url\n const redirectUrl = `/${detectedLocale}${cleanUrl}`\n\n return sendRedirect(event, redirectUrl, 302)\n})\n\n/**\n * Parse Accept-Language header and find the best matching locale.\n */\nfunction parseAcceptLanguage(header: string, locales: string[]): string | null {\n const entries = header\n .split(',')\n .map((part) => {\n const [lang = '', q = ''] = part.trim().split(';q=')\n return {\n lang: lang!.trim().toLowerCase(),\n quality: q ? parseFloat(q) : 1.0,\n }\n })\n .filter((e) => e.quality > 0)\n .sort((a, b) => b.quality - a.quality)\n\n for (const entry of entries) {\n // Exact match\n const exact = locales.find((l) => l.toLowerCase() === entry.lang)\n if (exact) return exact\n\n // Prefix match (e.g., 'en' matches 'en-US')\n const prefix = locales.find(\n (l) => l.toLowerCase().startsWith(entry.lang) || entry.lang.startsWith(l.toLowerCase()),\n )\n if (prefix) return prefix\n }\n\n return null\n}\n\n/**\n * Read Fluenti runtime config from the event context.\n */\nfunction useRuntimeConfigFromEvent(event: { context: Record<string, unknown> }) {\n try {\n const nitroConfig = (event.context['nitro'] ?? event.context['__nitro']) as Record<string, unknown> | undefined\n const runtimeConfig = (nitroConfig?.['runtimeConfig'] ?? {}) as Record<string, unknown>\n const publicConfig = (runtimeConfig['public'] ?? {}) as Record<string, unknown>\n const fluentiConfig = publicConfig['fluenti']\n if (fluentiConfig) {\n event.context['__fluenti_config'] = fluentiConfig\n }\n return fluentiConfig\n } catch {\n return undefined\n }\n}\n"],"mappings":"gDAWA,IAAA,GAAA,EAAA,EAAA,oBAAmC,GAAU,CAC3C,IAAM,EAAM,EAAM,MAAQ,IAQ1B,GALI,EAAI,WAAW,UAAU,EAAI,EAAI,WAAW,QAAQ,EAAI,EAAI,WAAW,UAAU,EAKjF,aAAa,KAAK,EAAI,CACxB,OAIF,IAAM,EAAU,EAAM,QAAQ,kBAC5B,EAA0B,EAAM,CAYlC,GAHI,CAAC,GAGD,EAAO,WAAa,UAAY,EAAO,WAAa,qBACtD,OAKF,IAAM,EADe,EAAI,MAAM,IAAI,CAAC,OAAO,QAAQ,CACjB,GAElC,GAAI,GAAgB,EAAO,QAAQ,SAAS,EAAa,CAEvD,OAQF,IAAI,EAAiB,EAAO,cAGtB,EAAW,EAAO,eAAiB,SAEnC,GAAA,EAAA,EAAA,UADiB,EAAM,CACH,GAM1B,GALI,OAAO,GAAgB,UAAY,EAAO,QAAQ,SAAS,EAAY,GACzE,EAAiB,GAIf,CAAC,EAAa,CAEhB,IAAM,GAAA,EAAA,EAAA,WAAyB,EADb,EAAO,uBAAuB,WAAa,iBACb,CAC5C,GAAgB,EAAO,QAAQ,SAAS,EAAa,GACvD,EAAiB,GAKrB,GAAI,CAAC,EAAa,CAChB,IAAM,GAAA,EAAA,EAAA,WAAuB,EAAO,kBAAkB,CACtD,GAAI,EAAY,CACd,IAAM,EAAY,EAAoB,EAAY,EAAO,QAAQ,CAC7D,IACF,EAAiB,IASvB,OAAA,EAAA,EAAA,cAAoB,EAFA,IAAI,IADP,IAAQ,IAAM,GAAK,IAGI,IAAI,EAC5C,CAKF,SAAS,EAAoB,EAAgB,EAAkC,CAC7E,IAAM,EAAU,EACb,MAAM,IAAI,CACV,IAAK,GAAS,CACb,GAAM,CAAC,EAAO,GAAI,EAAI,IAAM,EAAK,MAAM,CAAC,MAAM,MAAM,CACpD,MAAO,CACL,KAAM,EAAM,MAAM,CAAC,aAAa,CAChC,QAAS,EAAI,WAAW,EAAE,CAAG,EAC9B,EACD,CACD,OAAQ,GAAM,EAAE,QAAU,EAAE,CAC5B,MAAM,EAAG,IAAM,EAAE,QAAU,EAAE,QAAQ,CAExC,IAAK,IAAM,KAAS,EAAS,CAE3B,IAAM,EAAQ,EAAQ,KAAM,GAAM,EAAE,aAAa,GAAK,EAAM,KAAK,CACjE,GAAI,EAAO,OAAO,EAGlB,IAAM,EAAS,EAAQ,KACpB,GAAM,EAAE,aAAa,CAAC,WAAW,EAAM,KAAK,EAAI,EAAM,KAAK,WAAW,EAAE,aAAa,CAAC,CACxF,CACD,GAAI,EAAQ,OAAO,EAGrB,OAAO,KAMT,SAAS,EAA0B,EAA6C,CAC9E,GAAI,CAIF,IAAM,KAHe,EAAM,QAAQ,OAAY,EAAM,QAAQ,UACxB,eAAoB,EAAE,EACvB,QAAa,EAAE,EAChB,QAInC,OAHI,IACF,EAAM,QAAQ,iBAAsB,GAE/B,OACD,CACN"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nitro server middleware for locale-based redirects.
|
|
3
|
+
*
|
|
4
|
+
* Runs at the Nitro layer (before Vue Router), which is earlier in the
|
|
5
|
+
* request lifecycle. This prevents any flash of wrong-locale content
|
|
6
|
+
* during SSR, as the redirect happens before page rendering starts.
|
|
7
|
+
*
|
|
8
|
+
* Only active when strategy is 'prefix' or 'prefix_and_default'.
|
|
9
|
+
*/
|
|
10
|
+
declare const _default: unknown;
|
|
11
|
+
export default _default;
|
|
12
|
+
//# sourceMappingURL=locale-redirect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale-redirect.d.ts","sourceRoot":"","sources":["../../../src/runtime/server/locale-redirect.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;;AACH,wBAgFE"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { defineEventHandler as e, getCookie as t, getHeader as n, getQuery as r, sendRedirect as i } from "h3";
|
|
2
|
+
//#region src/runtime/server/locale-redirect.ts
|
|
3
|
+
var a = e((e) => {
|
|
4
|
+
let a = e.path ?? "/";
|
|
5
|
+
if (a.startsWith("/_nuxt/") || a.startsWith("/api/") || a.startsWith("/__nuxt") || /\.\w{2,5}$/.test(a)) return;
|
|
6
|
+
let c = e.context.__fluenti_config ?? s(e);
|
|
7
|
+
if (!c || c.strategy !== "prefix" && c.strategy !== "prefix_and_default") return;
|
|
8
|
+
let l = a.split("/").filter(Boolean)[0];
|
|
9
|
+
if (l && c.locales.includes(l)) return;
|
|
10
|
+
let u = c.defaultLocale, d = c.queryParamKey ?? "locale", f = r(e)[d];
|
|
11
|
+
if (typeof f == "string" && c.locales.includes(f) && (u = f), !f) {
|
|
12
|
+
let n = t(e, c.detectBrowserLanguage?.cookieKey ?? "fluenti_locale");
|
|
13
|
+
n && c.locales.includes(n) && (u = n);
|
|
14
|
+
}
|
|
15
|
+
if (!f) {
|
|
16
|
+
let t = n(e, "accept-language");
|
|
17
|
+
if (t) {
|
|
18
|
+
let e = o(t, c.locales);
|
|
19
|
+
e && (u = e);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return i(e, `/${u}${a === "/" ? "" : a}`, 302);
|
|
23
|
+
});
|
|
24
|
+
function o(e, t) {
|
|
25
|
+
let n = e.split(",").map((e) => {
|
|
26
|
+
let [t = "", n = ""] = e.trim().split(";q=");
|
|
27
|
+
return {
|
|
28
|
+
lang: t.trim().toLowerCase(),
|
|
29
|
+
quality: n ? parseFloat(n) : 1
|
|
30
|
+
};
|
|
31
|
+
}).filter((e) => e.quality > 0).sort((e, t) => t.quality - e.quality);
|
|
32
|
+
for (let e of n) {
|
|
33
|
+
let n = t.find((t) => t.toLowerCase() === e.lang);
|
|
34
|
+
if (n) return n;
|
|
35
|
+
let r = t.find((t) => t.toLowerCase().startsWith(e.lang) || e.lang.startsWith(t.toLowerCase()));
|
|
36
|
+
if (r) return r;
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
function s(e) {
|
|
41
|
+
try {
|
|
42
|
+
let t = (((e.context.nitro ?? e.context.__nitro)?.runtimeConfig ?? {}).public ?? {}).fluenti;
|
|
43
|
+
return t && (e.context.__fluenti_config = t), t;
|
|
44
|
+
} catch {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//#endregion
|
|
49
|
+
export { a as default };
|
|
50
|
+
|
|
51
|
+
//# sourceMappingURL=locale-redirect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale-redirect.js","names":[],"sources":["../../../src/runtime/server/locale-redirect.ts"],"sourcesContent":["import { defineEventHandler, sendRedirect, getHeader, getCookie, getQuery } from 'h3'\n\n/**\n * Nitro server middleware for locale-based redirects.\n *\n * Runs at the Nitro layer (before Vue Router), which is earlier in the\n * request lifecycle. This prevents any flash of wrong-locale content\n * during SSR, as the redirect happens before page rendering starts.\n *\n * Only active when strategy is 'prefix' or 'prefix_and_default'.\n */\nexport default defineEventHandler((event) => {\n const url = event.path ?? '/'\n\n // Skip non-page requests (assets, API routes, etc.)\n if (url.startsWith('/_nuxt/') || url.startsWith('/api/') || url.startsWith('/__nuxt')) {\n return\n }\n\n // Skip if URL already has a file extension (static assets)\n if (/\\.\\w{2,5}$/.test(url)) {\n return\n }\n\n // Read config from runtime config\n const config = (event.context['__fluenti_config'] ??\n useRuntimeConfigFromEvent(event)) as {\n locales: string[]\n defaultLocale: string\n strategy: string\n detectOrder?: string[]\n queryParamKey?: string\n detectBrowserLanguage?: { useCookie?: boolean; cookieKey?: string; fallbackLocale?: string }\n } | undefined\n\n if (!config) return\n\n // Only handle prefix/prefix_and_default strategies\n if (config.strategy !== 'prefix' && config.strategy !== 'prefix_and_default') {\n return\n }\n\n // Check if the URL already has a locale prefix\n const pathSegments = url.split('/').filter(Boolean)\n const firstSegment = pathSegments[0]\n\n if (firstSegment && config.locales.includes(firstSegment)) {\n // URL already has a valid locale prefix\n return\n }\n\n // For prefix_and_default, unprefixed URLs are allowed for the default locale\n // (they will be served without redirect)\n // For prefix strategy, we must redirect\n\n // Detect locale from various sources\n let detectedLocale = config.defaultLocale\n\n // 1. Query parameter\n const queryKey = config.queryParamKey ?? 'locale'\n const query = getQuery(event)\n const queryLocale = query[queryKey]\n if (typeof queryLocale === 'string' && config.locales.includes(queryLocale)) {\n detectedLocale = queryLocale\n }\n\n // 2. Cookie\n if (!queryLocale) {\n const cookieKey = config.detectBrowserLanguage?.cookieKey ?? 'fluenti_locale'\n const cookieLocale = getCookie(event, cookieKey)\n if (cookieLocale && config.locales.includes(cookieLocale)) {\n detectedLocale = cookieLocale\n }\n }\n\n // 3. Accept-Language header\n if (!queryLocale) {\n const acceptLang = getHeader(event, 'accept-language')\n if (acceptLang) {\n const preferred = parseAcceptLanguage(acceptLang, config.locales)\n if (preferred) {\n detectedLocale = preferred\n }\n }\n }\n\n // Redirect to locale-prefixed URL\n const cleanUrl = url === '/' ? '' : url\n const redirectUrl = `/${detectedLocale}${cleanUrl}`\n\n return sendRedirect(event, redirectUrl, 302)\n})\n\n/**\n * Parse Accept-Language header and find the best matching locale.\n */\nfunction parseAcceptLanguage(header: string, locales: string[]): string | null {\n const entries = header\n .split(',')\n .map((part) => {\n const [lang = '', q = ''] = part.trim().split(';q=')\n return {\n lang: lang!.trim().toLowerCase(),\n quality: q ? parseFloat(q) : 1.0,\n }\n })\n .filter((e) => e.quality > 0)\n .sort((a, b) => b.quality - a.quality)\n\n for (const entry of entries) {\n // Exact match\n const exact = locales.find((l) => l.toLowerCase() === entry.lang)\n if (exact) return exact\n\n // Prefix match (e.g., 'en' matches 'en-US')\n const prefix = locales.find(\n (l) => l.toLowerCase().startsWith(entry.lang) || entry.lang.startsWith(l.toLowerCase()),\n )\n if (prefix) return prefix\n }\n\n return null\n}\n\n/**\n * Read Fluenti runtime config from the event context.\n */\nfunction useRuntimeConfigFromEvent(event: { context: Record<string, unknown> }) {\n try {\n const nitroConfig = (event.context['nitro'] ?? event.context['__nitro']) as Record<string, unknown> | undefined\n const runtimeConfig = (nitroConfig?.['runtimeConfig'] ?? {}) as Record<string, unknown>\n const publicConfig = (runtimeConfig['public'] ?? {}) as Record<string, unknown>\n const fluentiConfig = publicConfig['fluenti']\n if (fluentiConfig) {\n event.context['__fluenti_config'] = fluentiConfig\n }\n return fluentiConfig\n } catch {\n return undefined\n }\n}\n"],"mappings":";;AAWA,IAAA,IAAe,GAAoB,MAAU;CAC3C,IAAM,IAAM,EAAM,QAAQ;AAQ1B,KALI,EAAI,WAAW,UAAU,IAAI,EAAI,WAAW,QAAQ,IAAI,EAAI,WAAW,UAAU,IAKjF,aAAa,KAAK,EAAI,CACxB;CAIF,IAAM,IAAU,EAAM,QAAQ,oBAC5B,EAA0B,EAAM;AAYlC,KAHI,CAAC,KAGD,EAAO,aAAa,YAAY,EAAO,aAAa,qBACtD;CAKF,IAAM,IADe,EAAI,MAAM,IAAI,CAAC,OAAO,QAAQ,CACjB;AAElC,KAAI,KAAgB,EAAO,QAAQ,SAAS,EAAa,CAEvD;CAQF,IAAI,IAAiB,EAAO,eAGtB,IAAW,EAAO,iBAAiB,UAEnC,IADQ,EAAS,EAAM,CACH;AAM1B,KALI,OAAO,KAAgB,YAAY,EAAO,QAAQ,SAAS,EAAY,KACzE,IAAiB,IAIf,CAAC,GAAa;EAEhB,IAAM,IAAe,EAAU,GADb,EAAO,uBAAuB,aAAa,iBACb;AAChD,EAAI,KAAgB,EAAO,QAAQ,SAAS,EAAa,KACvD,IAAiB;;AAKrB,KAAI,CAAC,GAAa;EAChB,IAAM,IAAa,EAAU,GAAO,kBAAkB;AACtD,MAAI,GAAY;GACd,IAAM,IAAY,EAAoB,GAAY,EAAO,QAAQ;AACjE,GAAI,MACF,IAAiB;;;AASvB,QAAO,EAAa,GAFA,IAAI,IADP,MAAQ,MAAM,KAAK,KAGI,IAAI;EAC5C;AAKF,SAAS,EAAoB,GAAgB,GAAkC;CAC7E,IAAM,IAAU,EACb,MAAM,IAAI,CACV,KAAK,MAAS;EACb,IAAM,CAAC,IAAO,IAAI,IAAI,MAAM,EAAK,MAAM,CAAC,MAAM,MAAM;AACpD,SAAO;GACL,MAAM,EAAM,MAAM,CAAC,aAAa;GAChC,SAAS,IAAI,WAAW,EAAE,GAAG;GAC9B;GACD,CACD,QAAQ,MAAM,EAAE,UAAU,EAAE,CAC5B,MAAM,GAAG,MAAM,EAAE,UAAU,EAAE,QAAQ;AAExC,MAAK,IAAM,KAAS,GAAS;EAE3B,IAAM,IAAQ,EAAQ,MAAM,MAAM,EAAE,aAAa,KAAK,EAAM,KAAK;AACjE,MAAI,EAAO,QAAO;EAGlB,IAAM,IAAS,EAAQ,MACpB,MAAM,EAAE,aAAa,CAAC,WAAW,EAAM,KAAK,IAAI,EAAM,KAAK,WAAW,EAAE,aAAa,CAAC,CACxF;AACD,MAAI,EAAQ,QAAO;;AAGrB,QAAO;;AAMT,SAAS,EAA0B,GAA6C;AAC9E,KAAI;EAIF,IAAM,OAHe,EAAM,QAAQ,SAAY,EAAM,QAAQ,UACxB,iBAAoB,EAAE,EACvB,UAAa,EAAE,EAChB;AAInC,SAHI,MACF,EAAM,QAAQ,mBAAsB,IAE/B;SACD;AACN"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../path-utils-BQIsp_or.cjs`),t=require(`../locale-head-D1NAUQc8.cjs`);require(`../module.cjs`);let n=require(`vue`);function r(t,n){return(r,i)=>e.n(r,i??t.value,n.defaultLocale,n.strategy)}function i(t,n){return r=>e.r(t.value,r,n.locales,n.defaultLocale,n.strategy)}function a(t,n,r){return(i,a)=>{let o=a??t.value;if(typeof i==`string`){let t=e.n(i,o,r.defaultLocale,r.strategy);return n.resolve(t)}if(`path`in i&&i.path){let t=e.n(i.path,o,r.defaultLocale,r.strategy);return n.resolve({...i,path:t})}return n.resolve(i)}}function o(e,r,i,a){return(0,n.computed)(()=>t.t(e.value,r.value,i,a))}exports.useLocaleHead=o,exports.useLocalePath=r,exports.useLocaleRoute=a,exports.useSwitchLocalePath=i;
|
|
2
|
+
//# sourceMappingURL=standalone-composables.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standalone-composables.cjs","names":[],"sources":["../../src/runtime/standalone-composables.ts"],"sourcesContent":["import { computed } from 'vue'\nimport type { ComputedRef, Ref } from 'vue'\nimport type { RouteLocationRaw, RouteLocationResolved, Router } from 'vue-router'\nimport { localePath, switchLocalePath } from './path-utils'\nimport type { FluentNuxtRuntimeConfig } from '../types'\nimport type { LocaleHeadMeta, LocaleHeadOptions } from './locale-head'\nimport { buildLocaleHead } from './locale-head'\n\n/**\n * Standalone composable for locale-prefixed paths (no Nuxt dependency).\n * Accepts explicit locale ref and config instead of reading from Nuxt context.\n */\nexport function useLocalePath(\n locale: Ref<string>,\n config: FluentNuxtRuntimeConfig,\n): (path: string, targetLocale?: string) => string {\n return (path: string, targetLocale?: string) => {\n return localePath(\n path,\n targetLocale ?? locale.value,\n config.defaultLocale,\n config.strategy,\n )\n }\n}\n\n/**\n * Standalone composable for switch-locale paths (no Nuxt dependency).\n * Accepts explicit current path ref and config.\n */\nexport function useSwitchLocalePath(\n currentPath: Ref<string>,\n config: FluentNuxtRuntimeConfig,\n): (locale: string) => string {\n return (newLocale: string) => {\n return switchLocalePath(\n currentPath.value,\n newLocale,\n config.locales,\n config.defaultLocale,\n config.strategy,\n )\n }\n}\n\n/**\n * Standalone composable for locale route resolution (no Nuxt dependency).\n * Accepts explicit locale ref, router, and config.\n */\nexport function useLocaleRoute(\n locale: Ref<string>,\n router: Router,\n config: FluentNuxtRuntimeConfig,\n): (to: RouteLocationRaw, targetLocale?: string) => RouteLocationResolved {\n return (to: RouteLocationRaw, targetLocale?: string) => {\n const resolvedLocale = targetLocale ?? locale.value\n if (typeof to === 'string') {\n const path = localePath(to, resolvedLocale, config.defaultLocale, config.strategy)\n return router.resolve(path)\n }\n if ('path' in to && to.path) {\n const path = localePath(to.path, resolvedLocale, config.defaultLocale, config.strategy)\n return router.resolve({ ...to, path })\n }\n return router.resolve(to)\n }\n}\n\n/**\n * Standalone composable for locale-aware head metadata (no Nuxt dependency).\n * Accepts explicit locale, path, and config refs.\n */\nexport function useLocaleHead(\n locale: Ref<string>,\n currentPath: Ref<string>,\n config: FluentNuxtRuntimeConfig,\n options?: LocaleHeadOptions,\n): ComputedRef<LocaleHeadMeta> {\n return computed(() => {\n return buildLocaleHead(locale.value, currentPath.value, config, options)\n })\n}\n"],"mappings":"wMAYA,SAAgB,EACd,EACA,EACiD,CACjD,OAAQ,EAAc,IACb,EAAA,EACL,EACA,GAAgB,EAAO,MACvB,EAAO,cACP,EAAO,SACR,CAQL,SAAgB,EACd,EACA,EAC4B,CAC5B,MAAQ,IACC,EAAA,EACL,EAAY,MACZ,EACA,EAAO,QACP,EAAO,cACP,EAAO,SACR,CAQL,SAAgB,EACd,EACA,EACA,EACwE,CACxE,OAAQ,EAAsB,IAA0B,CACtD,IAAM,EAAiB,GAAgB,EAAO,MAC9C,GAAI,OAAO,GAAO,SAAU,CAC1B,IAAM,EAAO,EAAA,EAAW,EAAI,EAAgB,EAAO,cAAe,EAAO,SAAS,CAClF,OAAO,EAAO,QAAQ,EAAK,CAE7B,GAAI,SAAU,GAAM,EAAG,KAAM,CAC3B,IAAM,EAAO,EAAA,EAAW,EAAG,KAAM,EAAgB,EAAO,cAAe,EAAO,SAAS,CACvF,OAAO,EAAO,QAAQ,CAAE,GAAG,EAAI,OAAM,CAAC,CAExC,OAAO,EAAO,QAAQ,EAAG,EAQ7B,SAAgB,EACd,EACA,EACA,EACA,EAC6B,CAC7B,OAAA,EAAA,EAAA,cACS,EAAA,EAAgB,EAAO,MAAO,EAAY,MAAO,EAAQ,EAAQ,CACxE"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ComputedRef, Ref } from 'vue';
|
|
2
|
+
import { RouteLocationRaw, RouteLocationResolved, Router } from 'vue-router';
|
|
2
3
|
import { FluentNuxtRuntimeConfig } from '../types';
|
|
3
4
|
import { LocaleHeadMeta, LocaleHeadOptions } from './locale-head';
|
|
4
5
|
/**
|
|
@@ -11,6 +12,11 @@ export declare function useLocalePath(locale: Ref<string>, config: FluentNuxtRun
|
|
|
11
12
|
* Accepts explicit current path ref and config.
|
|
12
13
|
*/
|
|
13
14
|
export declare function useSwitchLocalePath(currentPath: Ref<string>, config: FluentNuxtRuntimeConfig): (locale: string) => string;
|
|
15
|
+
/**
|
|
16
|
+
* Standalone composable for locale route resolution (no Nuxt dependency).
|
|
17
|
+
* Accepts explicit locale ref, router, and config.
|
|
18
|
+
*/
|
|
19
|
+
export declare function useLocaleRoute(locale: Ref<string>, router: Router, config: FluentNuxtRuntimeConfig): (to: RouteLocationRaw, targetLocale?: string) => RouteLocationResolved;
|
|
14
20
|
/**
|
|
15
21
|
* Standalone composable for locale-aware head metadata (no Nuxt dependency).
|
|
16
22
|
* Accepts explicit locale, path, and config refs.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standalone-composables.d.ts","sourceRoot":"","sources":["../../src/runtime/standalone-composables.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"standalone-composables.d.ts","sourceRoot":"","sources":["../../src/runtime/standalone-composables.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAEjF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAGtE;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,EACnB,MAAM,EAAE,uBAAuB,GAC9B,CAAC,IAAI,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,KAAK,MAAM,CASjD;AAED;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,EACxB,MAAM,EAAE,uBAAuB,GAC9B,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAU5B;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,EACnB,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,uBAAuB,GAC9B,CAAC,EAAE,EAAE,gBAAgB,EAAE,YAAY,CAAC,EAAE,MAAM,KAAK,qBAAqB,CAaxE;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,EACnB,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,EACxB,MAAM,EAAE,uBAAuB,EAC/B,OAAO,CAAC,EAAE,iBAAiB,GAC1B,WAAW,CAAC,cAAc,CAAC,CAI7B"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { n as e, r as t } from "../path-utils-BcvXLCGi.js";
|
|
2
|
+
import { t as n } from "../locale-head-BuSO-fCZ.js";
|
|
3
|
+
import { computed as r } from "vue";
|
|
4
|
+
//#region src/runtime/standalone-composables.ts
|
|
5
|
+
function i(t, n) {
|
|
6
|
+
return (r, i) => e(r, i ?? t.value, n.defaultLocale, n.strategy);
|
|
7
|
+
}
|
|
8
|
+
function a(e, n) {
|
|
9
|
+
return (r) => t(e.value, r, n.locales, n.defaultLocale, n.strategy);
|
|
10
|
+
}
|
|
11
|
+
function o(t, n, r) {
|
|
12
|
+
return (i, a) => {
|
|
13
|
+
let o = a ?? t.value;
|
|
14
|
+
if (typeof i == "string") {
|
|
15
|
+
let t = e(i, o, r.defaultLocale, r.strategy);
|
|
16
|
+
return n.resolve(t);
|
|
17
|
+
}
|
|
18
|
+
if ("path" in i && i.path) {
|
|
19
|
+
let t = e(i.path, o, r.defaultLocale, r.strategy);
|
|
20
|
+
return n.resolve({
|
|
21
|
+
...i,
|
|
22
|
+
path: t
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return n.resolve(i);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function s(e, t, i, a) {
|
|
29
|
+
return r(() => n(e.value, t.value, i, a));
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { s as useLocaleHead, i as useLocalePath, o as useLocaleRoute, a as useSwitchLocalePath };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=standalone-composables.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standalone-composables.js","names":[],"sources":["../../src/runtime/standalone-composables.ts"],"sourcesContent":["import { computed } from 'vue'\nimport type { ComputedRef, Ref } from 'vue'\nimport type { RouteLocationRaw, RouteLocationResolved, Router } from 'vue-router'\nimport { localePath, switchLocalePath } from './path-utils'\nimport type { FluentNuxtRuntimeConfig } from '../types'\nimport type { LocaleHeadMeta, LocaleHeadOptions } from './locale-head'\nimport { buildLocaleHead } from './locale-head'\n\n/**\n * Standalone composable for locale-prefixed paths (no Nuxt dependency).\n * Accepts explicit locale ref and config instead of reading from Nuxt context.\n */\nexport function useLocalePath(\n locale: Ref<string>,\n config: FluentNuxtRuntimeConfig,\n): (path: string, targetLocale?: string) => string {\n return (path: string, targetLocale?: string) => {\n return localePath(\n path,\n targetLocale ?? locale.value,\n config.defaultLocale,\n config.strategy,\n )\n }\n}\n\n/**\n * Standalone composable for switch-locale paths (no Nuxt dependency).\n * Accepts explicit current path ref and config.\n */\nexport function useSwitchLocalePath(\n currentPath: Ref<string>,\n config: FluentNuxtRuntimeConfig,\n): (locale: string) => string {\n return (newLocale: string) => {\n return switchLocalePath(\n currentPath.value,\n newLocale,\n config.locales,\n config.defaultLocale,\n config.strategy,\n )\n }\n}\n\n/**\n * Standalone composable for locale route resolution (no Nuxt dependency).\n * Accepts explicit locale ref, router, and config.\n */\nexport function useLocaleRoute(\n locale: Ref<string>,\n router: Router,\n config: FluentNuxtRuntimeConfig,\n): (to: RouteLocationRaw, targetLocale?: string) => RouteLocationResolved {\n return (to: RouteLocationRaw, targetLocale?: string) => {\n const resolvedLocale = targetLocale ?? locale.value\n if (typeof to === 'string') {\n const path = localePath(to, resolvedLocale, config.defaultLocale, config.strategy)\n return router.resolve(path)\n }\n if ('path' in to && to.path) {\n const path = localePath(to.path, resolvedLocale, config.defaultLocale, config.strategy)\n return router.resolve({ ...to, path })\n }\n return router.resolve(to)\n }\n}\n\n/**\n * Standalone composable for locale-aware head metadata (no Nuxt dependency).\n * Accepts explicit locale, path, and config refs.\n */\nexport function useLocaleHead(\n locale: Ref<string>,\n currentPath: Ref<string>,\n config: FluentNuxtRuntimeConfig,\n options?: LocaleHeadOptions,\n): ComputedRef<LocaleHeadMeta> {\n return computed(() => {\n return buildLocaleHead(locale.value, currentPath.value, config, options)\n })\n}\n"],"mappings":";;;;AAYA,SAAgB,EACd,GACA,GACiD;AACjD,SAAQ,GAAc,MACb,EACL,GACA,KAAgB,EAAO,OACvB,EAAO,eACP,EAAO,SACR;;AAQL,SAAgB,EACd,GACA,GAC4B;AAC5B,SAAQ,MACC,EACL,EAAY,OACZ,GACA,EAAO,SACP,EAAO,eACP,EAAO,SACR;;AAQL,SAAgB,EACd,GACA,GACA,GACwE;AACxE,SAAQ,GAAsB,MAA0B;EACtD,IAAM,IAAiB,KAAgB,EAAO;AAC9C,MAAI,OAAO,KAAO,UAAU;GAC1B,IAAM,IAAO,EAAW,GAAI,GAAgB,EAAO,eAAe,EAAO,SAAS;AAClF,UAAO,EAAO,QAAQ,EAAK;;AAE7B,MAAI,UAAU,KAAM,EAAG,MAAM;GAC3B,IAAM,IAAO,EAAW,EAAG,MAAM,GAAgB,EAAO,eAAe,EAAO,SAAS;AACvF,UAAO,EAAO,QAAQ;IAAE,GAAG;IAAI;IAAM,CAAC;;AAExC,SAAO,EAAO,QAAQ,EAAG;;;AAQ7B,SAAgB,EACd,GACA,GACA,GACA,GAC6B;AAC7B,QAAO,QACE,EAAgB,EAAO,OAAO,EAAY,OAAO,GAAQ,EAAQ,CACxE"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Strategy } from './types';
|
|
2
|
+
export interface SitemapUrl {
|
|
3
|
+
loc: string;
|
|
4
|
+
alternatives?: Array<{
|
|
5
|
+
hreflang: string;
|
|
6
|
+
href: string;
|
|
7
|
+
}>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Generate multi-locale sitemap URLs from a list of base paths.
|
|
11
|
+
*
|
|
12
|
+
* For each base path, produces a URL entry with hreflang alternatives
|
|
13
|
+
* pointing to every locale variant. Compatible with `@nuxtjs/sitemap`'s
|
|
14
|
+
* `sources` hook format.
|
|
15
|
+
*/
|
|
16
|
+
export declare function generateSitemapUrls(paths: string[], locales: string[], defaultLocale: string, strategy: Strategy, baseUrl?: string): SitemapUrl[];
|
|
17
|
+
/**
|
|
18
|
+
* Hook handler for `@nuxtjs/sitemap`'s `sitemap:generate` hook.
|
|
19
|
+
*
|
|
20
|
+
* Transforms single-locale URLs into multi-locale entries with hreflang.
|
|
21
|
+
* Register this in your nuxt.config.ts or let the module auto-register it.
|
|
22
|
+
*/
|
|
23
|
+
export declare function createSitemapHook(locales: string[], defaultLocale: string, strategy: Strategy, baseUrl?: string): (urls: SitemapUrl[]) => SitemapUrl[];
|
|
24
|
+
//# sourceMappingURL=sitemap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sitemap.d.ts","sourceRoot":"","sources":["../src/sitemap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAA;AAEvC,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAA;IACX,YAAY,CAAC,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;CACzD;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,EAAE,EACf,OAAO,EAAE,MAAM,EAAE,EACjB,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,QAAQ,EAClB,OAAO,CAAC,EAAE,MAAM,GACf,UAAU,EAAE,CA6Bd;AAkBD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EAAE,EACjB,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,QAAQ,EAClB,OAAO,CAAC,EAAE,MAAM,IAER,MAAM,UAAU,EAAE,kBA4B3B"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
|
+
import { FluentiBuildConfig, resolveLocaleCodes } from '@fluenti/core/internal';
|
|
2
|
+
import { LocaleDefinition, LocaleObject } from '@fluenti/core';
|
|
3
|
+
export type { LocaleObject, LocaleDefinition } from '@fluenti/core';
|
|
4
|
+
export { resolveLocaleCodes };
|
|
1
5
|
/** Routing strategy for locale-prefixed URLs */
|
|
2
|
-
export type Strategy = 'prefix' | 'prefix_except_default' | 'prefix_and_default' | 'no_prefix';
|
|
6
|
+
export type Strategy = 'prefix' | 'prefix_except_default' | 'prefix_and_default' | 'no_prefix' | 'domains';
|
|
3
7
|
/** Browser language detection options */
|
|
4
8
|
export interface DetectBrowserLanguageOptions {
|
|
5
9
|
/** Use a cookie to persist the detected locale */
|
|
@@ -10,7 +14,7 @@ export interface DetectBrowserLanguageOptions {
|
|
|
10
14
|
fallbackLocale?: string;
|
|
11
15
|
}
|
|
12
16
|
/** Built-in detector names */
|
|
13
|
-
export type BuiltinDetector = 'path' | 'cookie' | 'header' | 'query';
|
|
17
|
+
export type BuiltinDetector = 'path' | 'cookie' | 'header' | 'query' | 'domain';
|
|
14
18
|
/**
|
|
15
19
|
* Context passed to locale detectors and the `fluenti:detect-locale` hook.
|
|
16
20
|
*
|
|
@@ -34,6 +38,12 @@ export interface LocaleDetectContext {
|
|
|
34
38
|
setLocale: (locale: string) => void;
|
|
35
39
|
/** Whether we are running on the server */
|
|
36
40
|
isServer: boolean;
|
|
41
|
+
/** The request hostname (available when `strategy: 'domains'`) */
|
|
42
|
+
host?: string;
|
|
43
|
+
/** Pre-read cookie value (hoisted before await in plugin) */
|
|
44
|
+
cookieValue?: string | null;
|
|
45
|
+
/** Pre-read Accept-Language header (hoisted before await in plugin) */
|
|
46
|
+
acceptLanguage?: string;
|
|
37
47
|
}
|
|
38
48
|
/**
|
|
39
49
|
* A locale detector function.
|
|
@@ -41,24 +51,51 @@ export interface LocaleDetectContext {
|
|
|
41
51
|
* Can be sync or async. Call `ctx.setLocale(locale)` to claim a locale.
|
|
42
52
|
*/
|
|
43
53
|
export type LocaleDetectorFn = (ctx: LocaleDetectContext) => void | Promise<void>;
|
|
54
|
+
/**
|
|
55
|
+
* Per-page locale configuration.
|
|
56
|
+
*
|
|
57
|
+
* Restricts which locales a page supports. Routes will only be generated
|
|
58
|
+
* for the specified locales.
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```ts
|
|
62
|
+
* // In a page component's <script setup>
|
|
63
|
+
* defineI18nRoute({ locales: ['en', 'ja'] }) // only en and ja for this page
|
|
64
|
+
* defineI18nRoute(false) // disable i18n for this page
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
export type I18nRouteConfig = {
|
|
68
|
+
locales: string[];
|
|
69
|
+
} | false;
|
|
70
|
+
/** Domain-to-locale mapping for the `'domains'` strategy */
|
|
71
|
+
export interface DomainConfig {
|
|
72
|
+
/** Domain hostname (e.g. 'example.jp', 'ja.example.com') */
|
|
73
|
+
domain: string;
|
|
74
|
+
/** Locale code for this domain */
|
|
75
|
+
locale: string;
|
|
76
|
+
/** Whether this is the default domain (used for x-default hreflang) */
|
|
77
|
+
defaultForLocale?: boolean;
|
|
78
|
+
}
|
|
44
79
|
/** @fluenti/nuxt module options (set in nuxt.config.ts under `fluenti` key) */
|
|
45
80
|
export interface FluentNuxtOptions {
|
|
46
|
-
/**
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
|
|
52
|
-
/**
|
|
81
|
+
/** fluenti.config.ts path or inline config */
|
|
82
|
+
config?: string | FluentiBuildConfig;
|
|
83
|
+
/** Override locales from fluenti.config.ts */
|
|
84
|
+
locales?: FluentiBuildConfig['locales'];
|
|
85
|
+
/** Override defaultLocale from fluenti.config.ts */
|
|
86
|
+
defaultLocale?: string;
|
|
87
|
+
/** Override sourceLocale from fluenti.config.ts */
|
|
53
88
|
sourceLocale?: string;
|
|
54
|
-
/**
|
|
89
|
+
/** Override catalogDir from fluenti.config.ts */
|
|
55
90
|
catalogDir?: string;
|
|
91
|
+
/** URL routing strategy */
|
|
92
|
+
strategy?: Strategy;
|
|
56
93
|
/** Browser language detection settings */
|
|
57
94
|
detectBrowserLanguage?: DetectBrowserLanguageOptions;
|
|
58
95
|
/**
|
|
59
96
|
* Ordered list of locale detectors.
|
|
60
97
|
*
|
|
61
|
-
* Each entry is either a built-in detector name ('path', 'cookie', 'header', 'query')
|
|
98
|
+
* Each entry is either a built-in detector name ('path', 'cookie', 'header', 'query', 'domain')
|
|
62
99
|
* or a file path to a custom detector module (e.g. '~/detectors/jwt-detector').
|
|
63
100
|
*
|
|
64
101
|
* Detectors run in order; the first one to call `ctx.setLocale()` wins.
|
|
@@ -67,11 +104,17 @@ export interface FluentNuxtOptions {
|
|
|
67
104
|
*/
|
|
68
105
|
detectOrder?: Array<BuiltinDetector | string>;
|
|
69
106
|
/**
|
|
70
|
-
*
|
|
107
|
+
* Query parameter name for locale detection (e.g. `?lang=ja`).
|
|
108
|
+
*
|
|
109
|
+
* @default 'locale'
|
|
110
|
+
*/
|
|
111
|
+
queryParamKey?: string;
|
|
112
|
+
/**
|
|
113
|
+
* Prefix for globally registered i18n components (Trans, Plural, Select, DateTime, NumberFormat).
|
|
71
114
|
*
|
|
72
115
|
* Use this to avoid naming conflicts with other libraries.
|
|
73
116
|
*
|
|
74
|
-
* @example 'I18n' // → I18nTrans, I18nPlural, I18nSelect
|
|
117
|
+
* @example 'I18n' // → I18nTrans, I18nPlural, I18nSelect, I18nDateTime, I18nNumberFormat
|
|
75
118
|
* @default '' (no prefix)
|
|
76
119
|
*/
|
|
77
120
|
componentPrefix?: string;
|
|
@@ -83,6 +126,101 @@ export interface FluentNuxtOptions {
|
|
|
83
126
|
* @default true
|
|
84
127
|
*/
|
|
85
128
|
autoVitePlugin?: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* Whether to auto-import composables (useLocalePath, useSwitchLocalePath, useLocaleHead, useI18n).
|
|
131
|
+
*
|
|
132
|
+
* Set to `false` to disable all auto-imports. Useful when migrating from `@nuxtjs/i18n`
|
|
133
|
+
* or when you want explicit imports to avoid naming collisions.
|
|
134
|
+
*
|
|
135
|
+
* @default true
|
|
136
|
+
*/
|
|
137
|
+
autoImports?: boolean;
|
|
138
|
+
/**
|
|
139
|
+
* Whether to extend routes with locale-prefixed variants.
|
|
140
|
+
*
|
|
141
|
+
* Set to `false` to handle locale routing yourself (e.g., via a custom
|
|
142
|
+
* `pages:extend` hook or Nuxt Layers). When `false`, the module will NOT
|
|
143
|
+
* create locale-suffixed route clones and will NOT remove unprefixed routes.
|
|
144
|
+
*
|
|
145
|
+
* @default true
|
|
146
|
+
*/
|
|
147
|
+
extendRoutes?: boolean;
|
|
148
|
+
/**
|
|
149
|
+
* Route generation mode for locale variants.
|
|
150
|
+
*
|
|
151
|
+
* - `'all'` (default): All pages get locale route variants unless explicitly
|
|
152
|
+
* opted out via `definePageMeta({ i18n: false })`.
|
|
153
|
+
* - `'opt-in'`: Only pages that explicitly declare `definePageMeta({ i18n: { locales: [...] } })`
|
|
154
|
+
* get locale route variants. Pages without an `i18n` meta field are left untouched.
|
|
155
|
+
*
|
|
156
|
+
* Use `'opt-in'` for large projects where only a subset of pages need i18n routing.
|
|
157
|
+
*
|
|
158
|
+
* @default 'all'
|
|
159
|
+
*/
|
|
160
|
+
routeMode?: 'all' | 'opt-in';
|
|
161
|
+
/**
|
|
162
|
+
* Template for generating locale-specific route names.
|
|
163
|
+
*
|
|
164
|
+
* Receives the original route name and locale code, returns the desired name.
|
|
165
|
+
* Only used when `extendRoutes` is not `false`.
|
|
166
|
+
*
|
|
167
|
+
* @default (name, locale) => `${name}___${locale}`
|
|
168
|
+
* @example (name, locale) => `${locale}:${name}`
|
|
169
|
+
*/
|
|
170
|
+
routeNameTemplate?: (name: string, locale: string) => string;
|
|
171
|
+
/**
|
|
172
|
+
* Custom route paths per locale.
|
|
173
|
+
*
|
|
174
|
+
* Allows different URL slugs for different locales (e.g. `/about` in English
|
|
175
|
+
* becomes `/について` in Japanese).
|
|
176
|
+
*
|
|
177
|
+
* Keys are the original route paths; values are locale-to-path mappings.
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```ts
|
|
181
|
+
* routeOverrides: {
|
|
182
|
+
* '/about': { ja: '/について', 'zh-CN': '/关于' },
|
|
183
|
+
* '/contact': { ja: '/お問い合わせ' },
|
|
184
|
+
* }
|
|
185
|
+
* ```
|
|
186
|
+
*/
|
|
187
|
+
routeOverrides?: Record<string, Record<string, string>>;
|
|
188
|
+
/**
|
|
189
|
+
* Whether the locale redirect middleware should be registered globally.
|
|
190
|
+
*
|
|
191
|
+
* Set to `false` to register it as a named middleware instead, so you can
|
|
192
|
+
* apply it only to specific pages via `definePageMeta({ middleware: ['fluenti-locale-redirect'] })`.
|
|
193
|
+
*
|
|
194
|
+
* Only relevant when `strategy` is `'prefix'`.
|
|
195
|
+
*
|
|
196
|
+
* @default true
|
|
197
|
+
*/
|
|
198
|
+
globalMiddleware?: boolean;
|
|
199
|
+
/**
|
|
200
|
+
* Whether to register the `NuxtLinkLocale` component globally.
|
|
201
|
+
*
|
|
202
|
+
* Set to `false` to disable registration. You can still import it manually
|
|
203
|
+
* from `@fluenti/nuxt/runtime/components/NuxtLinkLocale`.
|
|
204
|
+
*
|
|
205
|
+
* @default true
|
|
206
|
+
*/
|
|
207
|
+
registerNuxtLinkLocale?: boolean;
|
|
208
|
+
/**
|
|
209
|
+
* Domain-to-locale mappings for the `'domains'` strategy.
|
|
210
|
+
*
|
|
211
|
+
* Each entry maps a domain hostname to a locale. Required when `strategy` is `'domains'`.
|
|
212
|
+
*
|
|
213
|
+
* Can also be specified inline in locale objects via `{ code: 'ja', domain: 'example.jp' }`.
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```ts
|
|
217
|
+
* domains: [
|
|
218
|
+
* { domain: 'example.com', locale: 'en', defaultForLocale: true },
|
|
219
|
+
* { domain: 'example.jp', locale: 'ja' },
|
|
220
|
+
* ]
|
|
221
|
+
* ```
|
|
222
|
+
*/
|
|
223
|
+
domains?: DomainConfig[];
|
|
86
224
|
/**
|
|
87
225
|
* Incremental Static Regeneration (ISR) settings.
|
|
88
226
|
*
|
|
@@ -92,7 +230,54 @@ export interface FluentNuxtOptions {
|
|
|
92
230
|
isr?: ISROptions;
|
|
93
231
|
/** Enable @fluenti/vue-i18n-compat bridge mode */
|
|
94
232
|
compat?: boolean;
|
|
233
|
+
/**
|
|
234
|
+
* Whether to inject `$localePath` onto `app.config.globalProperties`.
|
|
235
|
+
*
|
|
236
|
+
* Set to `false` if another plugin (e.g. `@nuxtjs/i18n`) already provides `$localePath`,
|
|
237
|
+
* or when using composition API exclusively.
|
|
238
|
+
*
|
|
239
|
+
* @default true
|
|
240
|
+
*/
|
|
241
|
+
injectGlobalProperties?: boolean;
|
|
242
|
+
/**
|
|
243
|
+
* Callback fired when a translation key is missing from the catalog.
|
|
244
|
+
*
|
|
245
|
+
* Useful for logging, error tracking, or providing dynamic fallbacks.
|
|
246
|
+
*/
|
|
247
|
+
onMissingTranslation?: (locale: string, id: string) => string | undefined;
|
|
248
|
+
/**
|
|
249
|
+
* Structured error handler for i18n errors.
|
|
250
|
+
*/
|
|
251
|
+
onError?: I18nErrorHandler;
|
|
252
|
+
/**
|
|
253
|
+
* Generate fallback text when a translation is missing or errors.
|
|
254
|
+
*/
|
|
255
|
+
getMessageFallback?: MessageFallbackHandler;
|
|
95
256
|
}
|
|
257
|
+
/** Structured i18n error types */
|
|
258
|
+
export type I18nErrorCode = 'MISSING_MESSAGE' | 'MISSING_LOCALE' | 'FORMAT_ERROR' | 'LOAD_ERROR';
|
|
259
|
+
/** Structured error passed to the onError callback */
|
|
260
|
+
export interface I18nError {
|
|
261
|
+
/** Error classification */
|
|
262
|
+
code: I18nErrorCode;
|
|
263
|
+
/** Human-readable error message */
|
|
264
|
+
message: string;
|
|
265
|
+
/** The message key that caused the error */
|
|
266
|
+
key?: string;
|
|
267
|
+
/** The locale that caused the error */
|
|
268
|
+
locale?: string;
|
|
269
|
+
/** The original error (if wrapping a lower-level error) */
|
|
270
|
+
cause?: unknown;
|
|
271
|
+
}
|
|
272
|
+
/** Callback for structured i18n error handling */
|
|
273
|
+
export type I18nErrorHandler = (error: I18nError) => void;
|
|
274
|
+
/**
|
|
275
|
+
* Callback to generate fallback text when a translation is missing or errors.
|
|
276
|
+
*
|
|
277
|
+
* Return a string to use as the fallback, or `undefined` for default behavior
|
|
278
|
+
* (which shows the message key).
|
|
279
|
+
*/
|
|
280
|
+
export type MessageFallbackHandler = (error: I18nError) => string | undefined;
|
|
96
281
|
/** ISR configuration */
|
|
97
282
|
export interface ISROptions {
|
|
98
283
|
/** Enable ISR route rules generation */
|
|
@@ -108,5 +293,17 @@ export interface FluentNuxtRuntimeConfig {
|
|
|
108
293
|
detectBrowserLanguage?: DetectBrowserLanguageOptions;
|
|
109
294
|
/** Ordered list of detector names/paths */
|
|
110
295
|
detectOrder: Array<string>;
|
|
296
|
+
/** Query parameter name for locale detection */
|
|
297
|
+
queryParamKey: string;
|
|
298
|
+
/** Whether to inject $localePath onto globalProperties */
|
|
299
|
+
injectGlobalProperties: boolean;
|
|
300
|
+
/** Domain-to-locale mappings (when strategy is 'domains') */
|
|
301
|
+
domains?: DomainConfig[];
|
|
302
|
+
/** Locale metadata (iso tags, dir, names) — keyed by locale code */
|
|
303
|
+
localeProperties?: Record<string, LocaleObject>;
|
|
111
304
|
}
|
|
305
|
+
/** Build a locale properties map from LocaleDefinition[] */
|
|
306
|
+
export declare function resolveLocaleProperties(locales: LocaleDefinition[]): Record<string, LocaleObject>;
|
|
307
|
+
/** Build domain configs from locale objects that have a `domain` field */
|
|
308
|
+
export declare function resolveDomainConfigs(locales: LocaleDefinition[], explicit?: DomainConfig[]): DomainConfig[];
|
|
112
309
|
//# sourceMappingURL=types.d.ts.map
|