@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.
@@ -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: o, params: l, plural: p, typeValue: i } = t, u = [], d = "count";
14
- p && (l = l ? {
15
- ...l,
16
- [d]: "number"
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
- [d]: "number"
19
- }), l && u.push({
18
+ [$]: "number"
19
+ }), p && P.push({
20
20
  name: "params",
21
- type: helpers.compileDataParamsToType(l),
21
+ type: helpers.compileDataParamsToType(p),
22
22
  optional: !1
23
- }), u.push({
23
+ }), P.push({
24
24
  name: "locale",
25
25
  type: "I18n.Locale",
26
26
  optional: !0
27
27
  });
28
- let y = [
28
+ let h = [
29
29
  f.types
30
- ], P = "";
31
- return utils.isPrimitive(o) ? P += c(o) : P += function(t, a) {
32
- let r = "";
33
- for(let n in a){
34
- let o = a[n];
35
- n === t || utils.areEqual(o, a[t]) || (r += `locale === "${n}" ? ${c(o)} : `);
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 r + c(a[t]);
38
- }(r, o), p && (y.push(f.tPluralise), P = `tPluralise(${P}, params.${d})`), l && (!p || p && !Object.keys(l).every((e)=>e === d)) && ("Primitive" === i ? (y.push(f.tInterpolateParams), P = `tInterpolateParams(${P}, params)`) : ("Array" === i || "Object" === i) && (y.push(f.tInterpolateParamsDeep), P = `tInterpolateParamsDeep(${P}, params)`)), {
39
- body: "locale = locale || global." + helpers.GLOBAL_I18N_IDENTIFIER + "; return " + P,
40
- args: u,
41
- imports: y
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: o, params: l, plural: p, typeValue: i } = t, u = [], d = "count";
10
- p && (l = l ? {
11
- ...l,
12
- [d]: "number"
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
- [d]: "number"
15
- }), l && u.push({
14
+ [$]: "number"
15
+ }), p && P.push({
16
16
  name: "params",
17
- type: compileDataParamsToType(l),
17
+ type: compileDataParamsToType(p),
18
18
  optional: !1
19
- }), u.push({
19
+ }), P.push({
20
20
  name: "locale",
21
21
  type: "I18n.Locale",
22
22
  optional: !0
23
23
  });
24
- let y = [
24
+ let h = [
25
25
  f.types
26
- ], P = "";
27
- return isPrimitive(o) ? P += c(o) : P += function(t, a) {
28
- let r = "";
29
- for(let n in a){
30
- let o = a[n];
31
- n === t || areEqual(o, a[t]) || (r += `locale === "${n}" ? ${c(o)} : `);
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 r + c(a[t]);
34
- }(r, o), p && (y.push(f.tPluralise), P = `tPluralise(${P}, params.${d})`), l && (!p || p && !Object.keys(l).every((e)=>e === d)) && ("Primitive" === i ? (y.push(f.tInterpolateParams), P = `tInterpolateParams(${P}, params)`) : ("Array" === i || "Object" === i) && (y.push(f.tInterpolateParamsDeep), P = `tInterpolateParamsDeep(${P}, params)`)), {
35
- body: "locale = locale || global." + GLOBAL_I18N_IDENTIFIER + "; return " + P,
36
- args: u,
37
- imports: y
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", (e)=>{
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";${t ? `
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,${t ? `
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", (e)=>{
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";${t ? `
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,${t ? `
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), y = g.functions.routes ? u.routes.byId : {}, I = g.functions.translations ? u.translations : {};
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(y).map((t)=>{
35
- let { id: n, fnName: a, params: o } = y[t], r = `var ${g.prefixSafe}${a}: (`;
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(I).map((t)=>{
39
- let { fnName: n, params: a, values: o } = I[t], r = `var ${g.prefixSafe}${n}: (`;
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(y).map((t)=>{
57
- let n = y[t], { fnName: a } = n, { args: o, body: l } = to.getToFunction(n, d);
58
- return `${g.prefixSafe}${a}: DefinePlugin.runtimeValue(() => ` + m([
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
- "return " + l,
63
+ i,
63
64
  "})`,",
64
- `{ fileDependencies: [join("${b}", "${j}", "${$.routes.functions.dir}"${$.adapter.modularize ? `, "${a}.ts"` : ""})] }`
65
+ `{ fileDependencies: [join(base, ${g ? `"${l}", "${a}.ts"` : `"${l}.ts"`})] }`
65
66
  ].join(" "));
66
67
  }).join("),\n ")}),
67
- ${Object.keys(I).map((e)=>{
68
- let r = I[e], { fnName: l, params: i, typeValue: p, plural: c } = r, { args: u, body: f } = t.getTFunction(r, d);
69
- return `${g.prefixSafe}${l}: DefinePlugin.runtimeValue(() => ` + m([
70
- "`(function(" + u.map((e)=>e.name).join(", ") + ") {",
71
- "locale = locale || global." + helpers.GLOBAL_I18N_IDENTIFIER + ";",
72
- i ? tInterpolateParams.tInterpolateParams($.translations.tokens.dynamicDelimiters).$outInline() : "",
73
- "Primitive" === p ? "" : tInterpolateParamsDeep.tInterpolateParamsDeep().$outInline(),
74
- c ? tPluralise.tPluralise().$outInline() : "",
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("${b}", "${j}", "${$.translations.functions.dir}"${$.adapter.modularize ? `, "${l}.ts"` : ""})] }`
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 ${g.prefix}: {
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
- ${g.prefix}: DefinePlugin.runtimeValue(
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(y).map((e)=>{
167
- let { args: t, body: n } = to.getToFunction(y[e], d);
168
- return `"${e}": (${t.map((e)=>"locale" === e.name ? "locale = locale" : e.name).join(", ")}) => ${n}`;
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(I).map((e)=>{
187
- let n = I[e], { fullKey: a } = n, { args: o, body: r } = t.getTFunction(n, d);
188
- return `"${a}": (${o.map((e)=>"locale" === e.name ? "locale = locale" : e.name).join(", ")}) => ${r}`;
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), y = g.functions.routes ? u.routes.byId : {}, I = g.functions.translations ? u.translations : {};
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(y).map((t)=>{
33
- let { id: n, fnName: a, params: o } = y[t], r = `var ${g.prefixSafe}${a}: (`;
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(I).map((t)=>{
37
- let { fnName: n, params: a, values: o } = I[t], r = `var ${g.prefixSafe}${n}: (`;
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(y).map((t)=>{
55
- let n = y[t], { fnName: a } = n, { args: o, body: l } = getToFunction(n, d);
56
- return `${g.prefixSafe}${a}: DefinePlugin.runtimeValue(() => ` + m([
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
- "return " + l,
61
+ i,
61
62
  "})`,",
62
- `{ fileDependencies: [join("${b}", "${j}", "${$.routes.functions.dir}"${$.adapter.modularize ? `, "${a}.ts"` : ""})] }`
63
+ `{ fileDependencies: [join(base, ${g ? `"${l}", "${a}.ts"` : `"${l}.ts"`})] }`
63
64
  ].join(" "));
64
65
  }).join("),\n ")}),
65
- ${Object.keys(I).map((e)=>{
66
- let r = I[e], { fnName: l, params: i, typeValue: p, plural: c } = r, { args: u, body: f } = getTFunction(r, d);
67
- return `${g.prefixSafe}${l}: DefinePlugin.runtimeValue(() => ` + m([
68
- "`(function(" + u.map((e)=>e.name).join(", ") + ") {",
69
- "locale = locale || global." + GLOBAL_I18N_IDENTIFIER + ";",
70
- i ? tInterpolateParams($.translations.tokens.dynamicDelimiters).$outInline() : "",
71
- "Primitive" === p ? "" : tInterpolateParamsDeep().$outInline(),
72
- c ? tPluralise().$outInline() : "",
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("${b}", "${j}", "${$.translations.functions.dir}"${$.adapter.modularize ? `, "${l}.ts"` : ""})] }`
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 ${g.prefix}: {
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
- ${g.prefix}: DefinePlugin.runtimeValue(
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(y).map((e)=>{
165
- let { args: t, body: n } = getToFunction(y[e], d);
166
- return `"${e}": (${t.map((e)=>"locale" === e.name ? "locale = locale" : e.name).join(", ")}) => ${n}`;
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(I).map((e)=>{
185
- let n = I[e], { fullKey: a } = n, { args: o, body: r } = getTFunction(n, d);
186
- return `"${a}": (${o.map((e)=>"locale" === e.name ? "locale = locale" : e.name).join(", ")}) => ${r}`;
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 v = RegExp(node_path.sep, "g");
53
- function y(e, { id: t, namespace: l, path: a, locale: r, value: n, typeValue: i }, s) {
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), p = l + e.tokens.namespaceDelimiter + a, c = {
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 = p.replace(/~/g, "_").replace(/-|\.|:/g, "_").replace(v, "_").replace(/[^a-zA-Z0-9_$]/gi, ""), u = /^[0-9]/.test(u) ? "_" + u : u, (e.functions.prefix + u).replace(/_+/g, "_")),
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: p,
61
+ fullKey: c,
62
62
  typeValue: i,
63
63
  values: s?.values || {}
64
64
  };
65
- return null !== r && null !== n && (c.values[r] = n), o && Object.keys(o).length && (c.params = o), c;
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, u, { translationFiles: v })=>{
68
- let { ignorePaths: _ } = u, k = {};
69
- return helpers.filterInputTranslationFiles(v, _).forEach((r)=>(function(r, i, u) {
70
- let { locale: o, path: p } = u, c = node_path.join(node_path.dirname(p), node_path.basename(p, node_path.extname(p))), f = c;
71
- for(let e in u.data){
72
- let t = u.data[e];
73
- e && (f = c + ":" + e), function e(t, l, { id: a, namespace: r, path: i, locale: u, value: o }) {
74
- let p = l[a];
75
- if (utils.isPrimitive(o)) l[a] = y(t, {
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: i,
78
+ path: n,
79
79
  typeValue: "Primitive",
80
- locale: u,
80
+ locale: s,
81
81
  value: o
82
- }, p);
83
- else if (t.functions.asData && (l[a] = y(t, {
82
+ }, c);
83
+ else if (t.functions.asData && (l[a] = _(t, {
84
84
  id: a,
85
85
  namespace: r,
86
- path: i,
86
+ path: n,
87
87
  typeValue: utils.isArray(o) ? "Array" : "Object",
88
- locale: u,
88
+ locale: s,
89
89
  value: o
90
- }, p)), utils.isArray(o)) {
91
- if (t.createArrayIndexBasedFns) for(let n = 0; n < o.length; n++)e(t, l, {
92
- id: a + "_" + n,
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: i + "[" + n + "]",
95
- locale: u,
96
- value: o[n]
94
+ path: n + "[" + i + "]",
95
+ locale: s,
96
+ value: o[i]
97
97
  });
98
- } else for(let n in o)e(t, l, {
99
- id: a + "_" + n,
98
+ } else for(let i in o)e(t, l, {
99
+ id: a + "_" + i,
100
100
  namespace: r,
101
- path: i + "." + n,
102
- locale: u,
103
- value: o[n]
101
+ path: n + "." + i,
102
+ locale: s,
103
+ value: o[i]
104
104
  });
105
105
  return l;
106
- }(r, i, {
107
- id: f,
108
- namespace: c,
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 i;
115
- })(u, k, r)), k = utils.objectSort(k = function(e, t) {
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), s = t[a], u = pluralisation.getRequiredPluralSuffix(r);
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 (s) {
122
- o || (t[r] = y(e, {
134
+ if (i) {
135
+ o || (t[r] = _(e, {
123
136
  id: r,
124
- namespace: s.namespace,
125
- path: pluralisation.removePluralSuffix(s.path),
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 s.values){
132
- let u = s.values[a];
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
- }(u, k));
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 v = RegExp(sep, "g");
51
- function y(e, { id: t, namespace: l, path: a, locale: r, value: n, typeValue: i }, s) {
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), p = l + e.tokens.namespaceDelimiter + a, c = {
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 = p.replace(/~/g, "_").replace(/-|\.|:/g, "_").replace(v, "_").replace(/[^a-zA-Z0-9_$]/gi, ""), u = /^[0-9]/.test(u) ? "_" + u : u, (e.functions.prefix + u).replace(/_+/g, "_")),
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: p,
59
+ fullKey: c,
60
60
  typeValue: i,
61
61
  values: s?.values || {}
62
62
  };
63
- return null !== r && null !== n && (c.values[r] = n), o && Object.keys(o).length && (c.params = o), c;
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, u, { translationFiles: v })=>{
66
- let { ignorePaths: _ } = u, k = {};
67
- return filterInputTranslationFiles(v, _).forEach((r)=>(function(r, i, u) {
68
- let { locale: o, path: p } = u, c = join(dirname(p), basename(p, extname(p))), f = c;
69
- for(let e in u.data){
70
- let t = u.data[e];
71
- e && (f = c + ":" + e), function e(t, l, { id: a, namespace: r, path: i, locale: u, value: o }) {
72
- let p = l[a];
73
- if (isPrimitive(o)) l[a] = y(t, {
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: i,
76
+ path: n,
77
77
  typeValue: "Primitive",
78
- locale: u,
78
+ locale: s,
79
79
  value: o
80
- }, p);
81
- else if (t.functions.asData && (l[a] = y(t, {
80
+ }, c);
81
+ else if (t.functions.asData && (l[a] = _(t, {
82
82
  id: a,
83
83
  namespace: r,
84
- path: i,
84
+ path: n,
85
85
  typeValue: isArray(o) ? "Array" : "Object",
86
- locale: u,
86
+ locale: s,
87
87
  value: o
88
- }, p)), isArray(o)) {
89
- if (t.createArrayIndexBasedFns) for(let n = 0; n < o.length; n++)e(t, l, {
90
- id: a + "_" + n,
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: i + "[" + n + "]",
93
- locale: u,
94
- value: o[n]
92
+ path: n + "[" + i + "]",
93
+ locale: s,
94
+ value: o[i]
95
95
  });
96
- } else for(let n in o)e(t, l, {
97
- id: a + "_" + n,
96
+ } else for(let i in o)e(t, l, {
97
+ id: a + "_" + i,
98
98
  namespace: r,
99
- path: i + "." + n,
100
- locale: u,
101
- value: o[n]
99
+ path: n + "." + i,
100
+ locale: s,
101
+ value: o[i]
102
102
  });
103
103
  return l;
104
- }(r, i, {
105
- id: f,
106
- namespace: c,
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 i;
113
- })(u, k, r)), k = objectSort(k = function(e, t) {
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), s = t[a], u = getRequiredPluralSuffix(r);
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 (s) {
120
- o || (t[r] = y(e, {
132
+ if (i) {
133
+ o || (t[r] = _(e, {
121
134
  id: r,
122
- namespace: s.namespace,
123
- path: removePluralSuffix(s.path),
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 s.values){
130
- let u = s.values[a];
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
- }(u, k));
159
+ }(o, x)));
147
160
  };
148
161
 
149
162
  export { codeDataTranslationsOptions, getCodeDataTranslations };
@@ -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.145",
6
- "@koine/utils": "2.0.0-beta.145",
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.145"
100
+ "version": "2.0.0-beta.147"
101
101
  }