@i18n-micro/utils 1.0.0 → 1.0.1
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/build.cjs +1 -1
- package/dist/build.mjs +56 -58
- package/dist/merge-source.cjs +1 -1
- package/dist/merge-source.mjs +17 -22
- package/dist/normalize.cjs +1 -0
- package/dist/normalize.d.cts +9 -0
- package/dist/normalize.d.ts +9 -0
- package/dist/normalize.mjs +10 -0
- package/dist/payload-fetch.cjs +1 -1
- package/dist/payload-fetch.mjs +12 -14
- package/dist/runtime-config.cjs +1 -1
- package/dist/runtime-config.mjs +51 -45
- package/dist/source-loader.cjs +1 -1
- package/dist/source-loader.mjs +9 -11
- package/package.json +36 -25
package/dist/build.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("node:fs"),i=require("node:path"),j=require("globby"),M=require("./deep-merge.cjs");async function P(m,h,r,y,p,w){n.existsSync(r)&&n.rmSync(r,{recursive:!0,force:!0}),n.mkdirSync(r,{recursive:!0});const c=m.map(e=>i.join(e,h)),l=new Set,S=await Promise.all(c.filter(e=>n.existsSync(e)).map(e=>j.globby("**/*.json",{cwd:e})));for(const e of S)e.forEach(o=>l.add(o));const g=new Map;for(const e of l){let o={};for(const t of c){const s=i.join(t,e);if(n.existsSync(s))try{o=M.deepMergeTranslationsRecursive(o,JSON.parse(n.readFileSync(s,"utf-8")))}catch{}}g.set(e,o)}const d=new Map,f=new Map;for(const[e,o]of g){const t=i.dirname(e),s=e.slice(e.lastIndexOf("/")+1).replace(".json","");t==="."?d.set(s,o):(f.has(t)||f.set(t,new Map),f.get(t).set(s,o))}const v=new Set(y.map(e=>e.code)),b=e=>{for(const o of y){const t=[p,o.fallbackLocale,o.code].filter(a=>!!a&&v.has(a)).filter((a,u,x)=>x.indexOf(a)===u);if(t.length<=1)continue;let s={};for(const a of t){const u=e.get(a);u&&(s=M.deepMergeTranslationsRecursive(s,u))}e.set(o.code,s)}};b(d);for(const e of f.values())b(e);if(w||f.size===0){const e=new Map;for(const[o,t]of d)e.set(o,{...t});f.set("pages/index",e)}else for(const[,e]of f)for(const[o,t]of d){const s=e.get(o);e.set(o,s?M.deepMergeTranslations(t,s):{...t})}for(const[e,o]of f)for(const[t,s]of o){const a=i.join(r,e,`${t}.json`);n.mkdirSync(i.dirname(a),{recursive:!0}),n.writeFileSync(a,JSON.stringify(s))}}async function k(m,h,r){n.existsSync(r)&&n.rmSync(r,{recursive:!0,force:!0}),n.mkdirSync(r,{recursive:!0});const y=m.map(c=>i.join(c,h)),p=new Set,w=await Promise.all(y.filter(c=>n.existsSync(c)).map(c=>j.globby("**/*.json",{cwd:c})));for(const c of w)c.forEach(l=>p.add(l));for(const c of p){let l={};for(const g of y){const d=i.join(g,c);if(n.existsSync(d))try{l=M.deepMergeTranslationsRecursive(l,JSON.parse(n.readFileSync(d,"utf-8")))}catch{}}const S=i.join(r,c);n.mkdirSync(i.dirname(S),{recursive:!0}),n.writeFileSync(S,JSON.stringify(l))}}exports.buildTranslationSourceLayers=k;exports.preMergeLocales=P;
|
package/dist/build.mjs
CHANGED
|
@@ -1,83 +1,81 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { join as p, dirname as
|
|
3
|
-
import { globby as
|
|
4
|
-
import { deepMergeTranslationsRecursive as
|
|
5
|
-
async function z(
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
for (const e of
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const h = /* @__PURE__ */ new Map();
|
|
13
|
-
for (const e of l) {
|
|
1
|
+
import O, { existsSync as i, mkdirSync as w, readFileSync as b, writeFileSync as j } from "node:fs";
|
|
2
|
+
import { join as p, dirname as v } from "node:path";
|
|
3
|
+
import { globby as F } from "globby";
|
|
4
|
+
import { deepMergeTranslationsRecursive as P, deepMergeTranslations as J } from "./deep-merge.mjs";
|
|
5
|
+
async function z(M, S, c, d, y, u) {
|
|
6
|
+
i(c) && O.rmSync(c, { recursive: !0, force: !0 }), w(c, { recursive: !0 });
|
|
7
|
+
const a = M.map((e) => p(e, S)), r = /* @__PURE__ */ new Set(), m = await Promise.all(a.filter((e) => i(e)).map((e) => F("**/*.json", { cwd: e })));
|
|
8
|
+
for (const e of m)
|
|
9
|
+
e.forEach((o) => r.add(o));
|
|
10
|
+
const g = /* @__PURE__ */ new Map();
|
|
11
|
+
for (const e of r) {
|
|
14
12
|
let o = {};
|
|
15
|
-
for (const t of
|
|
16
|
-
const
|
|
17
|
-
if (
|
|
13
|
+
for (const t of a) {
|
|
14
|
+
const s = p(t, e);
|
|
15
|
+
if (i(s))
|
|
18
16
|
try {
|
|
19
|
-
o =
|
|
17
|
+
o = P(o, JSON.parse(b(s, "utf-8")));
|
|
20
18
|
} catch {
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
|
-
|
|
21
|
+
g.set(e, o);
|
|
24
22
|
}
|
|
25
|
-
const
|
|
26
|
-
for (const [e, o] of
|
|
27
|
-
const t =
|
|
28
|
-
t === "." ?
|
|
23
|
+
const l = /* @__PURE__ */ new Map(), f = /* @__PURE__ */ new Map();
|
|
24
|
+
for (const [e, o] of g) {
|
|
25
|
+
const t = v(e), s = e.slice(e.lastIndexOf("/") + 1).replace(".json", "");
|
|
26
|
+
t === "." ? l.set(s, o) : (f.has(t) || f.set(t, /* @__PURE__ */ new Map()), f.get(t).set(s, o));
|
|
29
27
|
}
|
|
30
|
-
const
|
|
31
|
-
for (const o of
|
|
32
|
-
const t = [
|
|
28
|
+
const L = new Set(d.map((e) => e.code)), x = (e) => {
|
|
29
|
+
for (const o of d) {
|
|
30
|
+
const t = [y, o.fallbackLocale, o.code].filter((n) => !!n && L.has(n)).filter((n, h, k) => k.indexOf(n) === h);
|
|
33
31
|
if (t.length <= 1) continue;
|
|
34
|
-
let
|
|
35
|
-
for (const
|
|
36
|
-
const
|
|
37
|
-
|
|
32
|
+
let s = {};
|
|
33
|
+
for (const n of t) {
|
|
34
|
+
const h = e.get(n);
|
|
35
|
+
h && (s = P(s, h));
|
|
38
36
|
}
|
|
39
|
-
e.set(o.code,
|
|
37
|
+
e.set(o.code, s);
|
|
40
38
|
}
|
|
41
39
|
};
|
|
42
|
-
x(
|
|
43
|
-
for (const e of
|
|
40
|
+
x(l);
|
|
41
|
+
for (const e of f.values())
|
|
44
42
|
x(e);
|
|
45
|
-
if (
|
|
43
|
+
if (u || f.size === 0) {
|
|
46
44
|
const e = /* @__PURE__ */ new Map();
|
|
47
|
-
for (const [o, t] of
|
|
45
|
+
for (const [o, t] of l)
|
|
48
46
|
e.set(o, { ...t });
|
|
49
|
-
|
|
47
|
+
f.set("pages/index", e);
|
|
50
48
|
} else
|
|
51
|
-
for (const [, e] of
|
|
52
|
-
for (const [o, t] of
|
|
53
|
-
const
|
|
54
|
-
e.set(o,
|
|
49
|
+
for (const [, e] of f)
|
|
50
|
+
for (const [o, t] of l) {
|
|
51
|
+
const s = e.get(o);
|
|
52
|
+
e.set(o, s ? J(t, s) : { ...t });
|
|
55
53
|
}
|
|
56
|
-
for (const [e, o] of
|
|
57
|
-
for (const [t,
|
|
58
|
-
const
|
|
59
|
-
|
|
54
|
+
for (const [e, o] of f)
|
|
55
|
+
for (const [t, s] of o) {
|
|
56
|
+
const n = p(c, e, `${t}.json`);
|
|
57
|
+
w(v(n), { recursive: !0 }), j(n, JSON.stringify(s));
|
|
60
58
|
}
|
|
61
59
|
}
|
|
62
|
-
async function C(
|
|
63
|
-
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
for (const
|
|
70
|
-
let
|
|
71
|
-
for (const
|
|
72
|
-
const
|
|
73
|
-
if (
|
|
60
|
+
async function C(M, S, c) {
|
|
61
|
+
i(c) && O.rmSync(c, { recursive: !0, force: !0 }), w(c, { recursive: !0 });
|
|
62
|
+
const d = M.map((a) => p(a, S)), y = /* @__PURE__ */ new Set(), u = await Promise.all(
|
|
63
|
+
d.filter((a) => i(a)).map((a) => F("**/*.json", { cwd: a }))
|
|
64
|
+
);
|
|
65
|
+
for (const a of u)
|
|
66
|
+
a.forEach((r) => y.add(r));
|
|
67
|
+
for (const a of y) {
|
|
68
|
+
let r = {};
|
|
69
|
+
for (const g of d) {
|
|
70
|
+
const l = p(g, a);
|
|
71
|
+
if (i(l))
|
|
74
72
|
try {
|
|
75
|
-
|
|
73
|
+
r = P(r, JSON.parse(b(l, "utf-8")));
|
|
76
74
|
} catch {
|
|
77
75
|
}
|
|
78
76
|
}
|
|
79
|
-
const
|
|
80
|
-
|
|
77
|
+
const m = p(c, a);
|
|
78
|
+
w(v(m), { recursive: !0 }), j(m, JSON.stringify(r));
|
|
81
79
|
}
|
|
82
80
|
}
|
|
83
81
|
export {
|
package/dist/merge-source.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./deep-merge.cjs");function i(e,a,r){const c=new Set(a.map(o=>o.code)),n=a.find(o=>o.code===e);return[r,n?.fallbackLocale,e].filter(o=>!!o&&c.has(o)).filter((o,d,f)=>f.indexOf(o)===d)}function m(e,a,r){let c={};for(const n of e)c=t.deepMergeTranslations(c,a(r(n)));return c}async function l(e,a,r){return(await Promise.all(e.map(n=>a(r(n))))).reduce((n,o)=>t.deepMergeTranslations(n,o),{})}function s(e,a){return a?"index":e||"index"}function u(e){return`${e}.json`}function g(e,a){return`pages/${s(e)}/${a}.json`}function b(e){return`assets:i18n:${e.replace(/\//g,":")}`}async function S(e){const a=s(e.pageName,e.disablePageLocales),r=i(e.locale,e.locales,e.globalFallbackLocale),c=await l(r,e.readLocaleFile,u),n=await l(r,e.readLocaleFile,o=>g(a,o));return t.deepMergeTranslations(c,n)}function h(e){return(e??[]).map(a=>typeof a=="string"?{code:a}:{code:a.code,fallbackLocale:a.fallbackLocale})}exports.buildFallbackLocaleChain=i;exports.buildSourcePagePath=g;exports.buildSourceRootPath=u;exports.mergeSourceTranslations=S;exports.mergeTranslationsFromFallbackChain=m;exports.mergeTranslationsFromFallbackChainAsync=l;exports.normalizeConfiguredLocales=h;exports.resolveSourcePageName=s;exports.toSourceStorageKey=b;
|
package/dist/merge-source.mjs
CHANGED
|
@@ -1,21 +1,16 @@
|
|
|
1
1
|
import { deepMergeTranslations as t } from "./deep-merge.mjs";
|
|
2
|
-
function
|
|
3
|
-
const
|
|
4
|
-
return [r,
|
|
2
|
+
function f(e, a, r) {
|
|
3
|
+
const c = new Set(a.map((o) => o.code)), n = a.find((o) => o.code === e);
|
|
4
|
+
return [r, n?.fallbackLocale, e].filter((o) => !!o && c.has(o)).filter((o, i, u) => u.indexOf(o) === i);
|
|
5
5
|
}
|
|
6
6
|
function b(e, a, r) {
|
|
7
|
-
let
|
|
8
|
-
for (const
|
|
9
|
-
|
|
10
|
-
return
|
|
7
|
+
let c = {};
|
|
8
|
+
for (const n of e)
|
|
9
|
+
c = t(c, a(r(n)));
|
|
10
|
+
return c;
|
|
11
11
|
}
|
|
12
12
|
async function l(e, a, r) {
|
|
13
|
-
|
|
14
|
-
for (const c of e) {
|
|
15
|
-
const o = await a(r(c));
|
|
16
|
-
n = t(n, o);
|
|
17
|
-
}
|
|
18
|
-
return n;
|
|
13
|
+
return (await Promise.all(e.map((n) => a(r(n))))).reduce((n, o) => t(n, o), {});
|
|
19
14
|
}
|
|
20
15
|
function s(e, a) {
|
|
21
16
|
return a ? "index" : e || "index";
|
|
@@ -26,26 +21,26 @@ function d(e) {
|
|
|
26
21
|
function g(e, a) {
|
|
27
22
|
return `pages/${s(e)}/${a}.json`;
|
|
28
23
|
}
|
|
29
|
-
function
|
|
24
|
+
function k(e) {
|
|
30
25
|
return `assets:i18n:${e.replace(/\//g, ":")}`;
|
|
31
26
|
}
|
|
32
|
-
async function
|
|
33
|
-
const a = s(e.pageName, e.disablePageLocales), r =
|
|
34
|
-
return t(
|
|
27
|
+
async function h(e) {
|
|
28
|
+
const a = s(e.pageName, e.disablePageLocales), r = f(e.locale, e.locales, e.globalFallbackLocale), c = await l(r, e.readLocaleFile, d), n = await l(r, e.readLocaleFile, (o) => g(a, o));
|
|
29
|
+
return t(c, n);
|
|
35
30
|
}
|
|
36
|
-
function
|
|
31
|
+
function L(e) {
|
|
37
32
|
return (e ?? []).map(
|
|
38
33
|
(a) => typeof a == "string" ? { code: a } : { code: a.code, fallbackLocale: a.fallbackLocale }
|
|
39
34
|
);
|
|
40
35
|
}
|
|
41
36
|
export {
|
|
42
|
-
|
|
37
|
+
f as buildFallbackLocaleChain,
|
|
43
38
|
g as buildSourcePagePath,
|
|
44
39
|
d as buildSourceRootPath,
|
|
45
|
-
|
|
40
|
+
h as mergeSourceTranslations,
|
|
46
41
|
b as mergeTranslationsFromFallbackChain,
|
|
47
42
|
l as mergeTranslationsFromFallbackChainAsync,
|
|
48
|
-
|
|
43
|
+
L as normalizeConfiguredLocales,
|
|
49
44
|
s as resolveSourcePageName,
|
|
50
|
-
|
|
45
|
+
k as toSourceStorageKey
|
|
51
46
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function n(r){return r?typeof r=="object"&&r!==null&&!Array.isArray(r)?r:{}:{}}function o(r){return n(r)}exports.toTranslationRecord=o;exports.toTranslations=n;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Translations } from '@i18n-micro/types';
|
|
2
|
+
/**
|
|
3
|
+
* Normalize unknown fetch/storage payloads into a plain translation object.
|
|
4
|
+
*/
|
|
5
|
+
export declare function toTranslations(data: unknown): Translations;
|
|
6
|
+
/**
|
|
7
|
+
* Normalize unknown payloads into a mutable record (source loader).
|
|
8
|
+
*/
|
|
9
|
+
export declare function toTranslationRecord(data: unknown): Record<string, unknown>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Translations } from '@i18n-micro/types';
|
|
2
|
+
/**
|
|
3
|
+
* Normalize unknown fetch/storage payloads into a plain translation object.
|
|
4
|
+
*/
|
|
5
|
+
export declare function toTranslations(data: unknown): Translations;
|
|
6
|
+
/**
|
|
7
|
+
* Normalize unknown payloads into a mutable record (source loader).
|
|
8
|
+
*/
|
|
9
|
+
export declare function toTranslationRecord(data: unknown): Record<string, unknown>;
|
package/dist/payload-fetch.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("./payload-url.cjs");
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("./normalize.cjs"),i=require("./payload-url.cjs");async function n(a,r,t,s){if(!a.apiBaseServerHost)return{};const e=i.buildTranslationPayloadFetchRequest({apiBaseUrl:a.apiBaseUrl??"_locales",routeName:t,locale:r,isServer:!0,baseURL:a.apiBaseServerHost,apiBaseServerHost:a.apiBaseServerHost,dateBuild:a.dateBuild});try{const o=await s(e.path,{baseURL:e.baseURL,params:e.params});return l.toTranslations(o)}catch{return{}}}exports.fetchTranslationPayloadFromHost=n;
|
package/dist/payload-fetch.mjs
CHANGED
|
@@ -1,28 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const e = i({
|
|
8
|
-
apiBaseUrl: r.apiBaseUrl ?? "_locales",
|
|
1
|
+
import { toTranslations as i } from "./normalize.mjs";
|
|
2
|
+
import { buildTranslationPayloadFetchRequest as l } from "./payload-url.mjs";
|
|
3
|
+
async function n(a, r, t, s) {
|
|
4
|
+
if (!a.apiBaseServerHost) return {};
|
|
5
|
+
const e = l({
|
|
6
|
+
apiBaseUrl: a.apiBaseUrl ?? "_locales",
|
|
9
7
|
routeName: t,
|
|
10
|
-
locale:
|
|
8
|
+
locale: r,
|
|
11
9
|
isServer: !0,
|
|
12
|
-
baseURL:
|
|
13
|
-
apiBaseServerHost:
|
|
14
|
-
dateBuild:
|
|
10
|
+
baseURL: a.apiBaseServerHost,
|
|
11
|
+
apiBaseServerHost: a.apiBaseServerHost,
|
|
12
|
+
dateBuild: a.dateBuild
|
|
15
13
|
});
|
|
16
14
|
try {
|
|
17
15
|
const o = await s(e.path, {
|
|
18
16
|
baseURL: e.baseURL,
|
|
19
17
|
params: e.params
|
|
20
18
|
});
|
|
21
|
-
return
|
|
19
|
+
return i(o);
|
|
22
20
|
} catch {
|
|
23
21
|
return {};
|
|
24
22
|
}
|
|
25
23
|
}
|
|
26
24
|
export {
|
|
27
|
-
|
|
25
|
+
n as fetchTranslationPayloadFromHost
|
|
28
26
|
};
|
package/dist/runtime-config.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function o(e){if(typeof e!="string")return;const t=e.trim();return t.length>0?t:void 0}function L(e){if(Array.isArray(e)){const t=e.map(l=>o(l)).filter(l=>!!l);return t.length>0?t:void 0}if(typeof e=="string"){const t=e.split(",").map(l=>l.trim()).filter(l=>l.length>0);return t.length>0?t:void 0}}function m(){return{defaultLocale:o(process.env.NUXT_I18N_DEFAULT_LOCALE)??o(process.env.NUXT_PUBLIC_I18N_RUNTIME_DEFAULT_LOCALE),fallbackLocale:o(process.env.NUXT_I18N_FALLBACK_LOCALE)??o(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:o(process.env.NUXT_I18N_STRATEGY)??o(process.env.NUXT_PUBLIC_I18N_RUNTIME_STRATEGY)}}function g(e){const t=e?.i18nRuntime;if(!t||typeof t!="object")return{};const l=t;return{defaultLocale:o(l.defaultLocale),fallbackLocale:o(l.fallbackLocale),disabledLocales:L(l.disabledLocales),strategy:o(l.strategy)}}function v(e){return Object.assign({},e)}function b(e){return e.map(t=>v(t))}function y(e){const t=m(),l=g(e);return{defaultLocale:l.defaultLocale??t.defaultLocale,fallbackLocale:l.fallbackLocale??t.fallbackLocale,disabledLocales:l.disabledLocales??t.disabledLocales,strategy:l.strategy??t.strategy}}function p(e,t,l=a=>console.warn(a)){const a=y(t),n=b(e.locales??[]);if(a.strategy&&a.strategy!==e.strategy&&l(`[nuxt-i18n-micro] runtime i18n strategy override is ignored: "${a.strategy}" (build strategy: "${e.strategy}"). Build a separate artifact for each strategy.`),a.disabledLocales&&a.disabledLocales.length>0){const r=new Set(a.disabledLocales);for(const u of n)u.disabled=r.has(u.code)}const i=n.filter(r=>!r.disabled);if(i.length===0)return a.disabledLocales&&a.disabledLocales.length>0&&l("[nuxt-i18n-micro] runtime disabledLocales override would disable all locales; override ignored."),{...e,locales:b(e.locales??[])};const _=new Set(n.map(r=>r.code));let c=a.defaultLocale??e.defaultLocale,s=a.fallbackLocale??e.fallbackLocale;s&&!_.has(s)&&(l(`[nuxt-i18n-micro] runtime fallbackLocale "${s}" is not defined in locales; override ignored.`),s=e.fallbackLocale);const f=new Set(i.map(r=>r.code)),d=i[0]?.code??e.defaultLocale??"en";return(!c||!f.has(c))&&(a.defaultLocale?l(`[nuxt-i18n-micro] runtime defaultLocale "${a.defaultLocale}" is not enabled; falling back to "${d}".`):c&&!f.has(c)&&l(`[nuxt-i18n-micro] defaultLocale "${c}" is disabled by runtime overrides; falling back to "${d}".`),c=d),{...e,locales:n,defaultLocale:c,fallbackLocale:s}}exports.resolveI18nConfigWithRuntimeOverrides=p;
|
package/dist/runtime-config.mjs
CHANGED
|
@@ -1,69 +1,75 @@
|
|
|
1
|
-
function
|
|
2
|
-
if (typeof
|
|
3
|
-
const a =
|
|
1
|
+
function o(e) {
|
|
2
|
+
if (typeof e != "string") return;
|
|
3
|
+
const a = e.trim();
|
|
4
4
|
return a.length > 0 ? a : void 0;
|
|
5
5
|
}
|
|
6
|
-
function L(
|
|
7
|
-
if (Array.isArray(
|
|
8
|
-
const a =
|
|
6
|
+
function L(e) {
|
|
7
|
+
if (Array.isArray(e)) {
|
|
8
|
+
const a = e.map((l) => o(l)).filter((l) => !!l);
|
|
9
9
|
return a.length > 0 ? a : void 0;
|
|
10
10
|
}
|
|
11
|
-
if (typeof
|
|
12
|
-
const a =
|
|
11
|
+
if (typeof e == "string") {
|
|
12
|
+
const a = e.split(",").map((l) => l.trim()).filter((l) => l.length > 0);
|
|
13
13
|
return a.length > 0 ? a : void 0;
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
function
|
|
16
|
+
function m() {
|
|
17
17
|
return {
|
|
18
|
-
defaultLocale:
|
|
19
|
-
fallbackLocale:
|
|
18
|
+
defaultLocale: o(process.env.NUXT_I18N_DEFAULT_LOCALE) ?? o(process.env.NUXT_PUBLIC_I18N_RUNTIME_DEFAULT_LOCALE),
|
|
19
|
+
fallbackLocale: o(process.env.NUXT_I18N_FALLBACK_LOCALE) ?? o(process.env.NUXT_PUBLIC_I18N_RUNTIME_FALLBACK_LOCALE),
|
|
20
20
|
disabledLocales: L(process.env.NUXT_I18N_DISABLED_LOCALES) ?? L(process.env.NUXT_PUBLIC_I18N_RUNTIME_DISABLED_LOCALES),
|
|
21
|
-
strategy:
|
|
21
|
+
strategy: o(process.env.NUXT_I18N_STRATEGY) ?? o(process.env.NUXT_PUBLIC_I18N_RUNTIME_STRATEGY)
|
|
22
22
|
};
|
|
23
23
|
}
|
|
24
|
-
function
|
|
25
|
-
const a =
|
|
24
|
+
function g(e) {
|
|
25
|
+
const a = e?.i18nRuntime;
|
|
26
26
|
if (!a || typeof a != "object") return {};
|
|
27
|
-
const
|
|
27
|
+
const l = a;
|
|
28
28
|
return {
|
|
29
|
-
defaultLocale:
|
|
30
|
-
fallbackLocale:
|
|
31
|
-
disabledLocales: L(
|
|
32
|
-
strategy:
|
|
29
|
+
defaultLocale: o(l.defaultLocale),
|
|
30
|
+
fallbackLocale: o(l.fallbackLocale),
|
|
31
|
+
disabledLocales: L(l.disabledLocales),
|
|
32
|
+
strategy: o(l.strategy)
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
|
-
function
|
|
36
|
-
|
|
35
|
+
function v(e) {
|
|
36
|
+
return Object.assign({}, e);
|
|
37
|
+
}
|
|
38
|
+
function _(e) {
|
|
39
|
+
return e.map((a) => v(a));
|
|
40
|
+
}
|
|
41
|
+
function p(e) {
|
|
42
|
+
const a = m(), l = g(e);
|
|
37
43
|
return {
|
|
38
|
-
defaultLocale:
|
|
39
|
-
fallbackLocale:
|
|
40
|
-
disabledLocales:
|
|
41
|
-
strategy:
|
|
44
|
+
defaultLocale: l.defaultLocale ?? a.defaultLocale,
|
|
45
|
+
fallbackLocale: l.fallbackLocale ?? a.fallbackLocale,
|
|
46
|
+
disabledLocales: l.disabledLocales ?? a.disabledLocales,
|
|
47
|
+
strategy: l.strategy ?? a.strategy
|
|
42
48
|
};
|
|
43
49
|
}
|
|
44
|
-
function
|
|
45
|
-
const t =
|
|
46
|
-
if (t.strategy && t.strategy !==
|
|
47
|
-
`[nuxt-i18n-micro] runtime i18n strategy override is ignored: "${t.strategy}" (build strategy: "${
|
|
50
|
+
function y(e, a, l = (t) => console.warn(t)) {
|
|
51
|
+
const t = p(a), n = _(e.locales ?? []);
|
|
52
|
+
if (t.strategy && t.strategy !== e.strategy && l(
|
|
53
|
+
`[nuxt-i18n-micro] runtime i18n strategy override is ignored: "${t.strategy}" (build strategy: "${e.strategy}"). Build a separate artifact for each strategy.`
|
|
48
54
|
), t.disabledLocales && t.disabledLocales.length > 0) {
|
|
49
|
-
const
|
|
50
|
-
for (const u of
|
|
51
|
-
u.disabled =
|
|
55
|
+
const r = new Set(t.disabledLocales);
|
|
56
|
+
for (const u of n)
|
|
57
|
+
u.disabled = r.has(u.code);
|
|
52
58
|
}
|
|
53
|
-
const
|
|
54
|
-
if (
|
|
55
|
-
return t.disabledLocales && t.disabledLocales.length > 0 &&
|
|
56
|
-
const
|
|
57
|
-
let
|
|
58
|
-
|
|
59
|
-
const f = new Set(
|
|
60
|
-
return (!
|
|
61
|
-
...
|
|
62
|
-
locales:
|
|
63
|
-
defaultLocale:
|
|
64
|
-
fallbackLocale:
|
|
59
|
+
const i = n.filter((r) => !r.disabled);
|
|
60
|
+
if (i.length === 0)
|
|
61
|
+
return t.disabledLocales && t.disabledLocales.length > 0 && l("[nuxt-i18n-micro] runtime disabledLocales override would disable all locales; override ignored."), { ...e, locales: _(e.locales ?? []) };
|
|
62
|
+
const b = new Set(n.map((r) => r.code));
|
|
63
|
+
let c = t.defaultLocale ?? e.defaultLocale, s = t.fallbackLocale ?? e.fallbackLocale;
|
|
64
|
+
s && !b.has(s) && (l(`[nuxt-i18n-micro] runtime fallbackLocale "${s}" is not defined in locales; override ignored.`), s = e.fallbackLocale);
|
|
65
|
+
const f = new Set(i.map((r) => r.code)), d = i[0]?.code ?? e.defaultLocale ?? "en";
|
|
66
|
+
return (!c || !f.has(c)) && (t.defaultLocale ? l(`[nuxt-i18n-micro] runtime defaultLocale "${t.defaultLocale}" is not enabled; falling back to "${d}".`) : c && !f.has(c) && l(`[nuxt-i18n-micro] defaultLocale "${c}" is disabled by runtime overrides; falling back to "${d}".`), c = d), {
|
|
67
|
+
...e,
|
|
68
|
+
locales: n,
|
|
69
|
+
defaultLocale: c,
|
|
70
|
+
fallbackLocale: s
|
|
65
71
|
};
|
|
66
72
|
}
|
|
67
73
|
export {
|
|
68
|
-
|
|
74
|
+
y as resolveI18nConfigWithRuntimeOverrides
|
|
69
75
|
};
|
package/dist/source-loader.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./merge-source.cjs")
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./merge-source.cjs"),n=require("./normalize.cjs");async function c(r,o){return e.mergeSourceTranslations({...o,readLocaleFile:async t=>{const a=await r.getItem(e.toSourceStorageKey(t));return n.toTranslationRecord(a)}})}exports.loadSourceTranslationsFromStorage=c;
|
package/dist/source-loader.mjs
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import { mergeSourceTranslations as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const n = await r.getItem(i(o));
|
|
10
|
-
return u(n);
|
|
1
|
+
import { mergeSourceTranslations as a, toSourceStorageKey as n } from "./merge-source.mjs";
|
|
2
|
+
import { toTranslationRecord as c } from "./normalize.mjs";
|
|
3
|
+
async function l(o, r) {
|
|
4
|
+
return a({
|
|
5
|
+
...r,
|
|
6
|
+
readLocaleFile: async (e) => {
|
|
7
|
+
const t = await o.getItem(n(e));
|
|
8
|
+
return c(t);
|
|
11
9
|
}
|
|
12
10
|
});
|
|
13
11
|
}
|
|
14
12
|
export {
|
|
15
|
-
|
|
13
|
+
l as loadSourceTranslationsFromStorage
|
|
16
14
|
};
|
package/package.json
CHANGED
|
@@ -1,27 +1,34 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@i18n-micro/utils",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "Framework-agnostic utilities for Nuxt I18n Micro (granular subpath imports).",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
5
|
+
"keywords": [
|
|
6
|
+
"i18n",
|
|
7
|
+
"locale",
|
|
8
|
+
"translations",
|
|
9
|
+
"utils"
|
|
10
|
+
],
|
|
11
|
+
"homepage": "https://github.com/s00d/nuxt-i18n-micro/tree/main/packages/utils#readme",
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/s00d/nuxt-i18n-micro/issues"
|
|
9
14
|
},
|
|
10
15
|
"license": "MIT",
|
|
11
|
-
"type": "module",
|
|
12
|
-
"sideEffects": false,
|
|
13
16
|
"author": {
|
|
14
17
|
"name": "s00d",
|
|
15
18
|
"email": "Virus191288@gmail.com",
|
|
16
19
|
"url": "https://s00d.github.io/"
|
|
17
20
|
},
|
|
18
|
-
"
|
|
19
|
-
|
|
20
|
-
"url": "https://github.com/s00d/nuxt-i18n-micro
|
|
21
|
-
|
|
22
|
-
"engines": {
|
|
23
|
-
"node": ">=18"
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/s00d/nuxt-i18n-micro.git",
|
|
24
|
+
"directory": "packages/utils"
|
|
24
25
|
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist",
|
|
28
|
+
"README.md"
|
|
29
|
+
],
|
|
30
|
+
"type": "module",
|
|
31
|
+
"sideEffects": false,
|
|
25
32
|
"exports": {
|
|
26
33
|
"./deep-merge": {
|
|
27
34
|
"import": {
|
|
@@ -199,6 +206,17 @@
|
|
|
199
206
|
},
|
|
200
207
|
"default": "./dist/runtime-config.mjs"
|
|
201
208
|
},
|
|
209
|
+
"./normalize": {
|
|
210
|
+
"import": {
|
|
211
|
+
"types": "./dist/normalize.d.ts",
|
|
212
|
+
"default": "./dist/normalize.mjs"
|
|
213
|
+
},
|
|
214
|
+
"require": {
|
|
215
|
+
"types": "./dist/normalize.d.cts",
|
|
216
|
+
"default": "./dist/normalize.cjs"
|
|
217
|
+
},
|
|
218
|
+
"default": "./dist/normalize.mjs"
|
|
219
|
+
},
|
|
202
220
|
"./build": {
|
|
203
221
|
"import": {
|
|
204
222
|
"types": "./dist/build.d.ts",
|
|
@@ -216,26 +234,19 @@
|
|
|
216
234
|
"publishConfig": {
|
|
217
235
|
"access": "public"
|
|
218
236
|
},
|
|
219
|
-
"keywords": [
|
|
220
|
-
"i18n",
|
|
221
|
-
"translations",
|
|
222
|
-
"utils",
|
|
223
|
-
"locale"
|
|
224
|
-
],
|
|
225
|
-
"files": [
|
|
226
|
-
"dist",
|
|
227
|
-
"README.md"
|
|
228
|
-
],
|
|
229
237
|
"dependencies": {
|
|
230
238
|
"globby": "^14.1.0",
|
|
231
|
-
"@i18n-micro/types": "1.2.
|
|
239
|
+
"@i18n-micro/types": "1.2.4"
|
|
232
240
|
},
|
|
233
241
|
"devDependencies": {
|
|
234
242
|
"publint": "^0.3.17",
|
|
235
243
|
"vite": "^7.3.1",
|
|
236
244
|
"vite-plugin-dts": "^4.5.4",
|
|
237
245
|
"vitest": "^3.2.4",
|
|
238
|
-
"@i18n-micro/test-utils": "1.2.
|
|
246
|
+
"@i18n-micro/test-utils": "1.2.2"
|
|
247
|
+
},
|
|
248
|
+
"engines": {
|
|
249
|
+
"node": ">=18"
|
|
239
250
|
},
|
|
240
251
|
"scripts": {
|
|
241
252
|
"build": "vite build",
|