@koine/i18n 2.0.0-beta.161 → 2.0.0-beta.163

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.
@@ -108,8 +108,8 @@ module.exports = config;
108
108
  ]);
109
109
  return `
110
110
  export const i18nSwcTransforms = {
111
- flat: ${JSON.stringify(l, null, 2)};
112
- deep: ${JSON.stringify(n, null, 2)};
111
+ flat: ${JSON.stringify(l, null, 2)},
112
+ deep: ${JSON.stringify(n, null, 2)}
113
113
  }
114
114
  `;
115
115
  }
@@ -106,8 +106,8 @@ module.exports = config;
106
106
  ]);
107
107
  return `
108
108
  export const i18nSwcTransforms = {
109
- flat: ${JSON.stringify(l, null, 2)};
110
- deep: ${JSON.stringify(n, null, 2)};
109
+ flat: ${JSON.stringify(l, null, 2)},
110
+ deep: ${JSON.stringify(n, null, 2)}
111
111
  }
112
112
  `;
113
113
  }
@@ -58,6 +58,13 @@ export declare const adapterJs: {
58
58
  disabled: true;
59
59
  content: () => string;
60
60
  }) => import("../compiler").I18nCompiler.AdapterFile);
61
+ swcTransforms: boolean | ((file: {
62
+ name: string;
63
+ ext: "js";
64
+ index: false;
65
+ disabled: boolean;
66
+ content: () => string;
67
+ }) => import("../compiler").I18nCompiler.AdapterFile);
61
68
  createT: boolean | ((file: {
62
69
  dir: string;
63
70
  name: string;
@@ -249,6 +256,13 @@ export declare const adapterJs: {
249
256
  disabled: true;
250
257
  content: () => string;
251
258
  };
259
+ swcTransforms: {
260
+ name: string;
261
+ ext: "js";
262
+ index: false;
263
+ disabled: boolean;
264
+ content: () => string;
265
+ };
252
266
  }) | ((data: import("../compiler").I18nCompiler.DataCode<"js">) => {
253
267
  createT: {
254
268
  dir: string;
@@ -98,6 +98,13 @@ export declare const adapterNext: {
98
98
  disabled: true;
99
99
  content: () => string;
100
100
  }) => import("../compiler").I18nCompiler.AdapterFile);
101
+ swcTransforms: boolean | ((file: {
102
+ name: string;
103
+ ext: "js";
104
+ index: false;
105
+ disabled: boolean;
106
+ content: () => string;
107
+ }) => import("../compiler").I18nCompiler.AdapterFile);
101
108
  createT: boolean | ((file: {
102
109
  dir: string;
103
110
  name: string;
@@ -491,7 +498,7 @@ export declare const adapterNext: {
491
498
  webpackDefineGranular: boolean | ((file: {
492
499
  dir: string;
493
500
  name: string;
494
- ext: "js";
501
+ ext: "cjs";
495
502
  index: false;
496
503
  content: () => string;
497
504
  }) => import("../compiler").I18nCompiler.AdapterFile);
@@ -507,7 +514,7 @@ export declare const adapterNext: {
507
514
  disabled: true;
508
515
  dir: string;
509
516
  name: string;
510
- ext: "js";
517
+ ext: "cjs";
511
518
  index: false;
512
519
  content: () => string;
513
520
  }) => import("../compiler").I18nCompiler.AdapterFile);
@@ -540,6 +547,13 @@ export declare const adapterNext: {
540
547
  disabled: true;
541
548
  content: () => string;
542
549
  };
550
+ swcTransforms: {
551
+ name: string;
552
+ ext: "js";
553
+ index: false;
554
+ disabled: boolean;
555
+ content: () => string;
556
+ };
543
557
  }) | ((data: import("../compiler").I18nCompiler.DataCode<"js">) => {
544
558
  createT: {
545
559
  dir: string;
@@ -975,7 +989,7 @@ export declare const adapterNext: {
975
989
  webpackDefineGranular: {
976
990
  dir: string;
977
991
  name: string;
978
- ext: "js";
992
+ ext: "cjs";
979
993
  index: false;
980
994
  content: () => string;
981
995
  };
@@ -991,7 +1005,7 @@ export declare const adapterNext: {
991
1005
  disabled: true;
992
1006
  dir: string;
993
1007
  name: string;
994
- ext: "js";
1008
+ ext: "cjs";
995
1009
  index: false;
996
1010
  content: () => string;
997
1011
  };
@@ -30,6 +30,13 @@ export declare const adapterReact: {
30
30
  disabled: true;
31
31
  content: () => string;
32
32
  }) => import("../compiler").I18nCompiler.AdapterFile);
33
+ swcTransforms: boolean | ((file: {
34
+ name: string;
35
+ ext: "js";
36
+ index: false;
37
+ disabled: boolean;
38
+ content: () => string;
39
+ }) => import("../compiler").I18nCompiler.AdapterFile);
33
40
  createT: boolean | ((file: {
34
41
  dir: string;
35
42
  name: string;
@@ -367,6 +374,13 @@ export declare const adapterReact: {
367
374
  disabled: true;
368
375
  content: () => string;
369
376
  };
377
+ swcTransforms: {
378
+ name: string;
379
+ ext: "js";
380
+ index: false;
381
+ disabled: boolean;
382
+ content: () => string;
383
+ };
370
384
  }) | ((data: import("../compiler").I18nCompiler.DataCode<"js">) => {
371
385
  createT: {
372
386
  dir: string;
@@ -21,7 +21,7 @@ const codeDataTranslationsOptions = {
21
21
  }
22
22
  }
23
23
  };
24
- function h(e, t, l) {
24
+ function g(e, t, l) {
25
25
  if (utils.isPrimitive(t)) {
26
26
  let a = function(e, t) {
27
27
  if (utils.isString(t)) {
@@ -34,14 +34,14 @@ function h(e, t, l) {
34
34
  ...a
35
35
  });
36
36
  } else if (utils.isArray(t)) for(let a = 0; a < t.length; a++){
37
- let r = h(e, t[a], l);
37
+ let r = g(e, t[a], l);
38
38
  r && (l = {
39
39
  ...l || {},
40
40
  ...r
41
41
  });
42
42
  }
43
43
  else for(let a in t){
44
- let r = h(e, t[a], l);
44
+ let r = g(e, t[a], l);
45
45
  r && (l = {
46
46
  ...l || {},
47
47
  ...r
@@ -49,13 +49,12 @@ function h(e, t, l) {
49
49
  }
50
50
  return l;
51
51
  }
52
- let y = RegExp(node_path.sep, "g");
53
- function _(e, { id: t, namespace: l, path: a, locale: r, value: n, typeValue: i }, s) {
52
+ function h(e, { id: t, namespace: l, path: a, locale: r, value: n, typeValue: i }, s) {
54
53
  let u;
55
- let o = null === n ? null : h(e, n), f = l + e.tokens.namespaceDelimiter + a, p = {
54
+ let o = null === n ? null : g(e, n), f = l + e.tokens.namespaceDelimiter + a, p = {
56
55
  ...s,
57
56
  id: t,
58
- fnName: (u = f.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
+ fnName: (u = f.replace(/~/g, "_").replace(/-|\.|:/g, "_").replace(/\/|\\/g, "_").replace(/[^a-zA-Z0-9_$]/gi, ""), u = /^[0-9]/.test(u) ? "_" + u : u, (e.functions.prefix + u).replace(/_+/g, "_")),
59
58
  namespace: l,
60
59
  path: a,
61
60
  fullKey: f,
@@ -64,46 +63,46 @@ function _(e, { id: t, namespace: l, path: a, locale: r, value: n, typeValue: i
64
63
  };
65
64
  return null !== r && null !== n && (p.values[r] = n), o && Object.keys(o).length && (p.params = o), p;
66
65
  }
67
- let getCodeDataTranslations = (r, o, { translationFiles: y })=>{
68
- let { ignorePaths: k } = o, x = helpers.filterInputTranslationFiles(y, k), D = {};
69
- for(let r = 0; r < x.length; r++)!function(r, n, s) {
70
- let { locale: o, path: f } = s, p = node_path.join(node_path.dirname(f), node_path.basename(f, node_path.extname(f))), c = p;
71
- for(let e in s.data){
72
- let t = s.data[e];
73
- e && (c = p + ":" + e), function e(t, l, { id: a, namespace: r, path: n, locale: s, value: o }) {
66
+ let getCodeDataTranslations = (u, y, { translationFiles: _ })=>{
67
+ let { ignorePaths: k } = y, D = helpers.filterInputTranslationFiles(_, k), b = {};
68
+ for(let r = 0; r < D.length; r++)!function(r, i, u) {
69
+ let { locale: o, path: f } = u, p = node_path.join(node_path.dirname(f), node_path.basename(f, node_path.extname(f))), c = p;
70
+ for(let e in u.data){
71
+ let t = u.data[e];
72
+ e && (c = p + ":" + e), function e(t, l, { id: a, namespace: r, path: i, locale: u, value: o }) {
74
73
  let f = l[a];
75
- if (utils.isPrimitive(o)) l[a] = _(t, {
74
+ if (utils.isPrimitive(o)) l[a] = h(t, {
76
75
  id: a,
77
76
  namespace: r,
78
- path: n,
77
+ path: i,
79
78
  typeValue: "Primitive",
80
- locale: s,
79
+ locale: u,
81
80
  value: o
82
81
  }, f);
83
- else if (t.functions.asData && (l[a] = _(t, {
82
+ else if (t.functions.asData && (l[a] = h(t, {
84
83
  id: a,
85
84
  namespace: r,
86
- path: n,
85
+ path: i,
87
86
  typeValue: utils.isArray(o) ? "Array" : "Object",
88
- locale: s,
87
+ locale: u,
89
88
  value: o
90
89
  }, f)), utils.isArray(o)) {
91
- if (t.createArrayIndexBasedFns) for(let i = 0; i < o.length; i++)e(t, l, {
92
- id: a + "_" + i,
90
+ if (t.createArrayIndexBasedFns) for(let n = 0; n < o.length; n++)e(t, l, {
91
+ id: a + "_" + n,
93
92
  namespace: r,
94
- path: n + "[" + i + "]",
95
- locale: s,
96
- value: o[i]
93
+ path: i + "[" + n + "]",
94
+ locale: u,
95
+ value: o[n]
97
96
  });
98
- } else for(let i in o)e(t, l, {
99
- id: a + "_" + i,
97
+ } else for(let n in o)e(t, l, {
98
+ id: a + "_" + n,
100
99
  namespace: r,
101
- path: n + "." + i,
102
- locale: s,
103
- value: o[i]
100
+ path: i + "." + n,
101
+ locale: u,
102
+ value: o[n]
104
103
  });
105
104
  return l;
106
- }(r, n, {
105
+ }(r, i, {
107
106
  id: c,
108
107
  namespace: p,
109
108
  path: e,
@@ -111,27 +110,27 @@ let getCodeDataTranslations = (r, o, { translationFiles: y })=>{
111
110
  value: t
112
111
  });
113
112
  }
114
- }(o, D, x[r]);
113
+ }(y, b, D[r]);
115
114
  return !function(e, t) {
116
115
  let l = Object.keys(e).filter(pluralisation.isPluralKey);
117
116
  l.forEach((a)=>{
118
- let r = pluralisation.removePluralSuffix(a), n = pluralisation.getPluralSuffix(a), i = e[a], u = pluralisation.getRequiredPluralSuffix(r);
117
+ let r = pluralisation.removePluralSuffix(a), n = pluralisation.getPluralSuffix(a), s = e[a], u = pluralisation.getRequiredPluralSuffix(r);
119
118
  if (!l.includes(u)) return;
120
119
  let o = !!e[r];
121
- if (i) {
122
- o || (e[r] = _(t, {
120
+ if (s) {
121
+ o || (e[r] = h(t, {
123
122
  id: r,
124
- namespace: i.namespace,
125
- path: pluralisation.removePluralSuffix(i.path),
123
+ namespace: s.namespace,
124
+ path: pluralisation.removePluralSuffix(s.path),
126
125
  typeValue: "Primitive",
127
126
  locale: null,
128
127
  value: null
129
128
  }));
130
129
  let l = e[r].values || {};
131
- for(let a in i.values){
132
- let u = i.values[a];
130
+ for(let a in s.values){
131
+ let u = s.values[a];
133
132
  l[a] = utils.isObject(l[a]) ? l[a] : {}, l[a][n] = u;
134
- let o = h(t, u);
133
+ let o = g(t, u);
135
134
  o && (e[r].params = {
136
135
  ...e[r].params || {},
137
136
  ...o
@@ -145,19 +144,19 @@ let getCodeDataTranslations = (r, o, { translationFiles: y })=>{
145
144
  delete e[a];
146
145
  }
147
146
  });
148
- }(D, o), !function(e, t) {
147
+ }(b, y), !function(e, t) {
149
148
  for(let t in e){
150
- let l = e[t], a = null, r = !0;
149
+ let l = e[t], a = null, n = !0;
151
150
  for(let e in l.values){
152
151
  if (a && !utils.areEqual(a, l.values[e])) {
153
- r = !1;
152
+ n = !1;
154
153
  break;
155
154
  }
156
155
  a = l.values[e];
157
156
  }
158
- r && (e[t].equalValues = !0);
157
+ n && (e[t].equalValues = !0);
159
158
  }
160
- }(D), utils.objectSort(D);
159
+ }(b), utils.objectSort(b);
161
160
  };
162
161
 
163
162
  exports.codeDataTranslationsOptions = codeDataTranslationsOptions;
@@ -1,4 +1,4 @@
1
- import { join, dirname, basename, extname, sep } from 'node:path';
1
+ import { join, dirname, basename, extname } from 'node:path';
2
2
  import { isPrimitive, isArray, isObject, objectSort, 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';
@@ -19,7 +19,7 @@ const codeDataTranslationsOptions = {
19
19
  }
20
20
  }
21
21
  };
22
- function h(e, t, l) {
22
+ function g(e, t, l) {
23
23
  if (isPrimitive(t)) {
24
24
  let a = function(e, t) {
25
25
  if (isString(t)) {
@@ -32,14 +32,14 @@ function h(e, t, l) {
32
32
  ...a
33
33
  });
34
34
  } else if (isArray(t)) for(let a = 0; a < t.length; a++){
35
- let r = h(e, t[a], l);
35
+ let r = g(e, t[a], l);
36
36
  r && (l = {
37
37
  ...l || {},
38
38
  ...r
39
39
  });
40
40
  }
41
41
  else for(let a in t){
42
- let r = h(e, t[a], l);
42
+ let r = g(e, t[a], l);
43
43
  r && (l = {
44
44
  ...l || {},
45
45
  ...r
@@ -47,13 +47,12 @@ function h(e, t, l) {
47
47
  }
48
48
  return l;
49
49
  }
50
- let y = RegExp(sep, "g");
51
- function _(e, { id: t, namespace: l, path: a, locale: r, value: n, typeValue: i }, s) {
50
+ function h(e, { id: t, namespace: l, path: a, locale: r, value: n, typeValue: i }, s) {
52
51
  let u;
53
- let o = null === n ? null : h(e, n), f = l + e.tokens.namespaceDelimiter + a, p = {
52
+ let o = null === n ? null : g(e, n), f = l + e.tokens.namespaceDelimiter + a, p = {
54
53
  ...s,
55
54
  id: t,
56
- fnName: (u = f.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, "_")),
55
+ fnName: (u = f.replace(/~/g, "_").replace(/-|\.|:/g, "_").replace(/\/|\\/g, "_").replace(/[^a-zA-Z0-9_$]/gi, ""), u = /^[0-9]/.test(u) ? "_" + u : u, (e.functions.prefix + u).replace(/_+/g, "_")),
57
56
  namespace: l,
58
57
  path: a,
59
58
  fullKey: f,
@@ -62,46 +61,46 @@ function _(e, { id: t, namespace: l, path: a, locale: r, value: n, typeValue: i
62
61
  };
63
62
  return null !== r && null !== n && (p.values[r] = n), o && Object.keys(o).length && (p.params = o), p;
64
63
  }
65
- let getCodeDataTranslations = (r, o, { translationFiles: y })=>{
66
- let { ignorePaths: k } = o, x = filterInputTranslationFiles(y, k), D = {};
67
- for(let r = 0; r < x.length; r++)!function(r, n, s) {
68
- let { locale: o, path: f } = s, p = join(dirname(f), basename(f, extname(f))), c = p;
69
- for(let e in s.data){
70
- let t = s.data[e];
71
- e && (c = p + ":" + e), function e(t, l, { id: a, namespace: r, path: n, locale: s, value: o }) {
64
+ let getCodeDataTranslations = (u, y, { translationFiles: _ })=>{
65
+ let { ignorePaths: k } = y, D = filterInputTranslationFiles(_, k), b = {};
66
+ for(let r = 0; r < D.length; r++)!function(r, i, u) {
67
+ let { locale: o, path: f } = u, p = join(dirname(f), basename(f, extname(f))), c = p;
68
+ for(let e in u.data){
69
+ let t = u.data[e];
70
+ e && (c = p + ":" + e), function e(t, l, { id: a, namespace: r, path: i, locale: u, value: o }) {
72
71
  let f = l[a];
73
- if (isPrimitive(o)) l[a] = _(t, {
72
+ if (isPrimitive(o)) l[a] = h(t, {
74
73
  id: a,
75
74
  namespace: r,
76
- path: n,
75
+ path: i,
77
76
  typeValue: "Primitive",
78
- locale: s,
77
+ locale: u,
79
78
  value: o
80
79
  }, f);
81
- else if (t.functions.asData && (l[a] = _(t, {
80
+ else if (t.functions.asData && (l[a] = h(t, {
82
81
  id: a,
83
82
  namespace: r,
84
- path: n,
83
+ path: i,
85
84
  typeValue: isArray(o) ? "Array" : "Object",
86
- locale: s,
85
+ locale: u,
87
86
  value: o
88
87
  }, f)), isArray(o)) {
89
- if (t.createArrayIndexBasedFns) for(let i = 0; i < o.length; i++)e(t, l, {
90
- id: a + "_" + i,
88
+ if (t.createArrayIndexBasedFns) for(let n = 0; n < o.length; n++)e(t, l, {
89
+ id: a + "_" + n,
91
90
  namespace: r,
92
- path: n + "[" + i + "]",
93
- locale: s,
94
- value: o[i]
91
+ path: i + "[" + n + "]",
92
+ locale: u,
93
+ value: o[n]
95
94
  });
96
- } else for(let i in o)e(t, l, {
97
- id: a + "_" + i,
95
+ } else for(let n in o)e(t, l, {
96
+ id: a + "_" + n,
98
97
  namespace: r,
99
- path: n + "." + i,
100
- locale: s,
101
- value: o[i]
98
+ path: i + "." + n,
99
+ locale: u,
100
+ value: o[n]
102
101
  });
103
102
  return l;
104
- }(r, n, {
103
+ }(r, i, {
105
104
  id: c,
106
105
  namespace: p,
107
106
  path: e,
@@ -109,27 +108,27 @@ let getCodeDataTranslations = (r, o, { translationFiles: y })=>{
109
108
  value: t
110
109
  });
111
110
  }
112
- }(o, D, x[r]);
111
+ }(y, b, D[r]);
113
112
  return !function(e, t) {
114
113
  let l = Object.keys(e).filter(isPluralKey);
115
114
  l.forEach((a)=>{
116
- let r = removePluralSuffix(a), n = getPluralSuffix(a), i = e[a], u = getRequiredPluralSuffix(r);
115
+ let r = removePluralSuffix(a), n = getPluralSuffix(a), s = e[a], u = getRequiredPluralSuffix(r);
117
116
  if (!l.includes(u)) return;
118
117
  let o = !!e[r];
119
- if (i) {
120
- o || (e[r] = _(t, {
118
+ if (s) {
119
+ o || (e[r] = h(t, {
121
120
  id: r,
122
- namespace: i.namespace,
123
- path: removePluralSuffix(i.path),
121
+ namespace: s.namespace,
122
+ path: removePluralSuffix(s.path),
124
123
  typeValue: "Primitive",
125
124
  locale: null,
126
125
  value: null
127
126
  }));
128
127
  let l = e[r].values || {};
129
- for(let a in i.values){
130
- let u = i.values[a];
128
+ for(let a in s.values){
129
+ let u = s.values[a];
131
130
  l[a] = isObject(l[a]) ? l[a] : {}, l[a][n] = u;
132
- let o = h(t, u);
131
+ let o = g(t, u);
133
132
  o && (e[r].params = {
134
133
  ...e[r].params || {},
135
134
  ...o
@@ -143,19 +142,19 @@ let getCodeDataTranslations = (r, o, { translationFiles: y })=>{
143
142
  delete e[a];
144
143
  }
145
144
  });
146
- }(D, o), !function(e, t) {
145
+ }(b, y), !function(e, t) {
147
146
  for(let t in e){
148
- let l = e[t], a = null, r = !0;
147
+ let l = e[t], a = null, n = !0;
149
148
  for(let e in l.values){
150
149
  if (a && !areEqual(a, l.values[e])) {
151
- r = !1;
150
+ n = !1;
152
151
  break;
153
152
  }
154
153
  a = l.values[e];
155
154
  }
156
- r && (e[t].equalValues = !0);
155
+ n && (e[t].equalValues = !0);
157
156
  }
158
- }(D), objectSort(D);
157
+ }(b), objectSort(b);
159
158
  };
160
159
 
161
160
  export { codeDataTranslationsOptions, getCodeDataTranslations };
package/package.json CHANGED
@@ -5,8 +5,8 @@
5
5
  "node": "^14.18.0 || >=16.0.0"
6
6
  },
7
7
  "dependencies": {
8
- "@koine/node": "2.0.0-beta.161",
9
- "@koine/utils": "2.0.0-beta.161",
8
+ "@koine/node": "2.0.0-beta.163",
9
+ "@koine/utils": "2.0.0-beta.163",
10
10
  "comment-json": "^4.2.4",
11
11
  "consola": "^3.2.3",
12
12
  "glob": "^11.0.0",
@@ -100,5 +100,5 @@
100
100
  "module": "./index.esm.js",
101
101
  "main": "./index.cjs.js",
102
102
  "types": "./index.esm.d.ts",
103
- "version": "2.0.0-beta.161"
103
+ "version": "2.0.0-beta.163"
104
104
  }