@i18n-micro/utils 1.0.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 +14 -0
- package/dist/accept-language.cjs +1 -0
- package/dist/accept-language.d.cts +3 -0
- package/dist/accept-language.d.ts +3 -0
- package/dist/accept-language.mjs +22 -0
- package/dist/active-locales.cjs +1 -0
- package/dist/active-locales.d.cts +4 -0
- package/dist/active-locales.d.ts +4 -0
- package/dist/active-locales.mjs +14 -0
- package/dist/build.cjs +1 -0
- package/dist/build.d.cts +14 -0
- package/dist/build.d.ts +14 -0
- package/dist/build.mjs +86 -0
- package/dist/cache-control.cjs +1 -0
- package/dist/cache-control.d.cts +33 -0
- package/dist/cache-control.d.ts +33 -0
- package/dist/cache-control.mjs +56 -0
- package/dist/cookie.cjs +1 -0
- package/dist/cookie.d.cts +24 -0
- package/dist/cookie.d.ts +24 -0
- package/dist/cookie.mjs +25 -0
- package/dist/deep-merge.cjs +1 -0
- package/dist/deep-merge.d.cts +17 -0
- package/dist/deep-merge.d.ts +17 -0
- package/dist/deep-merge.mjs +23 -0
- package/dist/merge-source.cjs +1 -0
- package/dist/merge-source.d.cts +22 -0
- package/dist/merge-source.d.ts +22 -0
- package/dist/merge-source.mjs +51 -0
- package/dist/parse-path.cjs +1 -0
- package/dist/parse-path.d.cts +35 -0
- package/dist/parse-path.d.ts +35 -0
- package/dist/parse-path.mjs +41 -0
- package/dist/payload-config.cjs +1 -0
- package/dist/payload-config.d.cts +35 -0
- package/dist/payload-config.d.ts +35 -0
- package/dist/payload-config.mjs +59 -0
- package/dist/payload-fetch.cjs +1 -0
- package/dist/payload-fetch.d.cts +11 -0
- package/dist/payload-fetch.d.ts +11 -0
- package/dist/payload-fetch.mjs +28 -0
- package/dist/payload-stats.cjs +1 -0
- package/dist/payload-stats.d.cts +2 -0
- package/dist/payload-stats.d.ts +2 -0
- package/dist/payload-stats.mjs +19 -0
- package/dist/payload-url.cjs +1 -0
- package/dist/payload-url.d.cts +24 -0
- package/dist/payload-url.d.ts +24 -0
- package/dist/payload-url.mjs +24 -0
- package/dist/resolve-locale.cjs +1 -0
- package/dist/resolve-locale.d.cts +21 -0
- package/dist/resolve-locale.d.ts +21 -0
- package/dist/resolve-locale.mjs +15 -0
- package/dist/route-pattern.cjs +1 -0
- package/dist/route-pattern.d.cts +11 -0
- package/dist/route-pattern.d.ts +11 -0
- package/dist/route-pattern.mjs +20 -0
- package/dist/route.cjs +1 -0
- package/dist/route.d.cts +9 -0
- package/dist/route.d.ts +9 -0
- package/dist/route.mjs +38 -0
- package/dist/runtime-config.cjs +1 -0
- package/dist/runtime-config.d.cts +8 -0
- package/dist/runtime-config.d.ts +8 -0
- package/dist/runtime-config.mjs +69 -0
- package/dist/source-loader.cjs +1 -0
- package/dist/source-loader.d.cts +6 -0
- package/dist/source-loader.d.ts +6 -0
- package/dist/source-loader.mjs +16 -0
- package/package.json +246 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type ParsedTranslationRelativePath = {
|
|
2
|
+
type: 'page';
|
|
3
|
+
pageName: string;
|
|
4
|
+
locale: string;
|
|
5
|
+
} | {
|
|
6
|
+
type: 'root';
|
|
7
|
+
locale: string;
|
|
8
|
+
} | {
|
|
9
|
+
type: 'ignore';
|
|
10
|
+
};
|
|
11
|
+
export interface TranslationFileBuckets<T = Record<string, unknown>> {
|
|
12
|
+
root: Record<string, T>;
|
|
13
|
+
routes: Record<string, Record<string, T>>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Parse a translation file path relative to the locales root.
|
|
17
|
+
* Examples: `en.json`, `pages/about/en.json`, `pages/user/profile/en.json`
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseTranslationRelativePath(relativePath: string): ParsedTranslationRelativePath;
|
|
20
|
+
/**
|
|
21
|
+
* Classify a translation path, optionally treating page files as root-level translations.
|
|
22
|
+
*/
|
|
23
|
+
export declare function classifyTranslationRelativePath(relativePath: string, disablePageLocales?: boolean): ParsedTranslationRelativePath;
|
|
24
|
+
/**
|
|
25
|
+
* Convert nested page path segments to a route name (e.g. `user/profile` → `user-profile`).
|
|
26
|
+
*/
|
|
27
|
+
export declare function pagePathSegmentsToRouteName(segments: string[]): string | null;
|
|
28
|
+
/**
|
|
29
|
+
* Store a loaded translation file in root or route buckets based on its relative path.
|
|
30
|
+
*/
|
|
31
|
+
export declare function storeLoadedTranslationFile<T extends Record<string, unknown>>(buckets: TranslationFileBuckets<T>, relativePath: string, translations: T, disablePageLocales?: boolean): void;
|
|
32
|
+
/**
|
|
33
|
+
* Merge route-specific translations on top of root translations.
|
|
34
|
+
*/
|
|
35
|
+
export declare function mergeRouteTranslationsWithRoot<T extends Record<string, unknown>>(rootTranslations: T | undefined, routeTranslations: T): T;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { deepMergeTranslations as i } from "./deep-merge.mjs";
|
|
2
|
+
function l(e) {
|
|
3
|
+
const t = e.replace(/\\/g, "/");
|
|
4
|
+
if (!t.endsWith(".json"))
|
|
5
|
+
return { type: "ignore" };
|
|
6
|
+
if (t.startsWith("pages/")) {
|
|
7
|
+
const n = t.match(/^pages\/(.+)\/([^/]+)\.json$/);
|
|
8
|
+
if (!n?.[1] || !n[2])
|
|
9
|
+
return { type: "ignore" };
|
|
10
|
+
const r = p(n[1].split("/"));
|
|
11
|
+
return r ? { type: "page", pageName: r, locale: n[2] } : { type: "ignore" };
|
|
12
|
+
}
|
|
13
|
+
const o = t.match(/^([^/]+)\.json$/);
|
|
14
|
+
return o?.[1] ? { type: "root", locale: o[1] } : { type: "ignore" };
|
|
15
|
+
}
|
|
16
|
+
function s(e, t = !1) {
|
|
17
|
+
const o = l(e);
|
|
18
|
+
return t && o.type === "page" ? { type: "root", locale: o.locale } : o;
|
|
19
|
+
}
|
|
20
|
+
function p(e) {
|
|
21
|
+
return e.length === 0 ? null : e.join("-");
|
|
22
|
+
}
|
|
23
|
+
function u(e, t, o, n = !1) {
|
|
24
|
+
const r = s(t, n);
|
|
25
|
+
if (r.type === "page") {
|
|
26
|
+
const a = e.routes[r.pageName] ?? (e.routes[r.pageName] = {});
|
|
27
|
+
a[r.locale] = o;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
r.type === "root" && (e.root[r.locale] = o);
|
|
31
|
+
}
|
|
32
|
+
function f(e, t) {
|
|
33
|
+
return i(e ?? {}, t);
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
s as classifyTranslationRelativePath,
|
|
37
|
+
f as mergeRouteTranslationsWithRoot,
|
|
38
|
+
p as pagePathSegmentsToRouteName,
|
|
39
|
+
l as parseTranslationRelativePath,
|
|
40
|
+
u as storeLoadedTranslationFile
|
|
41
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const d=require("node:path"),r=500,t=10*1024*1024;function s(a){return a.translationPayloads?.mode==="source"?"source":"premerged"}function o(a){const e=s(a),n=e==="source";return{mode:e,serverAssets:a.translationPayloads?.serverAssets!==!1,serverHandler:a.translationPayloads?.serverHandler!==!1,publicAssets:n?a.translationPayloads?.publicAssets===!0:a.translationPayloads?.publicAssets!==!1,prerenderRoutes:n?a.translationPayloads?.prerenderRoutes===!0:a.translationPayloads?.prerenderRoutes!==!1,publicDir:a.translationPayloads?.publicDir,warnFileCount:a.translationPayloads?.warnFileCount,warnSizeBytes:a.translationPayloads?.warnSizeBytes}}function y(a,e){const n=o(e);return d.join(a??"./dist",n.publicDir??e.translationDir??"locales")}function c(a){return{warnFileCount:a?.warnFileCount??r,warnSizeBytes:a?.warnSizeBytes??t}}function l(a){return a.serverAssets||a.serverHandler||a.publicAssets||a.prerenderRoutes}function P(a){if(l(a.translationPayloads))return[];const e=[];return a.apiBaseServerHost||e.push("[nuxt-i18n-micro] translationPayloads disabled all local outputs but apiBaseServerHost is not set. SSR will load empty translations unless you provide an external server payload host."),a.apiBaseClientHost||e.push("[nuxt-i18n-micro] translationPayloads disabled all local outputs but apiBaseClientHost is not set. Client-side navigation may load empty translations unless you provide an external client payload host."),e}function i(a){return a>=1024*1024?`${(a/(1024*1024)).toFixed(1)} MB`:a>=1024?`${(a/1024).toFixed(1)} KB`:`${a} B`}function T(a,e){const n=e?.warnFileCount??r,u=e?.warnSizeBytes??t;return a.fileCount<n&&a.totalBytes<u?null:`[nuxt-i18n-micro] Generated translation payloads are large (${a.fileCount} files, ${i(a.totalBytes)}). Consider translationPayloads.mode: 'source' for serverless deployments, disabling unused outputs, or hosting payloads externally.`}exports.DEFAULT_TRANSLATION_PAYLOAD_WARN_FILE_COUNT=r;exports.DEFAULT_TRANSLATION_PAYLOAD_WARN_SIZE_BYTES=t;exports.formatBytes=i;exports.getTranslationPayloadMisconfigurationWarnings=P;exports.getTranslationPayloadSizeWarning=T;exports.hasLocalTranslationPayloadOutput=l;exports.resolveTranslationPayloadMode=s;exports.resolveTranslationPayloadOptions=o;exports.resolveTranslationPayloadPublicDir=y;exports.resolveTranslationPayloadWarningThresholds=c;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ModuleOptions, TranslationPayloadOptions } from '@i18n-micro/types';
|
|
2
|
+
export type TranslationPayloadMode = 'premerged' | 'source';
|
|
3
|
+
export interface ResolvedTranslationPayloadOptions {
|
|
4
|
+
mode: TranslationPayloadMode;
|
|
5
|
+
serverAssets: boolean;
|
|
6
|
+
serverHandler: boolean;
|
|
7
|
+
publicAssets: boolean;
|
|
8
|
+
prerenderRoutes: boolean;
|
|
9
|
+
publicDir?: string;
|
|
10
|
+
warnFileCount?: number;
|
|
11
|
+
warnSizeBytes?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface TranslationPayloadMisconfigurationInput {
|
|
14
|
+
translationPayloads: ResolvedTranslationPayloadOptions;
|
|
15
|
+
apiBaseClientHost?: string;
|
|
16
|
+
apiBaseServerHost?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface TranslationPayloadStats {
|
|
19
|
+
fileCount: number;
|
|
20
|
+
totalBytes: number;
|
|
21
|
+
}
|
|
22
|
+
export interface TranslationPayloadSizeThresholds {
|
|
23
|
+
warnFileCount?: number;
|
|
24
|
+
warnSizeBytes?: number;
|
|
25
|
+
}
|
|
26
|
+
export declare const DEFAULT_TRANSLATION_PAYLOAD_WARN_FILE_COUNT = 500;
|
|
27
|
+
export declare const DEFAULT_TRANSLATION_PAYLOAD_WARN_SIZE_BYTES: number;
|
|
28
|
+
export declare function resolveTranslationPayloadMode(options: ModuleOptions): TranslationPayloadMode;
|
|
29
|
+
export declare function resolveTranslationPayloadOptions(options: ModuleOptions): ResolvedTranslationPayloadOptions;
|
|
30
|
+
export declare function resolveTranslationPayloadPublicDir(outputPublicDir: string | undefined, options: ModuleOptions): string;
|
|
31
|
+
export declare function resolveTranslationPayloadWarningThresholds(options?: TranslationPayloadOptions): Required<TranslationPayloadSizeThresholds>;
|
|
32
|
+
export declare function hasLocalTranslationPayloadOutput(translationPayloads: ResolvedTranslationPayloadOptions): boolean;
|
|
33
|
+
export declare function getTranslationPayloadMisconfigurationWarnings(input: TranslationPayloadMisconfigurationInput): string[];
|
|
34
|
+
export declare function formatBytes(bytes: number): string;
|
|
35
|
+
export declare function getTranslationPayloadSizeWarning(stats: TranslationPayloadStats, thresholds?: TranslationPayloadSizeThresholds): string | null;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { ModuleOptions, TranslationPayloadOptions } from '@i18n-micro/types';
|
|
2
|
+
export type TranslationPayloadMode = 'premerged' | 'source';
|
|
3
|
+
export interface ResolvedTranslationPayloadOptions {
|
|
4
|
+
mode: TranslationPayloadMode;
|
|
5
|
+
serverAssets: boolean;
|
|
6
|
+
serverHandler: boolean;
|
|
7
|
+
publicAssets: boolean;
|
|
8
|
+
prerenderRoutes: boolean;
|
|
9
|
+
publicDir?: string;
|
|
10
|
+
warnFileCount?: number;
|
|
11
|
+
warnSizeBytes?: number;
|
|
12
|
+
}
|
|
13
|
+
export interface TranslationPayloadMisconfigurationInput {
|
|
14
|
+
translationPayloads: ResolvedTranslationPayloadOptions;
|
|
15
|
+
apiBaseClientHost?: string;
|
|
16
|
+
apiBaseServerHost?: string;
|
|
17
|
+
}
|
|
18
|
+
export interface TranslationPayloadStats {
|
|
19
|
+
fileCount: number;
|
|
20
|
+
totalBytes: number;
|
|
21
|
+
}
|
|
22
|
+
export interface TranslationPayloadSizeThresholds {
|
|
23
|
+
warnFileCount?: number;
|
|
24
|
+
warnSizeBytes?: number;
|
|
25
|
+
}
|
|
26
|
+
export declare const DEFAULT_TRANSLATION_PAYLOAD_WARN_FILE_COUNT = 500;
|
|
27
|
+
export declare const DEFAULT_TRANSLATION_PAYLOAD_WARN_SIZE_BYTES: number;
|
|
28
|
+
export declare function resolveTranslationPayloadMode(options: ModuleOptions): TranslationPayloadMode;
|
|
29
|
+
export declare function resolveTranslationPayloadOptions(options: ModuleOptions): ResolvedTranslationPayloadOptions;
|
|
30
|
+
export declare function resolveTranslationPayloadPublicDir(outputPublicDir: string | undefined, options: ModuleOptions): string;
|
|
31
|
+
export declare function resolveTranslationPayloadWarningThresholds(options?: TranslationPayloadOptions): Required<TranslationPayloadSizeThresholds>;
|
|
32
|
+
export declare function hasLocalTranslationPayloadOutput(translationPayloads: ResolvedTranslationPayloadOptions): boolean;
|
|
33
|
+
export declare function getTranslationPayloadMisconfigurationWarnings(input: TranslationPayloadMisconfigurationInput): string[];
|
|
34
|
+
export declare function formatBytes(bytes: number): string;
|
|
35
|
+
export declare function getTranslationPayloadSizeWarning(stats: TranslationPayloadStats, thresholds?: TranslationPayloadSizeThresholds): string | null;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { join as l } from "node:path";
|
|
2
|
+
const r = 500, t = 10 * 1024 * 1024;
|
|
3
|
+
function o(a) {
|
|
4
|
+
return a.translationPayloads?.mode === "source" ? "source" : "premerged";
|
|
5
|
+
}
|
|
6
|
+
function i(a) {
|
|
7
|
+
const e = o(a), n = e === "source";
|
|
8
|
+
return {
|
|
9
|
+
mode: e,
|
|
10
|
+
serverAssets: a.translationPayloads?.serverAssets !== !1,
|
|
11
|
+
serverHandler: a.translationPayloads?.serverHandler !== !1,
|
|
12
|
+
publicAssets: n ? a.translationPayloads?.publicAssets === !0 : a.translationPayloads?.publicAssets !== !1,
|
|
13
|
+
prerenderRoutes: n ? a.translationPayloads?.prerenderRoutes === !0 : a.translationPayloads?.prerenderRoutes !== !1,
|
|
14
|
+
publicDir: a.translationPayloads?.publicDir,
|
|
15
|
+
warnFileCount: a.translationPayloads?.warnFileCount,
|
|
16
|
+
warnSizeBytes: a.translationPayloads?.warnSizeBytes
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function y(a, e) {
|
|
20
|
+
const n = i(e);
|
|
21
|
+
return l(a ?? "./dist", n.publicDir ?? e.translationDir ?? "locales");
|
|
22
|
+
}
|
|
23
|
+
function f(a) {
|
|
24
|
+
return {
|
|
25
|
+
warnFileCount: a?.warnFileCount ?? r,
|
|
26
|
+
warnSizeBytes: a?.warnSizeBytes ?? t
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function u(a) {
|
|
30
|
+
return a.serverAssets || a.serverHandler || a.publicAssets || a.prerenderRoutes;
|
|
31
|
+
}
|
|
32
|
+
function P(a) {
|
|
33
|
+
if (u(a.translationPayloads)) return [];
|
|
34
|
+
const e = [];
|
|
35
|
+
return a.apiBaseServerHost || e.push(
|
|
36
|
+
"[nuxt-i18n-micro] translationPayloads disabled all local outputs but apiBaseServerHost is not set. SSR will load empty translations unless you provide an external server payload host."
|
|
37
|
+
), a.apiBaseClientHost || e.push(
|
|
38
|
+
"[nuxt-i18n-micro] translationPayloads disabled all local outputs but apiBaseClientHost is not set. Client-side navigation may load empty translations unless you provide an external client payload host."
|
|
39
|
+
), e;
|
|
40
|
+
}
|
|
41
|
+
function d(a) {
|
|
42
|
+
return a >= 1024 * 1024 ? `${(a / (1024 * 1024)).toFixed(1)} MB` : a >= 1024 ? `${(a / 1024).toFixed(1)} KB` : `${a} B`;
|
|
43
|
+
}
|
|
44
|
+
function p(a, e) {
|
|
45
|
+
const n = e?.warnFileCount ?? r, s = e?.warnSizeBytes ?? t;
|
|
46
|
+
return a.fileCount < n && a.totalBytes < s ? null : `[nuxt-i18n-micro] Generated translation payloads are large (${a.fileCount} files, ${d(a.totalBytes)}). Consider translationPayloads.mode: 'source' for serverless deployments, disabling unused outputs, or hosting payloads externally.`;
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
r as DEFAULT_TRANSLATION_PAYLOAD_WARN_FILE_COUNT,
|
|
50
|
+
t as DEFAULT_TRANSLATION_PAYLOAD_WARN_SIZE_BYTES,
|
|
51
|
+
d as formatBytes,
|
|
52
|
+
P as getTranslationPayloadMisconfigurationWarnings,
|
|
53
|
+
p as getTranslationPayloadSizeWarning,
|
|
54
|
+
u as hasLocalTranslationPayloadOutput,
|
|
55
|
+
o as resolveTranslationPayloadMode,
|
|
56
|
+
i as resolveTranslationPayloadOptions,
|
|
57
|
+
y as resolveTranslationPayloadPublicDir,
|
|
58
|
+
f as resolveTranslationPayloadWarningThresholds
|
|
59
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./payload-url.cjs");function l(e){return e?typeof e=="object"&&e!==null&&!Array.isArray(e)?e:{}:{}}async function n(e,a,t,s){if(!e.apiBaseServerHost)return{};const r=i.buildTranslationPayloadFetchRequest({apiBaseUrl:e.apiBaseUrl??"_locales",routeName:t,locale:a,isServer:!0,baseURL:e.apiBaseServerHost,apiBaseServerHost:e.apiBaseServerHost,dateBuild:e.dateBuild});try{const o=await s(r.path,{baseURL:r.baseURL,params:r.params});return l(o)}catch{return{}}}exports.fetchTranslationPayloadFromHost=n;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Translations } from '@i18n-micro/types';
|
|
2
|
+
export type TranslationPayloadFetcher = <T>(path: string, options: {
|
|
3
|
+
baseURL: string;
|
|
4
|
+
params?: Record<string, string | number>;
|
|
5
|
+
}) => Promise<T>;
|
|
6
|
+
export interface TranslationPayloadHostConfig {
|
|
7
|
+
apiBaseUrl?: string;
|
|
8
|
+
apiBaseServerHost?: string;
|
|
9
|
+
dateBuild?: string | number;
|
|
10
|
+
}
|
|
11
|
+
export declare function fetchTranslationPayloadFromHost(config: TranslationPayloadHostConfig, locale: string, page: string, fetcher: TranslationPayloadFetcher): Promise<Translations>;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Translations } from '@i18n-micro/types';
|
|
2
|
+
export type TranslationPayloadFetcher = <T>(path: string, options: {
|
|
3
|
+
baseURL: string;
|
|
4
|
+
params?: Record<string, string | number>;
|
|
5
|
+
}) => Promise<T>;
|
|
6
|
+
export interface TranslationPayloadHostConfig {
|
|
7
|
+
apiBaseUrl?: string;
|
|
8
|
+
apiBaseServerHost?: string;
|
|
9
|
+
dateBuild?: string | number;
|
|
10
|
+
}
|
|
11
|
+
export declare function fetchTranslationPayloadFromHost(config: TranslationPayloadHostConfig, locale: string, page: string, fetcher: TranslationPayloadFetcher): Promise<Translations>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { buildTranslationPayloadFetchRequest as i } from "./payload-url.mjs";
|
|
2
|
+
function n(r) {
|
|
3
|
+
return r ? typeof r == "object" && r !== null && !Array.isArray(r) ? r : {} : {};
|
|
4
|
+
}
|
|
5
|
+
async function l(r, a, t, s) {
|
|
6
|
+
if (!r.apiBaseServerHost) return {};
|
|
7
|
+
const e = i({
|
|
8
|
+
apiBaseUrl: r.apiBaseUrl ?? "_locales",
|
|
9
|
+
routeName: t,
|
|
10
|
+
locale: a,
|
|
11
|
+
isServer: !0,
|
|
12
|
+
baseURL: r.apiBaseServerHost,
|
|
13
|
+
apiBaseServerHost: r.apiBaseServerHost,
|
|
14
|
+
dateBuild: r.dateBuild
|
|
15
|
+
});
|
|
16
|
+
try {
|
|
17
|
+
const o = await s(e.path, {
|
|
18
|
+
baseURL: e.baseURL,
|
|
19
|
+
params: e.params
|
|
20
|
+
});
|
|
21
|
+
return n(o);
|
|
22
|
+
} catch {
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export {
|
|
27
|
+
l as fetchTranslationPayloadFromHost
|
|
28
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("node:fs"),s=require("node:path");function r(n,t){for(const e of o.readdirSync(n,{withFileTypes:!0})){const i=s.join(n,e.name);if(e.isDirectory()){r(i,t);continue}e.name.endsWith(".json")&&(t.fileCount+=1,t.totalBytes+=o.statSync(i).size)}}function a(n){const t={fileCount:0,totalBytes:0};return o.existsSync(n)&&r(n,t),t}exports.scanTranslationPayloadDirectory=a;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { existsSync as r, readdirSync as s, statSync as c } from "node:fs";
|
|
2
|
+
import { join as a } from "node:path";
|
|
3
|
+
function i(n, t) {
|
|
4
|
+
for (const o of s(n, { withFileTypes: !0 })) {
|
|
5
|
+
const e = a(n, o.name);
|
|
6
|
+
if (o.isDirectory()) {
|
|
7
|
+
i(e, t);
|
|
8
|
+
continue;
|
|
9
|
+
}
|
|
10
|
+
o.name.endsWith(".json") && (t.fileCount += 1, t.totalBytes += c(e).size);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
function u(n) {
|
|
14
|
+
const t = { fileCount: 0, totalBytes: 0 };
|
|
15
|
+
return r(n) && i(n, t), t;
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
u as scanTranslationPayloadDirectory
|
|
19
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function r(a,e){const l=a||"index";return e?.[l]??l}function o(a,e,l){return`/${a.replace(/^\/+|\/+$/g,"")}/${e}/${l}/data.json`.replace(/\/{2,}/g,"/")}function n(a){return(a.isServer?a.apiBaseServerHost:a.apiBaseClientHost)??a.baseURL}function t(a){const e=r(a.routeName,a.routesLocaleLinks);return{path:o(a.apiBaseUrl,e,a.locale),baseURL:n(a),params:a.dateBuild?{v:a.dateBuild}:void 0}}exports.buildTranslationPayloadFetchRequest=t;exports.buildTranslationPayloadPath=o;exports.resolveTranslationPayloadBaseURL=n;exports.resolveTranslationPayloadPage=r;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare function resolveTranslationPayloadPage(routeName: string | undefined, routesLocaleLinks?: Record<string, string>): string;
|
|
2
|
+
export declare function buildTranslationPayloadPath(apiBaseUrl: string, page: string, locale: string): string;
|
|
3
|
+
export declare function resolveTranslationPayloadBaseURL(options: {
|
|
4
|
+
isServer: boolean;
|
|
5
|
+
baseURL: string;
|
|
6
|
+
apiBaseClientHost?: string;
|
|
7
|
+
apiBaseServerHost?: string;
|
|
8
|
+
}): string;
|
|
9
|
+
export interface TranslationPayloadFetchRequestInput {
|
|
10
|
+
apiBaseUrl: string;
|
|
11
|
+
routeName?: string;
|
|
12
|
+
locale: string;
|
|
13
|
+
isServer: boolean;
|
|
14
|
+
baseURL: string;
|
|
15
|
+
apiBaseClientHost?: string;
|
|
16
|
+
apiBaseServerHost?: string;
|
|
17
|
+
dateBuild?: string | number;
|
|
18
|
+
routesLocaleLinks?: Record<string, string>;
|
|
19
|
+
}
|
|
20
|
+
export declare function buildTranslationPayloadFetchRequest(input: TranslationPayloadFetchRequestInput): {
|
|
21
|
+
path: string;
|
|
22
|
+
baseURL: string;
|
|
23
|
+
params?: Record<string, string | number>;
|
|
24
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export declare function resolveTranslationPayloadPage(routeName: string | undefined, routesLocaleLinks?: Record<string, string>): string;
|
|
2
|
+
export declare function buildTranslationPayloadPath(apiBaseUrl: string, page: string, locale: string): string;
|
|
3
|
+
export declare function resolveTranslationPayloadBaseURL(options: {
|
|
4
|
+
isServer: boolean;
|
|
5
|
+
baseURL: string;
|
|
6
|
+
apiBaseClientHost?: string;
|
|
7
|
+
apiBaseServerHost?: string;
|
|
8
|
+
}): string;
|
|
9
|
+
export interface TranslationPayloadFetchRequestInput {
|
|
10
|
+
apiBaseUrl: string;
|
|
11
|
+
routeName?: string;
|
|
12
|
+
locale: string;
|
|
13
|
+
isServer: boolean;
|
|
14
|
+
baseURL: string;
|
|
15
|
+
apiBaseClientHost?: string;
|
|
16
|
+
apiBaseServerHost?: string;
|
|
17
|
+
dateBuild?: string | number;
|
|
18
|
+
routesLocaleLinks?: Record<string, string>;
|
|
19
|
+
}
|
|
20
|
+
export declare function buildTranslationPayloadFetchRequest(input: TranslationPayloadFetchRequestInput): {
|
|
21
|
+
path: string;
|
|
22
|
+
baseURL: string;
|
|
23
|
+
params?: Record<string, string | number>;
|
|
24
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
function l(a, e) {
|
|
2
|
+
const r = a || "index";
|
|
3
|
+
return e?.[r] ?? r;
|
|
4
|
+
}
|
|
5
|
+
function n(a, e, r) {
|
|
6
|
+
return `/${a.replace(/^\/+|\/+$/g, "")}/${e}/${r}/data.json`.replace(/\/{2,}/g, "/");
|
|
7
|
+
}
|
|
8
|
+
function o(a) {
|
|
9
|
+
return (a.isServer ? a.apiBaseServerHost : a.apiBaseClientHost) ?? a.baseURL;
|
|
10
|
+
}
|
|
11
|
+
function t(a) {
|
|
12
|
+
const e = l(a.routeName, a.routesLocaleLinks);
|
|
13
|
+
return {
|
|
14
|
+
path: n(a.apiBaseUrl, e, a.locale),
|
|
15
|
+
baseURL: o(a),
|
|
16
|
+
params: a.dateBuild ? { v: a.dateBuild } : void 0
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export {
|
|
20
|
+
t as buildTranslationPayloadFetchRequest,
|
|
21
|
+
n as buildTranslationPayloadPath,
|
|
22
|
+
o as resolveTranslationPayloadBaseURL,
|
|
23
|
+
l as resolveTranslationPayloadPage
|
|
24
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const L=require("./accept-language.cjs");function d(i){const{defaultLocale:n,validLocales:e,autoDetectLanguage:s,hasLocaleInUrl:c,urlLocale:l,queryLocale:t,cookieLocale:r,acceptLanguageHeader:o}=i;let a=n,u=!1;return c&&l&&e.includes(l)?(a=l,u=!0):t&&e.includes(t)?(a=t,u=!0):r&&e.includes(r)&&(a=r,u=!0),L.applyAutoDetectLanguage(a,u,s,o??void 0,e)}function f(i){const{defaultLocale:n,validLocales:e,autoDetectLanguage:s,stateLocale:c,cookieLocale:l,acceptLanguageHeader:t,ignoreStateLocale:r=!1}=i;let o=n,a=!1;return!r&&c&&e.includes(c)?(o=c,a=!0):l&&e.includes(l)&&(o=l,a=!0),L.applyAutoDetectLanguage(o,a,s,t??void 0,e)}exports.resolvePreferredLocale=f;exports.resolveServerLocale=d;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface ResolveServerLocaleInput {
|
|
2
|
+
defaultLocale: string;
|
|
3
|
+
validLocales: string[];
|
|
4
|
+
autoDetectLanguage?: boolean;
|
|
5
|
+
hasLocaleInUrl: boolean;
|
|
6
|
+
urlLocale?: string | null;
|
|
7
|
+
queryLocale?: string | null;
|
|
8
|
+
cookieLocale?: string | null;
|
|
9
|
+
acceptLanguageHeader?: string | null;
|
|
10
|
+
}
|
|
11
|
+
export declare function resolveServerLocale(input: ResolveServerLocaleInput): string;
|
|
12
|
+
export interface ResolvePreferredLocaleInput {
|
|
13
|
+
defaultLocale: string;
|
|
14
|
+
validLocales: string[];
|
|
15
|
+
autoDetectLanguage?: boolean;
|
|
16
|
+
stateLocale?: string | null;
|
|
17
|
+
cookieLocale?: string | null;
|
|
18
|
+
acceptLanguageHeader?: string | null;
|
|
19
|
+
ignoreStateLocale?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare function resolvePreferredLocale(input: ResolvePreferredLocaleInput): string;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export interface ResolveServerLocaleInput {
|
|
2
|
+
defaultLocale: string;
|
|
3
|
+
validLocales: string[];
|
|
4
|
+
autoDetectLanguage?: boolean;
|
|
5
|
+
hasLocaleInUrl: boolean;
|
|
6
|
+
urlLocale?: string | null;
|
|
7
|
+
queryLocale?: string | null;
|
|
8
|
+
cookieLocale?: string | null;
|
|
9
|
+
acceptLanguageHeader?: string | null;
|
|
10
|
+
}
|
|
11
|
+
export declare function resolveServerLocale(input: ResolveServerLocaleInput): string;
|
|
12
|
+
export interface ResolvePreferredLocaleInput {
|
|
13
|
+
defaultLocale: string;
|
|
14
|
+
validLocales: string[];
|
|
15
|
+
autoDetectLanguage?: boolean;
|
|
16
|
+
stateLocale?: string | null;
|
|
17
|
+
cookieLocale?: string | null;
|
|
18
|
+
acceptLanguageHeader?: string | null;
|
|
19
|
+
ignoreStateLocale?: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare function resolvePreferredLocale(input: ResolvePreferredLocaleInput): string;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { applyAutoDetectLanguage as L } from "./accept-language.mjs";
|
|
2
|
+
function d(i) {
|
|
3
|
+
const { defaultLocale: n, validLocales: e, autoDetectLanguage: s, hasLocaleInUrl: c, urlLocale: l, queryLocale: t, cookieLocale: o, acceptLanguageHeader: r } = i;
|
|
4
|
+
let a = n, u = !1;
|
|
5
|
+
return c && l && e.includes(l) ? (a = l, u = !0) : t && e.includes(t) ? (a = t, u = !0) : o && e.includes(o) && (a = o, u = !0), L(a, u, s, r ?? void 0, e);
|
|
6
|
+
}
|
|
7
|
+
function g(i) {
|
|
8
|
+
const { defaultLocale: n, validLocales: e, autoDetectLanguage: s, stateLocale: c, cookieLocale: l, acceptLanguageHeader: t, ignoreStateLocale: o = !1 } = i;
|
|
9
|
+
let r = n, a = !1;
|
|
10
|
+
return !o && c && e.includes(c) ? (r = c, a = !0) : l && e.includes(l) && (r = l, a = !0), L(r, a, s, t ?? void 0, e);
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
g as resolvePreferredLocale,
|
|
14
|
+
d as resolveServerLocale
|
|
15
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function a(e){return e.replace(/\/:locale\([^)]+\)/g,"").replace(/\/:([^()]+)\(\)/g,"/[$1]").replace(/\/:([^()]+)/g,"/[$1]")}function i(e,r="localized-"){if(!e)return;const t=e.replace(r,"");return t.length>0?t:void 0}function o(e){return e?`/${e}`:void 0}function n(e){return e.replace(/^\//,"")}exports.extractBaseRoutePattern=a;exports.routeNameToPath=o;exports.stripLeadingSlash=n;exports.stripLocalizedRouteNamePrefix=i;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts Vue Router dynamic route patterns to file-based route patterns.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* extractBaseRoutePattern('/:locale(es)/test/:param()') // '/test/[param]'
|
|
6
|
+
* extractBaseRoutePattern('/:locale(en)/static') // '/static'
|
|
7
|
+
*/
|
|
8
|
+
export declare function extractBaseRoutePattern(matchedPath: string): string;
|
|
9
|
+
export declare function stripLocalizedRouteNamePrefix(routeName: string | undefined | null, localizedRouteNamePrefix?: string): string | undefined;
|
|
10
|
+
export declare function routeNameToPath(normalizedRouteName: string | undefined): string | undefined;
|
|
11
|
+
export declare function stripLeadingSlash(path: string): string;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Converts Vue Router dynamic route patterns to file-based route patterns.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* extractBaseRoutePattern('/:locale(es)/test/:param()') // '/test/[param]'
|
|
6
|
+
* extractBaseRoutePattern('/:locale(en)/static') // '/static'
|
|
7
|
+
*/
|
|
8
|
+
export declare function extractBaseRoutePattern(matchedPath: string): string;
|
|
9
|
+
export declare function stripLocalizedRouteNamePrefix(routeName: string | undefined | null, localizedRouteNamePrefix?: string): string | undefined;
|
|
10
|
+
export declare function routeNameToPath(normalizedRouteName: string | undefined): string | undefined;
|
|
11
|
+
export declare function stripLeadingSlash(path: string): string;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
function n(e) {
|
|
2
|
+
return e.replace(/\/:locale\([^)]+\)/g, "").replace(/\/:([^()]+)\(\)/g, "/[$1]").replace(/\/:([^()]+)/g, "/[$1]");
|
|
3
|
+
}
|
|
4
|
+
function a(e, t = "localized-") {
|
|
5
|
+
if (!e) return;
|
|
6
|
+
const r = e.replace(t, "");
|
|
7
|
+
return r.length > 0 ? r : void 0;
|
|
8
|
+
}
|
|
9
|
+
function c(e) {
|
|
10
|
+
return e ? `/${e}` : void 0;
|
|
11
|
+
}
|
|
12
|
+
function i(e) {
|
|
13
|
+
return e.replace(/^\//, "");
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
n as extractBaseRoutePattern,
|
|
17
|
+
c as routeNameToPath,
|
|
18
|
+
i as stripLeadingSlash,
|
|
19
|
+
a as stripLocalizedRouteNamePrefix
|
|
20
|
+
};
|
package/dist/route.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("./route-pattern.cjs");function u(e,t,h="localized-",d){const f=e.path,o=e.name?.toString(),r=a.stripLocalizedRouteNamePrefix(o,h),s=a.routeNameToPath(r);let i=o&&t?.[o]||r&&t?.[r]||s&&t?.[s]||s&&t?.[a.stripLeadingSlash(s)]||t?.[f]||f&&t?.[a.stripLeadingSlash(f)];if(!i&&t&&d?.length){const n=f.split("/").filter(Boolean),c=n[0];if(c&&d.includes(c)&&n.length>1){const l=`/${n.slice(1).join("/")}`,m=l==="/"?"/":a.stripLeadingSlash(l);i=t[l]??t[m]??void 0}}if(!i&&e.matched&&e.matched.length>0){const n=e.matched[0];if(!n)return null;const c=a.extractBaseRoutePattern(n.path);t?.[c]&&(i=t[c])}return i||null}function R(e,t,h,d="localized-"){if(!t)return!1;const f=e.path,o=e.name?.toString(),r=a.stripLocalizedRouteNamePrefix(o,d),s=a.routeNameToPath(r),i=n=>n===void 0?!1:typeof n=="boolean"?n:Array.isArray(n)&&h?n.includes(h):!1;if(i(t[f])||o&&i(t[o])||r&&i(t[r])||s&&i(t[s]))return!0;if(e.matched&&e.matched.length>0){const n=e.matched[0];if(!n)return!1;const c=a.extractBaseRoutePattern(n.path);if(i(t[c]))return!0}return!1}exports.findAllowedLocalesForRoute=u;exports.isMetaDisabledForRoute=R;
|
package/dist/route.d.cts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface I18nRouteContext {
|
|
2
|
+
path: string;
|
|
3
|
+
name?: string | symbol | null;
|
|
4
|
+
matched?: Array<{
|
|
5
|
+
path: string;
|
|
6
|
+
}>;
|
|
7
|
+
}
|
|
8
|
+
export declare function findAllowedLocalesForRoute(route: I18nRouteContext, routeLocales: Record<string, string[]> | undefined, localizedRouteNamePrefix?: string, localeCodes?: string[]): string[] | null;
|
|
9
|
+
export declare function isMetaDisabledForRoute(route: I18nRouteContext, routeDisableMeta: Record<string, boolean | string[]> | undefined, currentLocale?: string, localizedRouteNamePrefix?: string): boolean;
|
package/dist/route.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface I18nRouteContext {
|
|
2
|
+
path: string;
|
|
3
|
+
name?: string | symbol | null;
|
|
4
|
+
matched?: Array<{
|
|
5
|
+
path: string;
|
|
6
|
+
}>;
|
|
7
|
+
}
|
|
8
|
+
export declare function findAllowedLocalesForRoute(route: I18nRouteContext, routeLocales: Record<string, string[]> | undefined, localizedRouteNamePrefix?: string, localeCodes?: string[]): string[] | null;
|
|
9
|
+
export declare function isMetaDisabledForRoute(route: I18nRouteContext, routeDisableMeta: Record<string, boolean | string[]> | undefined, currentLocale?: string, localizedRouteNamePrefix?: string): boolean;
|
package/dist/route.mjs
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { stripLocalizedRouteNamePrefix as l, stripLeadingSlash as d, extractBaseRoutePattern as p, routeNameToPath as R } from "./route-pattern.mjs";
|
|
2
|
+
function g(e, t, h = "localized-", m) {
|
|
3
|
+
const c = e.path, o = e.name?.toString(), r = l(o, h), a = R(r);
|
|
4
|
+
let i = o && t?.[o] || r && t?.[r] || a && t?.[a] || a && t?.[d(a)] || t?.[c] || c && t?.[d(c)];
|
|
5
|
+
if (!i && t && m?.length) {
|
|
6
|
+
const n = c.split("/").filter(Boolean), f = n[0];
|
|
7
|
+
if (f && m.includes(f) && n.length > 1) {
|
|
8
|
+
const s = `/${n.slice(1).join("/")}`, u = s === "/" ? "/" : d(s);
|
|
9
|
+
i = t[s] ?? t[u] ?? void 0;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
if (!i && e.matched && e.matched.length > 0) {
|
|
13
|
+
const n = e.matched[0];
|
|
14
|
+
if (!n) return null;
|
|
15
|
+
const f = p(n.path);
|
|
16
|
+
t?.[f] && (i = t[f]);
|
|
17
|
+
}
|
|
18
|
+
return i || null;
|
|
19
|
+
}
|
|
20
|
+
function z(e, t, h, m = "localized-") {
|
|
21
|
+
if (!t)
|
|
22
|
+
return !1;
|
|
23
|
+
const c = e.path, o = e.name?.toString(), r = l(o, m), a = R(r), i = (n) => n === void 0 ? !1 : typeof n == "boolean" ? n : Array.isArray(n) && h ? n.includes(h) : !1;
|
|
24
|
+
if (i(t[c]) || o && i(t[o]) || r && i(t[r]) || a && i(t[a]))
|
|
25
|
+
return !0;
|
|
26
|
+
if (e.matched && e.matched.length > 0) {
|
|
27
|
+
const n = e.matched[0];
|
|
28
|
+
if (!n) return !1;
|
|
29
|
+
const f = p(n.path);
|
|
30
|
+
if (i(t[f]))
|
|
31
|
+
return !0;
|
|
32
|
+
}
|
|
33
|
+
return !1;
|
|
34
|
+
}
|
|
35
|
+
export {
|
|
36
|
+
g as findAllowedLocalesForRoute,
|
|
37
|
+
z as isMetaDisabledForRoute
|
|
38
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function r(l){if(typeof l!="string")return;const t=l.trim();return t.length>0?t:void 0}function L(l){if(Array.isArray(l)){const t=l.map(e=>r(e)).filter(e=>!!e);return t.length>0?t:void 0}if(typeof l=="string"){const t=l.split(",").map(e=>e.trim()).filter(e=>e.length>0);return t.length>0?t:void 0}}function m(){return{defaultLocale:r(process.env.NUXT_I18N_DEFAULT_LOCALE)??r(process.env.NUXT_PUBLIC_I18N_RUNTIME_DEFAULT_LOCALE),fallbackLocale:r(process.env.NUXT_I18N_FALLBACK_LOCALE)??r(process.env.NUXT_PUBLIC_I18N_RUNTIME_FALLBACK_LOCALE),disabledLocales:L(process.env.NUXT_I18N_DISABLED_LOCALES)??L(process.env.NUXT_PUBLIC_I18N_RUNTIME_DISABLED_LOCALES),strategy:r(process.env.NUXT_I18N_STRATEGY)??r(process.env.NUXT_PUBLIC_I18N_RUNTIME_STRATEGY)}}function _(l){const t=l?.i18nRuntime;if(!t||typeof t!="object")return{};const e=t;return{defaultLocale:r(e.defaultLocale),fallbackLocale:r(e.fallbackLocale),disabledLocales:L(e.disabledLocales),strategy:r(e.strategy)}}function g(l){const t=m(),e=_(l);return{defaultLocale:e.defaultLocale??t.defaultLocale,fallbackLocale:e.fallbackLocale??t.fallbackLocale,disabledLocales:e.disabledLocales??t.disabledLocales,strategy:e.strategy??t.strategy}}function v(l,t,e=a=>console.warn(a)){const a=g(t),i=(l.locales??[]).map(o=>({...o}));if(a.strategy&&a.strategy!==l.strategy&&e(`[nuxt-i18n-micro] runtime i18n strategy override is ignored: "${a.strategy}" (build strategy: "${l.strategy}"). Build a separate artifact for each strategy.`),a.disabledLocales&&a.disabledLocales.length>0){const o=new Set(a.disabledLocales);for(const u of i)u.disabled=o.has(u.code)}const n=i.filter(o=>!o.disabled);if(n.length===0)return a.disabledLocales&&a.disabledLocales.length>0&&e("[nuxt-i18n-micro] runtime disabledLocales override would disable all locales; override ignored."),{...l,locales:(l.locales??[]).map(o=>({...o}))};const b=new Set(i.map(o=>o.code));let c=a.defaultLocale??l.defaultLocale,s=a.fallbackLocale??l.fallbackLocale;s&&!b.has(s)&&(e(`[nuxt-i18n-micro] runtime fallbackLocale "${s}" is not defined in locales; override ignored.`),s=l.fallbackLocale);const f=new Set(n.map(o=>o.code)),d=n[0]?.code??l.defaultLocale??"en";return(!c||!f.has(c))&&(a.defaultLocale?e(`[nuxt-i18n-micro] runtime defaultLocale "${a.defaultLocale}" is not enabled; falling back to "${d}".`):c&&!f.has(c)&&e(`[nuxt-i18n-micro] defaultLocale "${c}" is disabled by runtime overrides; falling back to "${d}".`),c=d),{...l,locales:i,defaultLocale:c,fallbackLocale:s}}exports.resolveI18nConfigWithRuntimeOverrides=v;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ModuleOptionsExtend } from '@i18n-micro/types';
|
|
2
|
+
export interface RuntimeI18nOverrides {
|
|
3
|
+
defaultLocale?: string;
|
|
4
|
+
fallbackLocale?: string;
|
|
5
|
+
disabledLocales?: string[];
|
|
6
|
+
strategy?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function resolveI18nConfigWithRuntimeOverrides(baseConfig: ModuleOptionsExtend, runtimePublic?: Record<string, unknown>, warn?: (message: string) => void): ModuleOptionsExtend;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ModuleOptionsExtend } from '@i18n-micro/types';
|
|
2
|
+
export interface RuntimeI18nOverrides {
|
|
3
|
+
defaultLocale?: string;
|
|
4
|
+
fallbackLocale?: string;
|
|
5
|
+
disabledLocales?: string[];
|
|
6
|
+
strategy?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare function resolveI18nConfigWithRuntimeOverrides(baseConfig: ModuleOptionsExtend, runtimePublic?: Record<string, unknown>, warn?: (message: string) => void): ModuleOptionsExtend;
|