@koine/i18n 2.0.0-beta.144 → 2.0.0-beta.146

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,7 +2,7 @@
2
2
 
3
3
  var createAdapter = require('../../../compiler/createAdapter.cjs.js');
4
4
 
5
- var s = createAdapter.createGenerator("next", (e)=>{
5
+ var i = createAdapter.createGenerator("next", (e)=>{
6
6
  let { options: { adapter: { modularize: t } } } = e;
7
7
  return {
8
8
  i18nServer: {
@@ -72,4 +72,4 @@ export default i18nServer;
72
72
  };
73
73
  });
74
74
 
75
- module.exports = s;
75
+ module.exports = i;
@@ -1,6 +1,6 @@
1
1
  import { createGenerator } from '../../../compiler/createAdapter.esm.js';
2
2
 
3
- var s = createGenerator("next", (e)=>{
3
+ var i = createGenerator("next", (e)=>{
4
4
  let { options: { adapter: { modularize: t } } } = e;
5
5
  return {
6
6
  i18nServer: {
@@ -70,4 +70,4 @@ export default i18nServer;
70
70
  };
71
71
  });
72
72
 
73
- export { s as default };
73
+ export { i as default };
@@ -2,7 +2,7 @@
2
2
 
3
3
  var createAdapter = require('../../../compiler/createAdapter.cjs.js');
4
4
 
5
- var i = createAdapter.createGenerator("next", (e)=>({
5
+ var s = createAdapter.createGenerator("next", (e)=>({
6
6
  I18nApp: {
7
7
  name: "I18nApp",
8
8
  ext: "tsx",
@@ -86,4 +86,4 @@ export default I18nApp;
86
86
  }
87
87
  }));
88
88
 
89
- module.exports = i;
89
+ module.exports = s;
@@ -1,6 +1,6 @@
1
1
  import { createGenerator } from '../../../compiler/createAdapter.esm.js';
2
2
 
3
- var i = createGenerator("next", (e)=>({
3
+ var s = createGenerator("next", (e)=>({
4
4
  I18nApp: {
5
5
  name: "I18nApp",
6
6
  ext: "tsx",
@@ -84,4 +84,4 @@ export default I18nApp;
84
84
  }
85
85
  }));
86
86
 
87
- export { i as default };
87
+ export { s as default };
@@ -2,7 +2,7 @@
2
2
 
3
3
  var createAdapter = require('../../../compiler/createAdapter.cjs.js');
4
4
 
5
- var g = createAdapter.createGenerator("next", (a)=>({
5
+ var f = createAdapter.createGenerator("next", (a)=>({
6
6
  I18nHead: {
7
7
  dir: createAdapter.createGenerator.dirs.internal,
8
8
  name: "I18nHead",
@@ -51,4 +51,4 @@ export const I18nHead = (props: I18nHeadProps) => {
51
51
  }
52
52
  }));
53
53
 
54
- module.exports = g;
54
+ module.exports = f;
@@ -1,6 +1,6 @@
1
1
  import { createGenerator } from '../../../compiler/createAdapter.esm.js';
2
2
 
3
- var g = createGenerator("next", (a)=>({
3
+ var f = createGenerator("next", (a)=>({
4
4
  I18nHead: {
5
5
  dir: createGenerator.dirs.internal,
6
6
  name: "I18nHead",
@@ -49,4 +49,4 @@ export const I18nHead = (props: I18nHeadProps) => {
49
49
  }
50
50
  }));
51
51
 
52
- export { g as default };
52
+ export { f as default };
@@ -2,7 +2,7 @@
2
2
 
3
3
  var createAdapter = require('../../../compiler/createAdapter.cjs.js');
4
4
 
5
- var f = createAdapter.createGenerator("next", (e)=>({
5
+ var g = createAdapter.createGenerator("next", (e)=>({
6
6
  I18nSetter: {
7
7
  name: "I18nSetter",
8
8
  ext: "tsx",
@@ -54,4 +54,4 @@ export default I18nSetter;
54
54
  }
55
55
  }));
56
56
 
57
- module.exports = f;
57
+ module.exports = g;
@@ -1,6 +1,6 @@
1
1
  import { createGenerator } from '../../../compiler/createAdapter.esm.js';
2
2
 
3
- var f = createGenerator("next", (e)=>({
3
+ var g = createGenerator("next", (e)=>({
4
4
  I18nSetter: {
5
5
  name: "I18nSetter",
6
6
  ext: "tsx",
@@ -52,4 +52,4 @@ export default I18nSetter;
52
52
  }
53
53
  }));
54
54
 
55
- export { f as default };
55
+ export { g as default };
@@ -2,7 +2,7 @@
2
2
 
3
3
  var createAdapter = require('../../compiler/createAdapter.cjs.js');
4
4
 
5
- var d = createAdapter.createGenerator("next", (t)=>{
5
+ var l = createAdapter.createGenerator("next", (t)=>{
6
6
  let { options: { routes: { localeParamName: e }, adapter: { router: o } } } = t;
7
7
  return {
8
8
  useRouteId: {
@@ -71,4 +71,4 @@ export default useRouteId;
71
71
  };
72
72
  });
73
73
 
74
- module.exports = d;
74
+ module.exports = l;
@@ -1,6 +1,6 @@
1
1
  import { createGenerator } from '../../compiler/createAdapter.esm.js';
2
2
 
3
- var d = createGenerator("next", (t)=>{
3
+ var l = createGenerator("next", (t)=>{
4
4
  let { options: { routes: { localeParamName: e }, adapter: { router: o } } } = t;
5
5
  return {
6
6
  useRouteId: {
@@ -69,4 +69,4 @@ export default useRouteId;
69
69
  };
70
70
  });
71
71
 
72
- export { d as default };
72
+ export { l as default };
@@ -14,11 +14,11 @@ var index = require('../index.cjs.js');
14
14
  function m(e) {
15
15
  return e.replace(/\s+/g, " ");
16
16
  }
17
- var l = createAdapter.createGenerator("next", (u)=>{
17
+ 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 l = 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.prefix}_${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.prefix}_${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,28 +52,30 @@ 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.prefix}_${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
- "})`"
64
- ].join(" ") + ", { fileDependencies: [" + $.adapter.modularize ? `join("${b}", "${j}", "${$.routes.functions.dir}", "${a}.ts")` : `join("${b}", "${j}", "$to.ts")] }`);
63
+ i,
64
+ "})`,",
65
+ `{ fileDependencies: [join(base, ${g ? `"${l}", "${a}.ts"` : `"${l}.ts"`})] }`
66
+ ].join(" "));
65
67
  }).join("),\n ")}),
66
- ${Object.keys(I).map((e)=>{
67
- let r = I[e], { fnName: l, params: i, typeValue: p, plural: c } = r, { args: u, body: f } = t.getTFunction(r, d);
68
- return `${g.prefix}_${l}: DefinePlugin.runtimeValue(() => ` + m([
69
- "`(function(" + u.map((e)=>e.name).join(", ") + ") {",
70
- "locale = locale || global." + helpers.GLOBAL_I18N_IDENTIFIER + ";",
71
- i ? tInterpolateParams.tInterpolateParams($.translations.tokens.dynamicDelimiters).$outInline() : "",
72
- "Primitive" === p ? "" : tInterpolateParamsDeep.tInterpolateParamsDeep().$outInline(),
73
- c ? tPluralise.tPluralise().$outInline() : "",
74
- "return " + f,
75
- "})`"
76
- ].join(" ") + ", { fileDependencies: [" + $.adapter.modularize ? `join("${b}", "${j}", "${$.translations.functions.dir}", "${l}.ts")` : `join("${b}", "${j}", "$t.ts")] }`);
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
+ "})`,",
77
+ `{ fileDependencies: [join(base, ${g ? `"${f}", "${i}.ts"` : `"${f}.ts"`})] }`
78
+ ].join(" "));
77
79
  }).join(`),\n `)}),
78
80
  };
79
81
  `
@@ -125,7 +127,7 @@ declare global {
125
127
  */
126
128
  ${a}
127
129
 
128
- var ${g.prefix}: {
130
+ var ${y.prefix}: {
129
131
  t: GlobalT;
130
132
  to: GlobalTo;
131
133
  }
@@ -144,7 +146,7 @@ const { join } = require("path");
144
146
  const { DefinePlugin } = require("webpack");
145
147
 
146
148
  module.exports = {
147
- ${g.prefix}: DefinePlugin.runtimeValue(
149
+ ${y.prefix}: DefinePlugin.runtimeValue(
148
150
  (_ctx) => {
149
151
  ${"internal" === f ? 'console.log("[@koine/i18n]:webpack-define:ctx.module", _ctx.module);' : ""};
150
152
  return {
@@ -161,9 +163,9 @@ module.exports = {
161
163
  })}
162
164
 
163
165
  const lookup = {
164
- ${Object.keys(y).map((e)=>{
165
- let { args: t, body: n } = to.getToFunction(y[e], d);
166
- 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} }`;
167
169
  }).join(",\n ")}
168
170
  };
169
171
 
@@ -181,9 +183,9 @@ module.exports = {
181
183
  ${tInterpolateParamsDeep.tInterpolateParamsDeep().$outInline()}
182
184
 
183
185
  const lookup = {
184
- ${Object.keys(I).map((e)=>{
185
- let n = I[e], { fullKey: a } = n, { args: o, body: r } = t.getTFunction(n, d);
186
- 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} }`;
187
189
  }).join(",\n ")}
188
190
  };
189
191
 
@@ -206,4 +208,4 @@ module.exports = {
206
208
  };
207
209
  });
208
210
 
209
- module.exports = l;
211
+ module.exports = d;
@@ -12,11 +12,11 @@ import { resolveGlobalizeOption } from '../index.esm.js';
12
12
  function m(e) {
13
13
  return e.replace(/\s+/g, " ");
14
14
  }
15
- var l = createGenerator("next", (u)=>{
15
+ 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 l = 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.prefix}_${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.prefix}_${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,28 +50,30 @@ 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.prefix}_${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
- "})`"
62
- ].join(" ") + ", { fileDependencies: [" + $.adapter.modularize ? `join("${b}", "${j}", "${$.routes.functions.dir}", "${a}.ts")` : `join("${b}", "${j}", "$to.ts")] }`);
61
+ i,
62
+ "})`,",
63
+ `{ fileDependencies: [join(base, ${g ? `"${l}", "${a}.ts"` : `"${l}.ts"`})] }`
64
+ ].join(" "));
63
65
  }).join("),\n ")}),
64
- ${Object.keys(I).map((e)=>{
65
- let r = I[e], { fnName: l, params: i, typeValue: p, plural: c } = r, { args: u, body: f } = getTFunction(r, d);
66
- return `${g.prefix}_${l}: DefinePlugin.runtimeValue(() => ` + m([
67
- "`(function(" + u.map((e)=>e.name).join(", ") + ") {",
68
- "locale = locale || global." + GLOBAL_I18N_IDENTIFIER + ";",
69
- i ? tInterpolateParams($.translations.tokens.dynamicDelimiters).$outInline() : "",
70
- "Primitive" === p ? "" : tInterpolateParamsDeep().$outInline(),
71
- c ? tPluralise().$outInline() : "",
72
- "return " + f,
73
- "})`"
74
- ].join(" ") + ", { fileDependencies: [" + $.adapter.modularize ? `join("${b}", "${j}", "${$.translations.functions.dir}", "${l}.ts")` : `join("${b}", "${j}", "$t.ts")] }`);
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
+ "})`,",
75
+ `{ fileDependencies: [join(base, ${g ? `"${f}", "${i}.ts"` : `"${f}.ts"`})] }`
76
+ ].join(" "));
75
77
  }).join(`),\n `)}),
76
78
  };
77
79
  `
@@ -123,7 +125,7 @@ declare global {
123
125
  */
124
126
  ${a}
125
127
 
126
- var ${g.prefix}: {
128
+ var ${y.prefix}: {
127
129
  t: GlobalT;
128
130
  to: GlobalTo;
129
131
  }
@@ -142,7 +144,7 @@ const { join } = require("path");
142
144
  const { DefinePlugin } = require("webpack");
143
145
 
144
146
  module.exports = {
145
- ${g.prefix}: DefinePlugin.runtimeValue(
147
+ ${y.prefix}: DefinePlugin.runtimeValue(
146
148
  (_ctx) => {
147
149
  ${"internal" === f ? 'console.log("[@koine/i18n]:webpack-define:ctx.module", _ctx.module);' : ""};
148
150
  return {
@@ -159,9 +161,9 @@ module.exports = {
159
161
  })}
160
162
 
161
163
  const lookup = {
162
- ${Object.keys(y).map((e)=>{
163
- let { args: t, body: n } = getToFunction(y[e], d);
164
- 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} }`;
165
167
  }).join(",\n ")}
166
168
  };
167
169
 
@@ -179,9 +181,9 @@ module.exports = {
179
181
  ${tInterpolateParamsDeep().$outInline()}
180
182
 
181
183
  const lookup = {
182
- ${Object.keys(I).map((e)=>{
183
- let n = I[e], { fullKey: a } = n, { args: o, body: r } = getTFunction(n, d);
184
- 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} }`;
185
187
  }).join(",\n ")}
186
188
  };
187
189
 
@@ -204,4 +206,4 @@ module.exports = {
204
206
  };
205
207
  });
206
208
 
207
- export { l as default };
209
+ export { d as default };
@@ -21,7 +21,8 @@ var webpackDefine = require('./generators/webpack-define.cjs.js');
21
21
  function resolveGlobalizeOption(r) {
22
22
  let { functions: e, prefix: t } = r;
23
23
  return {
24
- prefix: t,
24
+ prefix: t || "",
25
+ prefixSafe: t ? (t + "_").replace(/_+$/, "_") : "",
25
26
  functions: "boolean" == typeof e ? {
26
27
  routes: !0,
27
28
  translations: !0
@@ -49,8 +49,14 @@ export type Options = AdapterReactOptions & {
49
49
  };
50
50
  };
51
51
  };
52
+ /**
53
+ * We add `safePrefix`: when `prefix` is present we add an underscore after it
54
+ * and remove consecutive underscores in case the user defined prefix already
55
+ * had an ending underscore.
56
+ */
52
57
  export declare function resolveGlobalizeOption(globalize: Options["globalize"]): {
53
58
  prefix: string;
59
+ prefixSafe: string;
54
60
  functions: {
55
61
  /**
56
62
  * Configure generation of _routes_' `to` functions
@@ -5,19 +5,20 @@ import o from './generators/next-rewrites.esm.js';
5
5
  import a from './generators/router-app/I18nLayout.esm.js';
6
6
  import p from './generators/router-app/I18nLayoutRoot.esm.js';
7
7
  import n from './generators/router-app/I18nPage.esm.js';
8
- import s from './generators/router-app/i18nServer.esm.js';
9
- import i from './generators/router-pages/I18nApp.esm.js';
8
+ import i from './generators/router-app/i18nServer.esm.js';
9
+ import s from './generators/router-pages/I18nApp.esm.js';
10
10
  import m from './generators/router-pages/I18nDocument.esm.js';
11
- import g from './generators/router-pages/I18nHead.esm.js';
12
- import f from './generators/router-pages/I18nSetter.esm.js';
11
+ import f from './generators/router-pages/I18nHead.esm.js';
12
+ import g from './generators/router-pages/I18nSetter.esm.js';
13
13
  import u from './generators/router-pages/i18nGet.esm.js';
14
- import d from './generators/useRouteId.esm.js';
15
- import l from './generators/webpack-define.esm.js';
14
+ import l from './generators/useRouteId.esm.js';
15
+ import d from './generators/webpack-define.esm.js';
16
16
 
17
17
  function resolveGlobalizeOption(r) {
18
18
  let { functions: e, prefix: t } = r;
19
19
  return {
20
- prefix: t,
20
+ prefix: t || "",
21
+ prefixSafe: t ? (t + "_").replace(/_+$/, "_") : "",
21
22
  functions: "boolean" == typeof e ? {
22
23
  routes: !0,
23
24
  translations: !0
@@ -44,17 +45,17 @@ const adapterNext = createAdapter({
44
45
  a,
45
46
  p,
46
47
  n,
47
- s
48
+ i
48
49
  ] : [],
49
50
  ..."pages" === c || "migrating" === c ? [
50
- i,
51
+ s,
51
52
  m,
52
- g,
53
53
  f,
54
+ g,
54
55
  u
55
56
  ] : [],
56
- d,
57
- l
57
+ l,
58
+ d
58
59
  ];
59
60
  },
60
61
  getTransformers: (r)=>{
@@ -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.144",
6
- "@koine/utils": "2.0.0-beta.144",
5
+ "@koine/node": "2.0.0-beta.146",
6
+ "@koine/utils": "2.0.0-beta.146",
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.144"
100
+ "version": "2.0.0-beta.146"
101
101
  }