@koine/i18n 2.0.0-beta.145 → 2.0.0-beta.147
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/adapter-js/generators/t.cjs.js +22 -20
- package/adapter-js/generators/t.d.ts +1 -1
- package/adapter-js/generators/t.esm.js +22 -20
- package/adapter-next/generators/router-app/i18nServer.cjs.js +4 -13
- package/adapter-next/generators/router-app/i18nServer.esm.js +4 -13
- package/adapter-next/generators/webpack-define.cjs.js +29 -29
- package/adapter-next/generators/webpack-define.esm.js +29 -29
- package/compiler/code/data-translations.cjs.js +58 -45
- package/compiler/code/data-translations.esm.js +59 -46
- package/compiler/types.d.ts +5 -0
- package/package.json +3 -3
|
@@ -10,35 +10,37 @@ var imports = require('../../compiler/imports.cjs.js');
|
|
|
10
10
|
var types = require('./types.cjs.js');
|
|
11
11
|
|
|
12
12
|
function getTFunction(t, a) {
|
|
13
|
-
let { defaultLocale: r } = a, { values:
|
|
14
|
-
|
|
15
|
-
...
|
|
16
|
-
[
|
|
13
|
+
let { defaultLocale: r, single: o } = a, { values: l, params: p, plural: i, typeValue: u, equalValues: d } = t, y = !o && !d, P = [], $ = "count";
|
|
14
|
+
i && (p = p ? {
|
|
15
|
+
...p,
|
|
16
|
+
[$]: "number"
|
|
17
17
|
} : {
|
|
18
|
-
[
|
|
19
|
-
}),
|
|
18
|
+
[$]: "number"
|
|
19
|
+
}), p && P.push({
|
|
20
20
|
name: "params",
|
|
21
|
-
type: helpers.compileDataParamsToType(
|
|
21
|
+
type: helpers.compileDataParamsToType(p),
|
|
22
22
|
optional: !1
|
|
23
|
-
}),
|
|
23
|
+
}), P.push({
|
|
24
24
|
name: "locale",
|
|
25
25
|
type: "I18n.Locale",
|
|
26
26
|
optional: !0
|
|
27
27
|
});
|
|
28
|
-
let
|
|
28
|
+
let h = [
|
|
29
29
|
f.types
|
|
30
|
-
],
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
30
|
+
], I = y ? "locale = locale || global." + helpers.GLOBAL_I18N_IDENTIFIER + "; " : "";
|
|
31
|
+
I += "return ";
|
|
32
|
+
let x = "";
|
|
33
|
+
return utils.isPrimitive(l) ? x += c(l) : x += function(t, a, r) {
|
|
34
|
+
let n = "";
|
|
35
|
+
if (r) for(let r in a){
|
|
36
|
+
let o = a[r];
|
|
37
|
+
r === t || utils.areEqual(o, a[t]) || (n += `locale === "${r}" ? ${c(o)} : `);
|
|
36
38
|
}
|
|
37
|
-
return
|
|
38
|
-
}(r,
|
|
39
|
-
body:
|
|
40
|
-
args:
|
|
41
|
-
imports:
|
|
39
|
+
return n + c(a[t]);
|
|
40
|
+
}(r, l, y), i && (h.push(f.tPluralise), x = `tPluralise(${x}, params.${$})`), p && (!i || i && !Object.keys(p).every((e)=>e === $)) && ("Primitive" === u ? (h.push(f.tInterpolateParams), x = `tInterpolateParams(${x}, params)`) : ("Array" === u || "Object" === u) && (h.push(f.tInterpolateParamsDeep), x = `tInterpolateParamsDeep(${x}, params)`)), {
|
|
41
|
+
body: I + x,
|
|
42
|
+
args: P,
|
|
43
|
+
imports: h
|
|
42
44
|
};
|
|
43
45
|
}
|
|
44
46
|
function c(e) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type FunctionsCompilerDataArg } from "../../compiler/functions";
|
|
2
2
|
import { ImportsCompiler } from "../../compiler/imports";
|
|
3
3
|
import type { I18nCompiler } from "../../compiler/types";
|
|
4
|
-
export declare function getTFunction(translation: I18nCompiler.DataTranslation, options: Pick<I18nCompiler.Config, "defaultLocale">): {
|
|
4
|
+
export declare function getTFunction(translation: I18nCompiler.DataTranslation, options: Pick<I18nCompiler.Config, "defaultLocale" | "single">): {
|
|
5
5
|
body: string;
|
|
6
6
|
args: FunctionsCompilerDataArg[];
|
|
7
7
|
imports: ImportsCompiler[];
|
|
@@ -6,35 +6,37 @@ import { ImportsCompiler } from '../../compiler/imports.esm.js';
|
|
|
6
6
|
import { getImportTypes } from './types.esm.js';
|
|
7
7
|
|
|
8
8
|
function getTFunction(t, a) {
|
|
9
|
-
let { defaultLocale: r } = a, { values:
|
|
10
|
-
|
|
11
|
-
...
|
|
12
|
-
[
|
|
9
|
+
let { defaultLocale: r, single: o } = a, { values: l, params: p, plural: i, typeValue: u, equalValues: d } = t, y = !o && !d, P = [], $ = "count";
|
|
10
|
+
i && (p = p ? {
|
|
11
|
+
...p,
|
|
12
|
+
[$]: "number"
|
|
13
13
|
} : {
|
|
14
|
-
[
|
|
15
|
-
}),
|
|
14
|
+
[$]: "number"
|
|
15
|
+
}), p && P.push({
|
|
16
16
|
name: "params",
|
|
17
|
-
type: compileDataParamsToType(
|
|
17
|
+
type: compileDataParamsToType(p),
|
|
18
18
|
optional: !1
|
|
19
|
-
}),
|
|
19
|
+
}), P.push({
|
|
20
20
|
name: "locale",
|
|
21
21
|
type: "I18n.Locale",
|
|
22
22
|
optional: !0
|
|
23
23
|
});
|
|
24
|
-
let
|
|
24
|
+
let h = [
|
|
25
25
|
f.types
|
|
26
|
-
],
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
], I = y ? "locale = locale || global." + GLOBAL_I18N_IDENTIFIER + "; " : "";
|
|
27
|
+
I += "return ";
|
|
28
|
+
let x = "";
|
|
29
|
+
return isPrimitive(l) ? x += c(l) : x += function(t, a, r) {
|
|
30
|
+
let n = "";
|
|
31
|
+
if (r) for(let r in a){
|
|
32
|
+
let o = a[r];
|
|
33
|
+
r === t || areEqual(o, a[t]) || (n += `locale === "${r}" ? ${c(o)} : `);
|
|
32
34
|
}
|
|
33
|
-
return
|
|
34
|
-
}(r,
|
|
35
|
-
body:
|
|
36
|
-
args:
|
|
37
|
-
imports:
|
|
35
|
+
return n + c(a[t]);
|
|
36
|
+
}(r, l, y), i && (h.push(f.tPluralise), x = `tPluralise(${x}, params.${$})`), p && (!i || i && !Object.keys(p).every((e)=>e === $)) && ("Primitive" === u ? (h.push(f.tInterpolateParams), x = `tInterpolateParams(${x}, params)`) : ("Array" === u || "Object" === u) && (h.push(f.tInterpolateParamsDeep), x = `tInterpolateParamsDeep(${x}, params)`)), {
|
|
37
|
+
body: I + x,
|
|
38
|
+
args: P,
|
|
39
|
+
imports: h
|
|
38
40
|
};
|
|
39
41
|
}
|
|
40
42
|
function c(e) {
|
|
@@ -2,9 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
var createAdapter = require('../../../compiler/createAdapter.cjs.js');
|
|
4
4
|
|
|
5
|
-
var i = createAdapter.createGenerator("next", (
|
|
6
|
-
let { options: { adapter: { modularize: t } } } = e;
|
|
7
|
-
return {
|
|
5
|
+
var i = createAdapter.createGenerator("next", (o)=>({
|
|
8
6
|
i18nServer: {
|
|
9
7
|
dir: createAdapter.createGenerator.dirs.server,
|
|
10
8
|
name: "i18nServer",
|
|
@@ -12,9 +10,7 @@ var i = createAdapter.createGenerator("next", (e)=>{
|
|
|
12
10
|
index: !0,
|
|
13
11
|
content: ()=>`
|
|
14
12
|
import { defaultLocale } from "../defaultLocale";
|
|
15
|
-
import { locales } from "../locales"
|
|
16
|
-
import * as $to from "../$to";
|
|
17
|
-
import * as $t from "../$t";` : ""}
|
|
13
|
+
import { locales } from "../locales";
|
|
18
14
|
import { getLocale } from "./getLocale";
|
|
19
15
|
import { getTo } from "./getTo";
|
|
20
16
|
import { getT } from "./getT";
|
|
@@ -59,17 +55,12 @@ export const i18nServer = {
|
|
|
59
55
|
/** {@link getT} */
|
|
60
56
|
getT,
|
|
61
57
|
/** {@link getTo} */
|
|
62
|
-
getTo
|
|
63
|
-
/** {@link $t} */
|
|
64
|
-
$t,
|
|
65
|
-
/** {@link $to} */
|
|
66
|
-
$to,` : ""}
|
|
58
|
+
getTo,
|
|
67
59
|
};
|
|
68
60
|
|
|
69
61
|
export default i18nServer;
|
|
70
62
|
`
|
|
71
63
|
}
|
|
72
|
-
};
|
|
73
|
-
});
|
|
64
|
+
}));
|
|
74
65
|
|
|
75
66
|
module.exports = i;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { createGenerator } from '../../../compiler/createAdapter.esm.js';
|
|
2
2
|
|
|
3
|
-
var i = createGenerator("next", (
|
|
4
|
-
let { options: { adapter: { modularize: t } } } = e;
|
|
5
|
-
return {
|
|
3
|
+
var i = createGenerator("next", (o)=>({
|
|
6
4
|
i18nServer: {
|
|
7
5
|
dir: createGenerator.dirs.server,
|
|
8
6
|
name: "i18nServer",
|
|
@@ -10,9 +8,7 @@ var i = createGenerator("next", (e)=>{
|
|
|
10
8
|
index: !0,
|
|
11
9
|
content: ()=>`
|
|
12
10
|
import { defaultLocale } from "../defaultLocale";
|
|
13
|
-
import { locales } from "../locales"
|
|
14
|
-
import * as $to from "../$to";
|
|
15
|
-
import * as $t from "../$t";` : ""}
|
|
11
|
+
import { locales } from "../locales";
|
|
16
12
|
import { getLocale } from "./getLocale";
|
|
17
13
|
import { getTo } from "./getTo";
|
|
18
14
|
import { getT } from "./getT";
|
|
@@ -57,17 +53,12 @@ export const i18nServer = {
|
|
|
57
53
|
/** {@link getT} */
|
|
58
54
|
getT,
|
|
59
55
|
/** {@link getTo} */
|
|
60
|
-
getTo
|
|
61
|
-
/** {@link $t} */
|
|
62
|
-
$t,
|
|
63
|
-
/** {@link $to} */
|
|
64
|
-
$to,` : ""}
|
|
56
|
+
getTo,
|
|
65
57
|
};
|
|
66
58
|
|
|
67
59
|
export default i18nServer;
|
|
68
60
|
`
|
|
69
61
|
}
|
|
70
|
-
};
|
|
71
|
-
});
|
|
62
|
+
}));
|
|
72
63
|
|
|
73
64
|
export { i as default };
|
|
@@ -18,7 +18,7 @@ var d = createAdapter.createGenerator("next", (u)=>{
|
|
|
18
18
|
let { config: d, options: $ } = u, { debug: f } = d, { cwd: b, output: j } = $.write || {
|
|
19
19
|
cwd: "",
|
|
20
20
|
output: ""
|
|
21
|
-
}, g = index.resolveGlobalizeOption($.adapter.globalize),
|
|
21
|
+
}, { modularize: g } = $.adapter, y = index.resolveGlobalizeOption($.adapter.globalize), I = y.functions.routes ? u.routes.byId : {}, k = y.functions.translations ? u.translations : {};
|
|
22
22
|
return {
|
|
23
23
|
webpackDefineGranularTypes: {
|
|
24
24
|
dir: createAdapter.createGenerator.dirs.internal,
|
|
@@ -31,12 +31,12 @@ var d = createAdapter.createGenerator("next", (u)=>{
|
|
|
31
31
|
export {};
|
|
32
32
|
|
|
33
33
|
declare global {
|
|
34
|
-
${Object.keys(
|
|
35
|
-
let { id: n, fnName: a, params: o } =
|
|
34
|
+
${Object.keys(I).map((t)=>{
|
|
35
|
+
let { id: n, fnName: a, params: o } = I[t], r = `var ${y.prefixSafe}${a}: (`;
|
|
36
36
|
return o ? r += `params: ${helpers.compileDataParamsToType(o)}, ` : r += "", r += `locale?: ${e}) => import("../types").I18n.RoutePathnames["${n}"]`;
|
|
37
37
|
}).join(";\n ")};
|
|
38
|
-
${Object.keys(
|
|
39
|
-
let { fnName: n, params: a, values: o } =
|
|
38
|
+
${Object.keys(k).map((t)=>{
|
|
39
|
+
let { fnName: n, params: a, values: o } = k[t], r = `var ${y.prefixSafe}${n}: (`;
|
|
40
40
|
return a ? r += `params: ${helpers.compileDataParamsToType(a)}, ` : r += "", r += `locale?: ${e}) => ${JSON.stringify(o[d.defaultLocale])}`;
|
|
41
41
|
}).join(";\n ")};
|
|
42
42
|
}
|
|
@@ -52,29 +52,29 @@ declare global {
|
|
|
52
52
|
const { join } = require("path");
|
|
53
53
|
const { DefinePlugin } = require("webpack");
|
|
54
54
|
|
|
55
|
+
const base = join("${b}", "${j}");
|
|
56
|
+
|
|
55
57
|
module.exports = {
|
|
56
|
-
${Object.keys(
|
|
57
|
-
let n =
|
|
58
|
-
return `${
|
|
58
|
+
${Object.keys(I).map((t)=>{
|
|
59
|
+
let n = I[t], { fnName: a } = n, { args: o, body: i } = to.getToFunction(n, d), { dir: l } = $.routes.functions;
|
|
60
|
+
return `${y.prefixSafe}${a}: DefinePlugin.runtimeValue(() => ` + m([
|
|
59
61
|
"`(function(" + o.map((e)=>e.name).join(", ") + ") {",
|
|
60
|
-
"locale = locale || global." + helpers.GLOBAL_I18N_IDENTIFIER + ";",
|
|
61
62
|
formatTo.formatTo(d).$outInline(),
|
|
62
|
-
|
|
63
|
+
i,
|
|
63
64
|
"})`,",
|
|
64
|
-
`{ fileDependencies: [join(
|
|
65
|
+
`{ fileDependencies: [join(base, ${g ? `"${l}", "${a}.ts"` : `"${l}.ts"`})] }`
|
|
65
66
|
].join(" "));
|
|
66
67
|
}).join("),\n ")}),
|
|
67
|
-
${Object.keys(
|
|
68
|
-
let r =
|
|
69
|
-
return `${
|
|
70
|
-
"`(function(" +
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
"return " + f,
|
|
68
|
+
${Object.keys(k).map((e)=>{
|
|
69
|
+
let r = k[e], { fnName: i, params: l, typeValue: s, plural: p } = r, { args: c, body: u } = t.getTFunction(r, d), { dir: f } = $.translations.functions;
|
|
70
|
+
return `${y.prefixSafe}${i}: DefinePlugin.runtimeValue(() => ` + m([
|
|
71
|
+
"`(function(" + c.map((e)=>e.name).join(", ") + ") {",
|
|
72
|
+
l ? tInterpolateParams.tInterpolateParams($.translations.tokens.dynamicDelimiters).$outInline() : "",
|
|
73
|
+
l ? "Primitive" === s ? "" : tInterpolateParamsDeep.tInterpolateParamsDeep().$outInline() : "",
|
|
74
|
+
p ? tPluralise.tPluralise().$outInline() : "",
|
|
75
|
+
u,
|
|
76
76
|
"})`,",
|
|
77
|
-
`{ fileDependencies: [join(
|
|
77
|
+
`{ fileDependencies: [join(base, ${g ? `"${f}", "${i}.ts"` : `"${f}.ts"`})] }`
|
|
78
78
|
].join(" "));
|
|
79
79
|
}).join(`),\n `)}),
|
|
80
80
|
};
|
|
@@ -127,7 +127,7 @@ declare global {
|
|
|
127
127
|
*/
|
|
128
128
|
${a}
|
|
129
129
|
|
|
130
|
-
var ${
|
|
130
|
+
var ${y.prefix}: {
|
|
131
131
|
t: GlobalT;
|
|
132
132
|
to: GlobalTo;
|
|
133
133
|
}
|
|
@@ -146,7 +146,7 @@ const { join } = require("path");
|
|
|
146
146
|
const { DefinePlugin } = require("webpack");
|
|
147
147
|
|
|
148
148
|
module.exports = {
|
|
149
|
-
${
|
|
149
|
+
${y.prefix}: DefinePlugin.runtimeValue(
|
|
150
150
|
(_ctx) => {
|
|
151
151
|
${"internal" === f ? 'console.log("[@koine/i18n]:webpack-define:ctx.module", _ctx.module);' : ""};
|
|
152
152
|
return {
|
|
@@ -163,9 +163,9 @@ module.exports = {
|
|
|
163
163
|
})}
|
|
164
164
|
|
|
165
165
|
const lookup = {
|
|
166
|
-
${Object.keys(
|
|
167
|
-
let { args: t, body: n } = to.getToFunction(
|
|
168
|
-
return `"${e}": (${t.map((e)=>
|
|
166
|
+
${Object.keys(I).map((e)=>{
|
|
167
|
+
let { args: t, body: n } = to.getToFunction(I[e], d);
|
|
168
|
+
return `"${e}": (${t.map((e)=>e.name).join(", ")}) => { ${n} }`;
|
|
169
169
|
}).join(",\n ")}
|
|
170
170
|
};
|
|
171
171
|
|
|
@@ -183,9 +183,9 @@ module.exports = {
|
|
|
183
183
|
${tInterpolateParamsDeep.tInterpolateParamsDeep().$outInline()}
|
|
184
184
|
|
|
185
185
|
const lookup = {
|
|
186
|
-
${Object.keys(
|
|
187
|
-
let n =
|
|
188
|
-
return `"${a}": (${o.map((e)=>
|
|
186
|
+
${Object.keys(k).map((e)=>{
|
|
187
|
+
let n = k[e], { fullKey: a } = n, { args: o, body: r } = t.getTFunction(n, d);
|
|
188
|
+
return `"${a}": (${o.map((e)=>e.name).join(", ")}) => { ${r} }`;
|
|
189
189
|
}).join(",\n ")}
|
|
190
190
|
};
|
|
191
191
|
|
|
@@ -16,7 +16,7 @@ var d = createGenerator("next", (u)=>{
|
|
|
16
16
|
let { config: d, options: $ } = u, { debug: f } = d, { cwd: b, output: j } = $.write || {
|
|
17
17
|
cwd: "",
|
|
18
18
|
output: ""
|
|
19
|
-
}, g = resolveGlobalizeOption($.adapter.globalize),
|
|
19
|
+
}, { modularize: g } = $.adapter, y = resolveGlobalizeOption($.adapter.globalize), I = y.functions.routes ? u.routes.byId : {}, k = y.functions.translations ? u.translations : {};
|
|
20
20
|
return {
|
|
21
21
|
webpackDefineGranularTypes: {
|
|
22
22
|
dir: createGenerator.dirs.internal,
|
|
@@ -29,12 +29,12 @@ var d = createGenerator("next", (u)=>{
|
|
|
29
29
|
export {};
|
|
30
30
|
|
|
31
31
|
declare global {
|
|
32
|
-
${Object.keys(
|
|
33
|
-
let { id: n, fnName: a, params: o } =
|
|
32
|
+
${Object.keys(I).map((t)=>{
|
|
33
|
+
let { id: n, fnName: a, params: o } = I[t], r = `var ${y.prefixSafe}${a}: (`;
|
|
34
34
|
return o ? r += `params: ${compileDataParamsToType(o)}, ` : r += "", r += `locale?: ${e}) => import("../types").I18n.RoutePathnames["${n}"]`;
|
|
35
35
|
}).join(";\n ")};
|
|
36
|
-
${Object.keys(
|
|
37
|
-
let { fnName: n, params: a, values: o } =
|
|
36
|
+
${Object.keys(k).map((t)=>{
|
|
37
|
+
let { fnName: n, params: a, values: o } = k[t], r = `var ${y.prefixSafe}${n}: (`;
|
|
38
38
|
return a ? r += `params: ${compileDataParamsToType(a)}, ` : r += "", r += `locale?: ${e}) => ${JSON.stringify(o[d.defaultLocale])}`;
|
|
39
39
|
}).join(";\n ")};
|
|
40
40
|
}
|
|
@@ -50,29 +50,29 @@ declare global {
|
|
|
50
50
|
const { join } = require("path");
|
|
51
51
|
const { DefinePlugin } = require("webpack");
|
|
52
52
|
|
|
53
|
+
const base = join("${b}", "${j}");
|
|
54
|
+
|
|
53
55
|
module.exports = {
|
|
54
|
-
${Object.keys(
|
|
55
|
-
let n =
|
|
56
|
-
return `${
|
|
56
|
+
${Object.keys(I).map((t)=>{
|
|
57
|
+
let n = I[t], { fnName: a } = n, { args: o, body: i } = getToFunction(n, d), { dir: l } = $.routes.functions;
|
|
58
|
+
return `${y.prefixSafe}${a}: DefinePlugin.runtimeValue(() => ` + m([
|
|
57
59
|
"`(function(" + o.map((e)=>e.name).join(", ") + ") {",
|
|
58
|
-
"locale = locale || global." + GLOBAL_I18N_IDENTIFIER + ";",
|
|
59
60
|
formatTo(d).$outInline(),
|
|
60
|
-
|
|
61
|
+
i,
|
|
61
62
|
"})`,",
|
|
62
|
-
`{ fileDependencies: [join(
|
|
63
|
+
`{ fileDependencies: [join(base, ${g ? `"${l}", "${a}.ts"` : `"${l}.ts"`})] }`
|
|
63
64
|
].join(" "));
|
|
64
65
|
}).join("),\n ")}),
|
|
65
|
-
${Object.keys(
|
|
66
|
-
let r =
|
|
67
|
-
return `${
|
|
68
|
-
"`(function(" +
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
"return " + f,
|
|
66
|
+
${Object.keys(k).map((e)=>{
|
|
67
|
+
let r = k[e], { fnName: i, params: l, typeValue: s, plural: p } = r, { args: c, body: u } = getTFunction(r, d), { dir: f } = $.translations.functions;
|
|
68
|
+
return `${y.prefixSafe}${i}: DefinePlugin.runtimeValue(() => ` + m([
|
|
69
|
+
"`(function(" + c.map((e)=>e.name).join(", ") + ") {",
|
|
70
|
+
l ? tInterpolateParams($.translations.tokens.dynamicDelimiters).$outInline() : "",
|
|
71
|
+
l ? "Primitive" === s ? "" : tInterpolateParamsDeep().$outInline() : "",
|
|
72
|
+
p ? tPluralise().$outInline() : "",
|
|
73
|
+
u,
|
|
74
74
|
"})`,",
|
|
75
|
-
`{ fileDependencies: [join(
|
|
75
|
+
`{ fileDependencies: [join(base, ${g ? `"${f}", "${i}.ts"` : `"${f}.ts"`})] }`
|
|
76
76
|
].join(" "));
|
|
77
77
|
}).join(`),\n `)}),
|
|
78
78
|
};
|
|
@@ -125,7 +125,7 @@ declare global {
|
|
|
125
125
|
*/
|
|
126
126
|
${a}
|
|
127
127
|
|
|
128
|
-
var ${
|
|
128
|
+
var ${y.prefix}: {
|
|
129
129
|
t: GlobalT;
|
|
130
130
|
to: GlobalTo;
|
|
131
131
|
}
|
|
@@ -144,7 +144,7 @@ const { join } = require("path");
|
|
|
144
144
|
const { DefinePlugin } = require("webpack");
|
|
145
145
|
|
|
146
146
|
module.exports = {
|
|
147
|
-
${
|
|
147
|
+
${y.prefix}: DefinePlugin.runtimeValue(
|
|
148
148
|
(_ctx) => {
|
|
149
149
|
${"internal" === f ? 'console.log("[@koine/i18n]:webpack-define:ctx.module", _ctx.module);' : ""};
|
|
150
150
|
return {
|
|
@@ -161,9 +161,9 @@ module.exports = {
|
|
|
161
161
|
})}
|
|
162
162
|
|
|
163
163
|
const lookup = {
|
|
164
|
-
${Object.keys(
|
|
165
|
-
let { args: t, body: n } = getToFunction(
|
|
166
|
-
return `"${e}": (${t.map((e)=>
|
|
164
|
+
${Object.keys(I).map((e)=>{
|
|
165
|
+
let { args: t, body: n } = getToFunction(I[e], d);
|
|
166
|
+
return `"${e}": (${t.map((e)=>e.name).join(", ")}) => { ${n} }`;
|
|
167
167
|
}).join(",\n ")}
|
|
168
168
|
};
|
|
169
169
|
|
|
@@ -181,9 +181,9 @@ module.exports = {
|
|
|
181
181
|
${tInterpolateParamsDeep().$outInline()}
|
|
182
182
|
|
|
183
183
|
const lookup = {
|
|
184
|
-
${Object.keys(
|
|
185
|
-
let n =
|
|
186
|
-
return `"${a}": (${o.map((e)=>
|
|
184
|
+
${Object.keys(k).map((e)=>{
|
|
185
|
+
let n = k[e], { fullKey: a } = n, { args: o, body: r } = getTFunction(n, d);
|
|
186
|
+
return `"${a}": (${o.map((e)=>e.name).join(", ")}) => { ${r} }`;
|
|
187
187
|
}).join(",\n ")}
|
|
188
188
|
};
|
|
189
189
|
|
|
@@ -49,87 +49,100 @@ function h(e, t, l) {
|
|
|
49
49
|
}
|
|
50
50
|
return l;
|
|
51
51
|
}
|
|
52
|
-
let
|
|
53
|
-
function
|
|
52
|
+
let y = RegExp(node_path.sep, "g");
|
|
53
|
+
function _(e, { id: t, namespace: l, path: a, locale: r, value: n, typeValue: i }, s) {
|
|
54
54
|
let u;
|
|
55
|
-
let o = null === n ? null : h(e, n),
|
|
55
|
+
let o = null === n ? null : h(e, n), c = l + e.tokens.namespaceDelimiter + a, f = {
|
|
56
56
|
...s,
|
|
57
57
|
id: t,
|
|
58
|
-
fnName: (u =
|
|
58
|
+
fnName: (u = c.replace(/~/g, "_").replace(/-|\.|:/g, "_").replace(y, "_").replace(/[^a-zA-Z0-9_$]/gi, ""), u = /^[0-9]/.test(u) ? "_" + u : u, (e.functions.prefix + u).replace(/_+/g, "_")),
|
|
59
59
|
namespace: l,
|
|
60
60
|
path: a,
|
|
61
|
-
fullKey:
|
|
61
|
+
fullKey: c,
|
|
62
62
|
typeValue: i,
|
|
63
63
|
values: s?.values || {}
|
|
64
64
|
};
|
|
65
|
-
return null !== r && null !== n && (
|
|
65
|
+
return null !== r && null !== n && (f.values[r] = n), o && Object.keys(o).length && (f.params = o), f;
|
|
66
66
|
}
|
|
67
|
-
let getCodeDataTranslations = (r,
|
|
68
|
-
let { ignorePaths:
|
|
69
|
-
return helpers.filterInputTranslationFiles(
|
|
70
|
-
let { locale: o, path:
|
|
71
|
-
for(let e in
|
|
72
|
-
let t =
|
|
73
|
-
e && (
|
|
74
|
-
let
|
|
75
|
-
if (utils.isPrimitive(o)) l[a] =
|
|
67
|
+
let getCodeDataTranslations = (r, o, { translationFiles: y })=>{
|
|
68
|
+
let { ignorePaths: k } = o, x = {};
|
|
69
|
+
return helpers.filterInputTranslationFiles(y, k).forEach((r)=>(function(r, n, s) {
|
|
70
|
+
let { locale: o, path: c } = s, f = node_path.join(node_path.dirname(c), node_path.basename(c, node_path.extname(c))), p = f;
|
|
71
|
+
for(let e in s.data){
|
|
72
|
+
let t = s.data[e];
|
|
73
|
+
e && (p = f + ":" + e), function e(t, l, { id: a, namespace: r, path: n, locale: s, value: o }) {
|
|
74
|
+
let c = l[a];
|
|
75
|
+
if (utils.isPrimitive(o)) l[a] = _(t, {
|
|
76
76
|
id: a,
|
|
77
77
|
namespace: r,
|
|
78
|
-
path:
|
|
78
|
+
path: n,
|
|
79
79
|
typeValue: "Primitive",
|
|
80
|
-
locale:
|
|
80
|
+
locale: s,
|
|
81
81
|
value: o
|
|
82
|
-
},
|
|
83
|
-
else if (t.functions.asData && (l[a] =
|
|
82
|
+
}, c);
|
|
83
|
+
else if (t.functions.asData && (l[a] = _(t, {
|
|
84
84
|
id: a,
|
|
85
85
|
namespace: r,
|
|
86
|
-
path:
|
|
86
|
+
path: n,
|
|
87
87
|
typeValue: utils.isArray(o) ? "Array" : "Object",
|
|
88
|
-
locale:
|
|
88
|
+
locale: s,
|
|
89
89
|
value: o
|
|
90
|
-
},
|
|
91
|
-
if (t.createArrayIndexBasedFns) for(let
|
|
92
|
-
id: a + "_" +
|
|
90
|
+
}, c)), utils.isArray(o)) {
|
|
91
|
+
if (t.createArrayIndexBasedFns) for(let i = 0; i < o.length; i++)e(t, l, {
|
|
92
|
+
id: a + "_" + i,
|
|
93
93
|
namespace: r,
|
|
94
|
-
path:
|
|
95
|
-
locale:
|
|
96
|
-
value: o[
|
|
94
|
+
path: n + "[" + i + "]",
|
|
95
|
+
locale: s,
|
|
96
|
+
value: o[i]
|
|
97
97
|
});
|
|
98
|
-
} else for(let
|
|
99
|
-
id: a + "_" +
|
|
98
|
+
} else for(let i in o)e(t, l, {
|
|
99
|
+
id: a + "_" + i,
|
|
100
100
|
namespace: r,
|
|
101
|
-
path:
|
|
102
|
-
locale:
|
|
103
|
-
value: o[
|
|
101
|
+
path: n + "." + i,
|
|
102
|
+
locale: s,
|
|
103
|
+
value: o[i]
|
|
104
104
|
});
|
|
105
105
|
return l;
|
|
106
|
-
}(r,
|
|
107
|
-
id:
|
|
108
|
-
namespace:
|
|
106
|
+
}(r, n, {
|
|
107
|
+
id: p,
|
|
108
|
+
namespace: f,
|
|
109
109
|
path: e,
|
|
110
110
|
locale: o,
|
|
111
111
|
value: t
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
|
-
return
|
|
115
|
-
})(
|
|
114
|
+
return n;
|
|
115
|
+
})(o, x, r)), x = utils.objectSort(x = function(e, t) {
|
|
116
|
+
for(let e in t){
|
|
117
|
+
let l = t[e], a = null, r = !0;
|
|
118
|
+
for(let e in l.values){
|
|
119
|
+
if (a && !utils.areEqual(a, l.values[e])) {
|
|
120
|
+
r = !1;
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
a = l.values[e];
|
|
124
|
+
}
|
|
125
|
+
r && (t[e].equalValues = !0);
|
|
126
|
+
}
|
|
127
|
+
return t;
|
|
128
|
+
}(0, x = function(e, t) {
|
|
116
129
|
let l = Object.keys(t).filter(pluralisation.isPluralKey);
|
|
117
130
|
return l.forEach((a)=>{
|
|
118
|
-
let r = pluralisation.removePluralSuffix(a), n = pluralisation.getPluralSuffix(a),
|
|
131
|
+
let r = pluralisation.removePluralSuffix(a), n = pluralisation.getPluralSuffix(a), i = t[a], u = pluralisation.getRequiredPluralSuffix(r);
|
|
119
132
|
if (!l.includes(u)) return;
|
|
120
133
|
let o = !!t[r];
|
|
121
|
-
if (
|
|
122
|
-
o || (t[r] =
|
|
134
|
+
if (i) {
|
|
135
|
+
o || (t[r] = _(e, {
|
|
123
136
|
id: r,
|
|
124
|
-
namespace:
|
|
125
|
-
path: pluralisation.removePluralSuffix(
|
|
137
|
+
namespace: i.namespace,
|
|
138
|
+
path: pluralisation.removePluralSuffix(i.path),
|
|
126
139
|
typeValue: "Primitive",
|
|
127
140
|
locale: null,
|
|
128
141
|
value: null
|
|
129
142
|
}));
|
|
130
143
|
let l = t[r].values || {};
|
|
131
|
-
for(let a in
|
|
132
|
-
let u =
|
|
144
|
+
for(let a in i.values){
|
|
145
|
+
let u = i.values[a];
|
|
133
146
|
l[a] = utils.isObject(l[a]) ? l[a] : {}, l[a][n] = u;
|
|
134
147
|
let o = h(e, u);
|
|
135
148
|
o && (t[r].params = {
|
|
@@ -145,7 +158,7 @@ let getCodeDataTranslations = (r, u, { translationFiles: v })=>{
|
|
|
145
158
|
delete t[a];
|
|
146
159
|
}
|
|
147
160
|
}), t;
|
|
148
|
-
}(
|
|
161
|
+
}(o, x)));
|
|
149
162
|
};
|
|
150
163
|
|
|
151
164
|
exports.codeDataTranslationsOptions = codeDataTranslationsOptions;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { join, dirname, basename, extname, sep } from 'node:path';
|
|
2
|
-
import { isPrimitive, isArray, objectSort, isObject, isString } from '@koine/utils';
|
|
2
|
+
import { isPrimitive, isArray, objectSort, isObject, isString, areEqual } from '@koine/utils';
|
|
3
3
|
import { filterInputTranslationFiles } from '../helpers.esm.js';
|
|
4
4
|
import { isPluralKey, removePluralSuffix, getPluralSuffix, hasOnlyPluralKeys, getRequiredPluralSuffix } from '../pluralisation.esm.js';
|
|
5
5
|
|
|
@@ -47,87 +47,100 @@ function h(e, t, l) {
|
|
|
47
47
|
}
|
|
48
48
|
return l;
|
|
49
49
|
}
|
|
50
|
-
let
|
|
51
|
-
function
|
|
50
|
+
let y = RegExp(sep, "g");
|
|
51
|
+
function _(e, { id: t, namespace: l, path: a, locale: r, value: n, typeValue: i }, s) {
|
|
52
52
|
let u;
|
|
53
|
-
let o = null === n ? null : h(e, n),
|
|
53
|
+
let o = null === n ? null : h(e, n), c = l + e.tokens.namespaceDelimiter + a, f = {
|
|
54
54
|
...s,
|
|
55
55
|
id: t,
|
|
56
|
-
fnName: (u =
|
|
56
|
+
fnName: (u = c.replace(/~/g, "_").replace(/-|\.|:/g, "_").replace(y, "_").replace(/[^a-zA-Z0-9_$]/gi, ""), u = /^[0-9]/.test(u) ? "_" + u : u, (e.functions.prefix + u).replace(/_+/g, "_")),
|
|
57
57
|
namespace: l,
|
|
58
58
|
path: a,
|
|
59
|
-
fullKey:
|
|
59
|
+
fullKey: c,
|
|
60
60
|
typeValue: i,
|
|
61
61
|
values: s?.values || {}
|
|
62
62
|
};
|
|
63
|
-
return null !== r && null !== n && (
|
|
63
|
+
return null !== r && null !== n && (f.values[r] = n), o && Object.keys(o).length && (f.params = o), f;
|
|
64
64
|
}
|
|
65
|
-
let getCodeDataTranslations = (r,
|
|
66
|
-
let { ignorePaths:
|
|
67
|
-
return filterInputTranslationFiles(
|
|
68
|
-
let { locale: o, path:
|
|
69
|
-
for(let e in
|
|
70
|
-
let t =
|
|
71
|
-
e && (
|
|
72
|
-
let
|
|
73
|
-
if (isPrimitive(o)) l[a] =
|
|
65
|
+
let getCodeDataTranslations = (r, o, { translationFiles: y })=>{
|
|
66
|
+
let { ignorePaths: k } = o, x = {};
|
|
67
|
+
return filterInputTranslationFiles(y, k).forEach((r)=>(function(r, n, s) {
|
|
68
|
+
let { locale: o, path: c } = s, f = join(dirname(c), basename(c, extname(c))), p = f;
|
|
69
|
+
for(let e in s.data){
|
|
70
|
+
let t = s.data[e];
|
|
71
|
+
e && (p = f + ":" + e), function e(t, l, { id: a, namespace: r, path: n, locale: s, value: o }) {
|
|
72
|
+
let c = l[a];
|
|
73
|
+
if (isPrimitive(o)) l[a] = _(t, {
|
|
74
74
|
id: a,
|
|
75
75
|
namespace: r,
|
|
76
|
-
path:
|
|
76
|
+
path: n,
|
|
77
77
|
typeValue: "Primitive",
|
|
78
|
-
locale:
|
|
78
|
+
locale: s,
|
|
79
79
|
value: o
|
|
80
|
-
},
|
|
81
|
-
else if (t.functions.asData && (l[a] =
|
|
80
|
+
}, c);
|
|
81
|
+
else if (t.functions.asData && (l[a] = _(t, {
|
|
82
82
|
id: a,
|
|
83
83
|
namespace: r,
|
|
84
|
-
path:
|
|
84
|
+
path: n,
|
|
85
85
|
typeValue: isArray(o) ? "Array" : "Object",
|
|
86
|
-
locale:
|
|
86
|
+
locale: s,
|
|
87
87
|
value: o
|
|
88
|
-
},
|
|
89
|
-
if (t.createArrayIndexBasedFns) for(let
|
|
90
|
-
id: a + "_" +
|
|
88
|
+
}, c)), isArray(o)) {
|
|
89
|
+
if (t.createArrayIndexBasedFns) for(let i = 0; i < o.length; i++)e(t, l, {
|
|
90
|
+
id: a + "_" + i,
|
|
91
91
|
namespace: r,
|
|
92
|
-
path:
|
|
93
|
-
locale:
|
|
94
|
-
value: o[
|
|
92
|
+
path: n + "[" + i + "]",
|
|
93
|
+
locale: s,
|
|
94
|
+
value: o[i]
|
|
95
95
|
});
|
|
96
|
-
} else for(let
|
|
97
|
-
id: a + "_" +
|
|
96
|
+
} else for(let i in o)e(t, l, {
|
|
97
|
+
id: a + "_" + i,
|
|
98
98
|
namespace: r,
|
|
99
|
-
path:
|
|
100
|
-
locale:
|
|
101
|
-
value: o[
|
|
99
|
+
path: n + "." + i,
|
|
100
|
+
locale: s,
|
|
101
|
+
value: o[i]
|
|
102
102
|
});
|
|
103
103
|
return l;
|
|
104
|
-
}(r,
|
|
105
|
-
id:
|
|
106
|
-
namespace:
|
|
104
|
+
}(r, n, {
|
|
105
|
+
id: p,
|
|
106
|
+
namespace: f,
|
|
107
107
|
path: e,
|
|
108
108
|
locale: o,
|
|
109
109
|
value: t
|
|
110
110
|
});
|
|
111
111
|
}
|
|
112
|
-
return
|
|
113
|
-
})(
|
|
112
|
+
return n;
|
|
113
|
+
})(o, x, r)), x = objectSort(x = function(e, t) {
|
|
114
|
+
for(let e in t){
|
|
115
|
+
let l = t[e], a = null, r = !0;
|
|
116
|
+
for(let e in l.values){
|
|
117
|
+
if (a && !areEqual(a, l.values[e])) {
|
|
118
|
+
r = !1;
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
121
|
+
a = l.values[e];
|
|
122
|
+
}
|
|
123
|
+
r && (t[e].equalValues = !0);
|
|
124
|
+
}
|
|
125
|
+
return t;
|
|
126
|
+
}(0, x = function(e, t) {
|
|
114
127
|
let l = Object.keys(t).filter(isPluralKey);
|
|
115
128
|
return l.forEach((a)=>{
|
|
116
|
-
let r = removePluralSuffix(a), n = getPluralSuffix(a),
|
|
129
|
+
let r = removePluralSuffix(a), n = getPluralSuffix(a), i = t[a], u = getRequiredPluralSuffix(r);
|
|
117
130
|
if (!l.includes(u)) return;
|
|
118
131
|
let o = !!t[r];
|
|
119
|
-
if (
|
|
120
|
-
o || (t[r] =
|
|
132
|
+
if (i) {
|
|
133
|
+
o || (t[r] = _(e, {
|
|
121
134
|
id: r,
|
|
122
|
-
namespace:
|
|
123
|
-
path: removePluralSuffix(
|
|
135
|
+
namespace: i.namespace,
|
|
136
|
+
path: removePluralSuffix(i.path),
|
|
124
137
|
typeValue: "Primitive",
|
|
125
138
|
locale: null,
|
|
126
139
|
value: null
|
|
127
140
|
}));
|
|
128
141
|
let l = t[r].values || {};
|
|
129
|
-
for(let a in
|
|
130
|
-
let u =
|
|
142
|
+
for(let a in i.values){
|
|
143
|
+
let u = i.values[a];
|
|
131
144
|
l[a] = isObject(l[a]) ? l[a] : {}, l[a][n] = u;
|
|
132
145
|
let o = h(e, u);
|
|
133
146
|
o && (t[r].params = {
|
|
@@ -143,7 +156,7 @@ let getCodeDataTranslations = (r, u, { translationFiles: v })=>{
|
|
|
143
156
|
delete t[a];
|
|
144
157
|
}
|
|
145
158
|
}), t;
|
|
146
|
-
}(
|
|
159
|
+
}(o, x)));
|
|
147
160
|
};
|
|
148
161
|
|
|
149
162
|
export { codeDataTranslationsOptions, getCodeDataTranslations };
|
package/compiler/types.d.ts
CHANGED
|
@@ -196,6 +196,11 @@ export declare namespace I18nCompiler {
|
|
|
196
196
|
* Dictionary of the translation' values {@link DataTranslationValue} mapped by locale
|
|
197
197
|
*/
|
|
198
198
|
values: Record<Locale, DataTranslationValue>;
|
|
199
|
+
/**
|
|
200
|
+
* Flag as `true` when all values for all locales have the same value (a.k.a.
|
|
201
|
+
* there are no real translations...)
|
|
202
|
+
*/
|
|
203
|
+
equalValues?: boolean;
|
|
199
204
|
/**
|
|
200
205
|
* Dictionary of the plural versions of the translations' values
|
|
201
206
|
* {@link DataTranslationValue} for each plural suffix mapped by locale
|
package/package.json
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
"name": "@koine/i18n",
|
|
3
3
|
"sideEffects": false,
|
|
4
4
|
"dependencies": {
|
|
5
|
-
"@koine/node": "2.0.0-beta.
|
|
6
|
-
"@koine/utils": "2.0.0-beta.
|
|
5
|
+
"@koine/node": "2.0.0-beta.147",
|
|
6
|
+
"@koine/utils": "2.0.0-beta.147",
|
|
7
7
|
"comment-json": "^4.2.4",
|
|
8
8
|
"consola": "^3.2.3",
|
|
9
9
|
"glob": "^11.0.0",
|
|
@@ -97,5 +97,5 @@
|
|
|
97
97
|
"module": "./index.esm.js",
|
|
98
98
|
"main": "./index.cjs.js",
|
|
99
99
|
"types": "./index.esm.d.ts",
|
|
100
|
-
"version": "2.0.0-beta.
|
|
100
|
+
"version": "2.0.0-beta.147"
|
|
101
101
|
}
|