@fluenti/nuxt 0.1.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/LICENSE +21 -0
- package/README.md +311 -0
- package/dist/detectors-CFJvuwzi.cjs +2 -0
- package/dist/detectors-CFJvuwzi.cjs.map +1 -0
- package/dist/detectors-DhkfHBHr.js +84 -0
- package/dist/detectors-DhkfHBHr.js.map +1 -0
- package/dist/locale-head-BfsESdd7.cjs +2 -0
- package/dist/locale-head-BfsESdd7.cjs.map +1 -0
- package/dist/locale-head-CqUlvy3O.js +38 -0
- package/dist/locale-head-CqUlvy3O.js.map +1 -0
- package/dist/module.cjs +2 -0
- package/dist/module.cjs.map +1 -0
- package/dist/module.js +104 -0
- package/dist/module.js.map +1 -0
- package/dist/page-extend-DJ7wpuVj.js +25 -0
- package/dist/page-extend-DJ7wpuVj.js.map +1 -0
- package/dist/page-extend-OvV-ZhFB.cjs +2 -0
- package/dist/page-extend-OvV-ZhFB.cjs.map +1 -0
- package/dist/path-utils-BQIsp_or.cjs +2 -0
- package/dist/path-utils-BQIsp_or.cjs.map +1 -0
- package/dist/path-utils-BcvXLCGi.js +28 -0
- package/dist/path-utils-BcvXLCGi.js.map +1 -0
- package/dist/runtime/client.cjs +2 -0
- package/dist/runtime/client.cjs.map +1 -0
- package/dist/runtime/client.d.ts +25 -0
- package/dist/runtime/client.d.ts.map +1 -0
- package/dist/runtime/client.js +18 -0
- package/dist/runtime/client.js.map +1 -0
- package/dist/runtime/components/NuxtLinkLocale.cjs +2 -0
- package/dist/runtime/components/NuxtLinkLocale.cjs.map +1 -0
- package/dist/runtime/components/NuxtLinkLocale.d.ts +44 -0
- package/dist/runtime/components/NuxtLinkLocale.d.ts.map +1 -0
- package/dist/runtime/components/NuxtLinkLocale.js +28 -0
- package/dist/runtime/components/NuxtLinkLocale.js.map +1 -0
- package/dist/runtime/composables.cjs +2 -0
- package/dist/runtime/composables.cjs.map +1 -0
- package/dist/runtime/composables.d.ts +37 -0
- package/dist/runtime/composables.d.ts.map +1 -0
- package/dist/runtime/composables.js +25 -0
- package/dist/runtime/composables.js.map +1 -0
- package/dist/runtime/detectors/cookie.d.ts +4 -0
- package/dist/runtime/detectors/cookie.d.ts.map +1 -0
- package/dist/runtime/detectors/header.d.ts +4 -0
- package/dist/runtime/detectors/header.d.ts.map +1 -0
- package/dist/runtime/detectors/index.d.ts +12 -0
- package/dist/runtime/detectors/index.d.ts.map +1 -0
- package/dist/runtime/detectors/path.d.ts +4 -0
- package/dist/runtime/detectors/path.d.ts.map +1 -0
- package/dist/runtime/detectors/query.d.ts +4 -0
- package/dist/runtime/detectors/query.d.ts.map +1 -0
- package/dist/runtime/index.cjs +1 -0
- package/dist/runtime/index.d.ts +8 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +6 -0
- package/dist/runtime/locale-head.d.ts +30 -0
- package/dist/runtime/locale-head.d.ts.map +1 -0
- package/dist/runtime/middleware/locale-redirect.cjs +2 -0
- package/dist/runtime/middleware/locale-redirect.cjs.map +1 -0
- package/dist/runtime/middleware/locale-redirect.d.ts +10 -0
- package/dist/runtime/middleware/locale-redirect.d.ts.map +1 -0
- package/dist/runtime/middleware/locale-redirect.js +19 -0
- package/dist/runtime/middleware/locale-redirect.js.map +1 -0
- package/dist/runtime/page-extend.d.ts +19 -0
- package/dist/runtime/page-extend.d.ts.map +1 -0
- package/dist/runtime/path-utils.d.ts +19 -0
- package/dist/runtime/path-utils.d.ts.map +1 -0
- package/dist/runtime/plugin.cjs +2 -0
- package/dist/runtime/plugin.cjs.map +1 -0
- package/dist/runtime/plugin.d.ts +9 -0
- package/dist/runtime/plugin.d.ts.map +1 -0
- package/dist/runtime/plugin.js +30 -0
- package/dist/runtime/plugin.js.map +1 -0
- package/dist/runtime/standalone-composables.d.ts +19 -0
- package/dist/runtime/standalone-composables.d.ts.map +1 -0
- package/dist/types.d.ts +112 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +90 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Strategy } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Add a locale prefix to a path based on the routing strategy.
|
|
4
|
+
*/
|
|
5
|
+
export declare function localePath(path: string, locale: string, defaultLocale: string, strategy: Strategy): string;
|
|
6
|
+
/**
|
|
7
|
+
* Extract the locale code from the beginning of a path.
|
|
8
|
+
* Returns the locale and the path without the locale prefix.
|
|
9
|
+
*/
|
|
10
|
+
export declare function extractLocaleFromPath(path: string, locales: string[]): {
|
|
11
|
+
locale: string | null;
|
|
12
|
+
pathWithoutLocale: string;
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Generate a path for switching to a different locale,
|
|
16
|
+
* preserving the current route path.
|
|
17
|
+
*/
|
|
18
|
+
export declare function switchLocalePath(currentPath: string, newLocale: string, locales: string[], defaultLocale: string, strategy: Strategy): string;
|
|
19
|
+
//# sourceMappingURL=path-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"path-utils.d.ts","sourceRoot":"","sources":["../../src/runtime/path-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAExC;;GAEG;AACH,wBAAgB,UAAU,CACxB,IAAI,EAAE,MAAM,EACZ,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,QAAQ,GACjB,MAAM,CAWR;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EAAE,GAChB;IAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IAAC,iBAAiB,EAAE,MAAM,CAAA;CAAE,CAgBtD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,EAAE,EACjB,aAAa,EAAE,MAAM,EACrB,QAAQ,EAAE,QAAQ,GACjB,MAAM,CAQR"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require(`../path-utils-BQIsp_or.cjs`),t=require(`../detectors-CFJvuwzi.cjs`);let n=require(`vue`),r=require(`#imports`);var i=(0,r.defineNuxtPlugin)(async i=>{let a=(0,r.useRuntimeConfig)().public.fluenti,o=(0,r.useRoute)(),s=a.detectBrowserLanguage?.useCookie?a.detectBrowserLanguage:null,c=s?.cookieKey??`fluenti_locale`,l=s?(0,r.useCookie)(c):null,u;if({}.server)u=await t.t(o.path,a,void 0,async e=>{await i.callHook(`fluenti:detect-locale`,e)}),i.payload.fluentiLocale=u;else if(i.payload.fluentiLocale)u=i.payload.fluentiLocale;else{let{locale:t}=e.t(o.path,a.locales);u=t||(l&&l.value&&a.locales.includes(l.value)?l.value:a.defaultLocale)}let d=(0,n.ref)(u);return a.strategy!==`no_prefix`&&(0,n.watch)(()=>o.path,t=>{let{locale:n}=e.t(t,a.locales);n?d.value=n:a.strategy===`prefix_except_default`&&(d.value=a.defaultLocale)}),l&&(0,n.watch)(d,e=>{l.value=e}),i.vueApp.config.globalProperties.$localePath=(t,n)=>e.n(t,n??d.value,a.defaultLocale,a.strategy),{provide:{fluentiLocale:d,fluentiConfig:a}}});module.exports=i;
|
|
2
|
+
//# sourceMappingURL=plugin.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.cjs","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 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 const currentLocale = ref(detectedLocale)\n\n // Sync locale when route changes (path-based detection)\n if (config.strategy !== 'no_prefix') {\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 nuxtApp.vueApp.config.globalProperties.$localePath = (path: string, locale?: string) => {\n return localePath(\n path,\n locale ?? currentLocale.value,\n config.defaultLocale,\n config.strategy,\n )\n }\n\n return {\n provide: {\n fluentiLocale: currentLocale,\n fluentiConfig: config,\n },\n }\n})\n"],"mappings":"gIAYA,IAAA,GAAA,EAAA,EAAA,kBAAgC,KAAO,IAAY,CACjD,IAAM,GAAA,EAAA,EAAA,mBAA2B,CAAC,OAAO,QACnC,GAAA,EAAA,EAAA,WAAkB,CAIlB,EAAY,EAAO,uBAAuB,UAC5C,EAAO,sBACP,KACE,EAAY,GAAW,WAAa,iBACpC,EAAe,GAAA,EAAA,EAAA,WAAsB,EAAU,CAAG,KAEpD,EAEJ,GAAA,EAAA,CAAgB,OAEd,EAAiB,MAAM,EAAA,EACrB,EAAM,KACN,EACA,IAAA,GACA,KAAO,IAA6B,CAClC,MAAO,EAAQ,SAAsB,wBAAyB,EAAI,EAErE,CAGD,EAAQ,QAAQ,cAAmB,UAC1B,EAAQ,QAAQ,cAEzB,EAAiB,EAAQ,QAAQ,kBAC5B,CAEL,GAAM,CAAE,OAAQ,GAAe,EAAA,EAAsB,EAAM,KAAM,EAAO,QAAQ,CAChF,AAOE,EAPE,IAEO,GACS,EAAa,OAAS,EAAO,QAAQ,SAAS,EAAa,MAAM,CAC/E,EAAa,MACb,EAAO,eAMf,IAAM,GAAA,EAAA,EAAA,KAAoB,EAAe,CAgCzC,OA7BI,EAAO,WAAa,cACtB,EAAA,EAAA,WAAY,EAAM,KAAO,GAAY,CACnC,GAAM,CAAE,UAAW,EAAA,EAAsB,EAAS,EAAO,QAAQ,CAC7D,EACF,EAAc,MAAQ,EACb,EAAO,WAAa,0BAE7B,EAAc,MAAQ,EAAO,gBAE/B,CAIA,IACF,EAAA,EAAA,OAAM,EAAgB,GAAc,CAClC,EAAa,MAAQ,GACrB,CAIJ,EAAQ,OAAO,OAAO,iBAAiB,aAAe,EAAc,IAC3D,EAAA,EACL,EACA,GAAU,EAAc,MACxB,EAAO,cACP,EAAO,SACR,CAGI,CACL,QAAS,CACP,cAAe,EACf,cAAe,EAChB,CACF,EACD"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Nuxt runtime plugin that:
|
|
3
|
+
* 1. Server: runs the locale detection chain, stores locale in payload for hydration
|
|
4
|
+
* 2. Client: reads locale from payload to avoid hydration mismatch
|
|
5
|
+
* 3. Provides reactive locale state and global helpers
|
|
6
|
+
*/
|
|
7
|
+
declare const _default: any;
|
|
8
|
+
export default _default;
|
|
9
|
+
//# sourceMappingURL=plugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/runtime/plugin.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;;AACH,wBAkFE"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { n as e, t } from "../path-utils-BcvXLCGi.js";
|
|
2
|
+
import { t as n } from "../detectors-DhkfHBHr.js";
|
|
3
|
+
import { ref as r, watch as i } from "vue";
|
|
4
|
+
import { defineNuxtPlugin as a, useCookie as o, useRoute as s, useRuntimeConfig as c } from "#imports";
|
|
5
|
+
//#region src/runtime/plugin.ts
|
|
6
|
+
var l = a(async (a) => {
|
|
7
|
+
let l = c().public.fluenti, u = s(), d = l.detectBrowserLanguage?.useCookie ? l.detectBrowserLanguage : null, f = d?.cookieKey ?? "fluenti_locale", p = d ? o(f) : null, m;
|
|
8
|
+
if (import.meta.server) m = await n(u.path, l, void 0, async (e) => {
|
|
9
|
+
await a.callHook("fluenti:detect-locale", e);
|
|
10
|
+
}), a.payload.fluentiLocale = m;
|
|
11
|
+
else if (a.payload.fluentiLocale) m = a.payload.fluentiLocale;
|
|
12
|
+
else {
|
|
13
|
+
let { locale: e } = t(u.path, l.locales);
|
|
14
|
+
m = e || (p && p.value && l.locales.includes(p.value) ? p.value : l.defaultLocale);
|
|
15
|
+
}
|
|
16
|
+
let h = r(m);
|
|
17
|
+
return l.strategy !== "no_prefix" && i(() => u.path, (e) => {
|
|
18
|
+
let { locale: n } = t(e, l.locales);
|
|
19
|
+
n ? h.value = n : l.strategy === "prefix_except_default" && (h.value = l.defaultLocale);
|
|
20
|
+
}), p && i(h, (e) => {
|
|
21
|
+
p.value = e;
|
|
22
|
+
}), a.vueApp.config.globalProperties.$localePath = (t, n) => e(t, n ?? h.value, l.defaultLocale, l.strategy), { provide: {
|
|
23
|
+
fluentiLocale: h,
|
|
24
|
+
fluentiConfig: l
|
|
25
|
+
} };
|
|
26
|
+
});
|
|
27
|
+
//#endregion
|
|
28
|
+
export { l as default };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +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 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 const currentLocale = ref(detectedLocale)\n\n // Sync locale when route changes (path-based detection)\n if (config.strategy !== 'no_prefix') {\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 nuxtApp.vueApp.config.globalProperties.$localePath = (path: string, locale?: string) => {\n return localePath(\n path,\n locale ?? currentLocale.value,\n config.defaultLocale,\n config.strategy,\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,MAEpD;AAEJ,KAAI,OAAO,KAAK,OAYd,CAVA,IAAiB,MAAM,EACrB,EAAM,MACN,GACA,KAAA,GACA,OAAO,MAA6B;AAClC,QAAO,EAAQ,SAAsB,yBAAyB,EAAI;GAErE,EAGD,EAAQ,QAAQ,gBAAmB;UAC1B,EAAQ,QAAQ,cAEzB,KAAiB,EAAQ,QAAQ;MAC5B;EAEL,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;;CAMf,IAAM,IAAgB,EAAI,EAAe;AAgCzC,QA7BI,EAAO,aAAa,eACtB,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,EAIJ,EAAQ,OAAO,OAAO,iBAAiB,eAAe,GAAc,MAC3D,EACL,GACA,KAAU,EAAc,OACxB,EAAO,eACP,EAAO,SACR,EAGI,EACL,SAAS;EACP,eAAe;EACf,eAAe;EAChB,EACF;EACD"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ComputedRef, Ref } from 'vue';
|
|
2
|
+
import { FluentNuxtRuntimeConfig } from '../types';
|
|
3
|
+
import { LocaleHeadMeta, LocaleHeadOptions } from './locale-head';
|
|
4
|
+
/**
|
|
5
|
+
* Standalone composable for locale-prefixed paths (no Nuxt dependency).
|
|
6
|
+
* Accepts explicit locale ref and config instead of reading from Nuxt context.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useLocalePath(locale: Ref<string>, config: FluentNuxtRuntimeConfig): (path: string, targetLocale?: string) => string;
|
|
9
|
+
/**
|
|
10
|
+
* Standalone composable for switch-locale paths (no Nuxt dependency).
|
|
11
|
+
* Accepts explicit current path ref and config.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useSwitchLocalePath(currentPath: Ref<string>, config: FluentNuxtRuntimeConfig): (locale: string) => string;
|
|
14
|
+
/**
|
|
15
|
+
* Standalone composable for locale-aware head metadata (no Nuxt dependency).
|
|
16
|
+
* Accepts explicit locale, path, and config refs.
|
|
17
|
+
*/
|
|
18
|
+
export declare function useLocaleHead(locale: Ref<string>, currentPath: Ref<string>, config: FluentNuxtRuntimeConfig, options?: LocaleHeadOptions): ComputedRef<LocaleHeadMeta>;
|
|
19
|
+
//# sourceMappingURL=standalone-composables.d.ts.map
|
|
@@ -0,0 +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;AAE3C,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,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"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/** Routing strategy for locale-prefixed URLs */
|
|
2
|
+
export type Strategy = 'prefix' | 'prefix_except_default' | 'prefix_and_default' | 'no_prefix';
|
|
3
|
+
/** Browser language detection options */
|
|
4
|
+
export interface DetectBrowserLanguageOptions {
|
|
5
|
+
/** Use a cookie to persist the detected locale */
|
|
6
|
+
useCookie?: boolean;
|
|
7
|
+
/** Cookie key name (default: 'fluenti_locale') */
|
|
8
|
+
cookieKey?: string;
|
|
9
|
+
/** Fallback locale when detection fails */
|
|
10
|
+
fallbackLocale?: string;
|
|
11
|
+
}
|
|
12
|
+
/** Built-in detector names */
|
|
13
|
+
export type BuiltinDetector = 'path' | 'cookie' | 'header' | 'query';
|
|
14
|
+
/**
|
|
15
|
+
* Context passed to locale detectors and the `fluenti:detect-locale` hook.
|
|
16
|
+
*
|
|
17
|
+
* Detectors inspect the context and call `setLocale()` to claim a locale.
|
|
18
|
+
* Once a locale is set, subsequent detectors are skipped.
|
|
19
|
+
*/
|
|
20
|
+
export interface LocaleDetectContext {
|
|
21
|
+
/** The request path (e.g. '/ja/about') */
|
|
22
|
+
path: string;
|
|
23
|
+
/** Available locale codes */
|
|
24
|
+
locales: string[];
|
|
25
|
+
/** Default locale */
|
|
26
|
+
defaultLocale: string;
|
|
27
|
+
/** Routing strategy */
|
|
28
|
+
strategy: Strategy;
|
|
29
|
+
/** detectBrowserLanguage config */
|
|
30
|
+
detectBrowserLanguage?: DetectBrowserLanguageOptions;
|
|
31
|
+
/** The detected locale so far (null if not yet detected) */
|
|
32
|
+
detectedLocale: string | null;
|
|
33
|
+
/** Set the locale and stop the detection chain */
|
|
34
|
+
setLocale: (locale: string) => void;
|
|
35
|
+
/** Whether we are running on the server */
|
|
36
|
+
isServer: boolean;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A locale detector function.
|
|
40
|
+
*
|
|
41
|
+
* Can be sync or async. Call `ctx.setLocale(locale)` to claim a locale.
|
|
42
|
+
*/
|
|
43
|
+
export type LocaleDetectorFn = (ctx: LocaleDetectContext) => void | Promise<void>;
|
|
44
|
+
/** @fluenti/nuxt module options (set in nuxt.config.ts under `fluenti` key) */
|
|
45
|
+
export interface FluentNuxtOptions {
|
|
46
|
+
/** List of supported locale codes */
|
|
47
|
+
locales: string[];
|
|
48
|
+
/** Default locale code */
|
|
49
|
+
defaultLocale: string;
|
|
50
|
+
/** URL routing strategy */
|
|
51
|
+
strategy?: Strategy;
|
|
52
|
+
/** Source locale for message extraction */
|
|
53
|
+
sourceLocale?: string;
|
|
54
|
+
/** Directory for compiled message catalogs */
|
|
55
|
+
catalogDir?: string;
|
|
56
|
+
/** Browser language detection settings */
|
|
57
|
+
detectBrowserLanguage?: DetectBrowserLanguageOptions;
|
|
58
|
+
/**
|
|
59
|
+
* Ordered list of locale detectors.
|
|
60
|
+
*
|
|
61
|
+
* Each entry is either a built-in detector name ('path', 'cookie', 'header', 'query')
|
|
62
|
+
* or a file path to a custom detector module (e.g. '~/detectors/jwt-detector').
|
|
63
|
+
*
|
|
64
|
+
* Detectors run in order; the first one to call `ctx.setLocale()` wins.
|
|
65
|
+
*
|
|
66
|
+
* @default ['path', 'cookie', 'header']
|
|
67
|
+
*/
|
|
68
|
+
detectOrder?: Array<BuiltinDetector | string>;
|
|
69
|
+
/**
|
|
70
|
+
* Prefix for globally registered i18n components (Trans, Plural, Select).
|
|
71
|
+
*
|
|
72
|
+
* Use this to avoid naming conflicts with other libraries.
|
|
73
|
+
*
|
|
74
|
+
* @example 'I18n' // → I18nTrans, I18nPlural, I18nSelect
|
|
75
|
+
* @default '' (no prefix)
|
|
76
|
+
*/
|
|
77
|
+
componentPrefix?: string;
|
|
78
|
+
/**
|
|
79
|
+
* Automatically register `@fluenti/vite-plugin` in the Vite config.
|
|
80
|
+
*
|
|
81
|
+
* Set to `false` to disable if you configure the Vite plugin manually.
|
|
82
|
+
*
|
|
83
|
+
* @default true
|
|
84
|
+
*/
|
|
85
|
+
autoVitePlugin?: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Incremental Static Regeneration (ISR) settings.
|
|
88
|
+
*
|
|
89
|
+
* When enabled, the module automatically generates `routeRules` with
|
|
90
|
+
* ISR caching for all locale route patterns.
|
|
91
|
+
*/
|
|
92
|
+
isr?: ISROptions;
|
|
93
|
+
/** Enable @fluenti/vue-i18n-compat bridge mode */
|
|
94
|
+
compat?: boolean;
|
|
95
|
+
}
|
|
96
|
+
/** ISR configuration */
|
|
97
|
+
export interface ISROptions {
|
|
98
|
+
/** Enable ISR route rules generation */
|
|
99
|
+
enabled: boolean;
|
|
100
|
+
/** Cache TTL in seconds (default: 3600 — 1 hour) */
|
|
101
|
+
ttl?: number;
|
|
102
|
+
}
|
|
103
|
+
/** Runtime config injected into Nuxt's public runtimeConfig */
|
|
104
|
+
export interface FluentNuxtRuntimeConfig {
|
|
105
|
+
locales: string[];
|
|
106
|
+
defaultLocale: string;
|
|
107
|
+
strategy: Strategy;
|
|
108
|
+
detectBrowserLanguage?: DetectBrowserLanguageOptions;
|
|
109
|
+
/** Ordered list of detector names/paths */
|
|
110
|
+
detectOrder: Array<string>;
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,gDAAgD;AAChD,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,uBAAuB,GAAG,oBAAoB,GAAG,WAAW,CAAA;AAE9F,yCAAyC;AACzC,MAAM,WAAW,4BAA4B;IAC3C,kDAAkD;IAClD,SAAS,CAAC,EAAE,OAAO,CAAA;IACnB,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,2CAA2C;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAA;CACxB;AAED,8BAA8B;AAC9B,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAA;AAEpE;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC,0CAA0C;IAC1C,IAAI,EAAE,MAAM,CAAA;IACZ,6BAA6B;IAC7B,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,qBAAqB;IACrB,aAAa,EAAE,MAAM,CAAA;IACrB,uBAAuB;IACvB,QAAQ,EAAE,QAAQ,CAAA;IAClB,mCAAmC;IACnC,qBAAqB,CAAC,EAAE,4BAA4B,CAAA;IACpD,4DAA4D;IAC5D,cAAc,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7B,kDAAkD;IAClD,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAA;IACnC,2CAA2C;IAC3C,QAAQ,EAAE,OAAO,CAAA;CAClB;AAED;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,CAAC,GAAG,EAAE,mBAAmB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;AAEjF,+EAA+E;AAC/E,MAAM,WAAW,iBAAiB;IAChC,qCAAqC;IACrC,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,0BAA0B;IAC1B,aAAa,EAAE,MAAM,CAAA;IACrB,2BAA2B;IAC3B,QAAQ,CAAC,EAAE,QAAQ,CAAA;IACnB,2CAA2C;IAC3C,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,8CAA8C;IAC9C,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,0CAA0C;IAC1C,qBAAqB,CAAC,EAAE,4BAA4B,CAAA;IACpD;;;;;;;;;OASG;IACH,WAAW,CAAC,EAAE,KAAK,CAAC,eAAe,GAAG,MAAM,CAAC,CAAA;IAC7C;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IACxB;;;;;OAKG;IACH,GAAG,CAAC,EAAE,UAAU,CAAA;IAChB,kDAAkD;IAClD,MAAM,CAAC,EAAE,OAAO,CAAA;CACjB;AAED,wBAAwB;AACxB,MAAM,WAAW,UAAU;IACzB,wCAAwC;IACxC,OAAO,EAAE,OAAO,CAAA;IAChB,oDAAoD;IACpD,GAAG,CAAC,EAAE,MAAM,CAAA;CACb;AAED,+DAA+D;AAC/D,MAAM,WAAW,uBAAuB;IACtC,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,aAAa,EAAE,MAAM,CAAA;IACrB,QAAQ,EAAE,QAAQ,CAAA;IAClB,qBAAqB,CAAC,EAAE,4BAA4B,CAAA;IACpD,2CAA2C;IAC3C,WAAW,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;CAC3B"}
|
package/package.json
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fluenti/nuxt",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Nuxt module for Fluenti — locale-prefixed routes, SEO helpers, auto locale detection",
|
|
6
|
+
"homepage": "https://fluenti.dev",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/usefluenti/fluenti.git",
|
|
10
|
+
"directory": "packages/nuxt"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/usefluenti/fluenti/issues"
|
|
14
|
+
},
|
|
15
|
+
"license": "MIT",
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"keywords": [
|
|
20
|
+
"i18n",
|
|
21
|
+
"nuxt",
|
|
22
|
+
"nuxt-module",
|
|
23
|
+
"fluenti",
|
|
24
|
+
"ssr",
|
|
25
|
+
"locale",
|
|
26
|
+
"routing"
|
|
27
|
+
],
|
|
28
|
+
"main": "./dist/module.cjs",
|
|
29
|
+
"module": "./dist/module.js",
|
|
30
|
+
"types": "./dist/module.d.ts",
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./dist/module.d.ts",
|
|
35
|
+
"default": "./dist/module.js"
|
|
36
|
+
},
|
|
37
|
+
"require": {
|
|
38
|
+
"types": "./dist/module.d.ts",
|
|
39
|
+
"default": "./dist/module.cjs"
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
"./runtime": {
|
|
43
|
+
"import": {
|
|
44
|
+
"types": "./dist/runtime/index.d.ts",
|
|
45
|
+
"default": "./dist/runtime/index.js"
|
|
46
|
+
},
|
|
47
|
+
"require": {
|
|
48
|
+
"types": "./dist/runtime/index.d.ts",
|
|
49
|
+
"default": "./dist/runtime/index.cjs"
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
"./client": {
|
|
53
|
+
"import": {
|
|
54
|
+
"types": "./dist/runtime/client.d.ts",
|
|
55
|
+
"default": "./dist/runtime/client.js"
|
|
56
|
+
},
|
|
57
|
+
"require": {
|
|
58
|
+
"types": "./dist/runtime/client.d.ts",
|
|
59
|
+
"default": "./dist/runtime/client.cjs"
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
"files": [
|
|
64
|
+
"dist"
|
|
65
|
+
],
|
|
66
|
+
"peerDependencies": {
|
|
67
|
+
"nuxt": "^3.0.0"
|
|
68
|
+
},
|
|
69
|
+
"dependencies": {
|
|
70
|
+
"@nuxt/kit": "^3.0.0",
|
|
71
|
+
"@fluenti/core": "0.1.0",
|
|
72
|
+
"@fluenti/vue": "0.1.0"
|
|
73
|
+
},
|
|
74
|
+
"devDependencies": {
|
|
75
|
+
"typescript": "^5.9",
|
|
76
|
+
"vite": "^8",
|
|
77
|
+
"vite-plugin-dts": "^4",
|
|
78
|
+
"vitest": "^4",
|
|
79
|
+
"@vitest/coverage-v8": "^4",
|
|
80
|
+
"vue": "^3.5",
|
|
81
|
+
"nuxt": "^3.17",
|
|
82
|
+
"vue-router": "^4"
|
|
83
|
+
},
|
|
84
|
+
"scripts": {
|
|
85
|
+
"build": "vite build",
|
|
86
|
+
"dev": "vite build --watch",
|
|
87
|
+
"test": "vitest run",
|
|
88
|
+
"typecheck": "tsc --noEmit"
|
|
89
|
+
}
|
|
90
|
+
}
|