@scoutello/i18n-magic 0.57.0 → 0.57.3

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.
Files changed (32) hide show
  1. package/dist/commands/check-missing.d.ts.map +1 -1
  2. package/dist/commands/check-missing.js +100 -3
  3. package/dist/commands/check-missing.js.map +1 -1
  4. package/dist/commands/scan.d.ts.map +1 -1
  5. package/dist/commands/scan.js +6 -0
  6. package/dist/commands/scan.js.map +1 -1
  7. package/dist/commands/sync-locales.d.ts.map +1 -1
  8. package/dist/commands/sync-locales.js +186 -98
  9. package/dist/commands/sync-locales.js.map +1 -1
  10. package/dist/lib/utils.d.ts +6 -2
  11. package/dist/lib/utils.d.ts.map +1 -1
  12. package/dist/lib/utils.js +33 -12
  13. package/dist/lib/utils.js.map +1 -1
  14. package/package.json +10 -8
  15. package/src/commands/check-missing.ts +154 -3
  16. package/src/commands/scan.ts +7 -0
  17. package/src/commands/sync-locales.ts +254 -155
  18. package/src/lib/utils.ts +37 -10
  19. package/dist/commands/create-pruned-namespace-automated.d.ts +0 -20
  20. package/dist/commands/create-pruned-namespace-automated.d.ts.map +0 -1
  21. package/dist/commands/create-pruned-namespace-automated.js +0 -98
  22. package/dist/commands/create-pruned-namespace-automated.js.map +0 -1
  23. package/dist/commands/create-pruned-namespace.d.ts +0 -3
  24. package/dist/commands/create-pruned-namespace.d.ts.map +0 -1
  25. package/dist/commands/create-pruned-namespace.js +0 -123
  26. package/dist/commands/create-pruned-namespace.js.map +0 -1
  27. package/dist/i18n-magic.cjs.development.js +0 -1787
  28. package/dist/i18n-magic.cjs.development.js.map +0 -1
  29. package/dist/i18n-magic.cjs.production.min.js +0 -2
  30. package/dist/i18n-magic.cjs.production.min.js.map +0 -1
  31. package/dist/i18n-magic.esm.js +0 -1776
  32. package/dist/i18n-magic.esm.js.map +0 -1
@@ -1,1787 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var glob = require('fast-glob');
6
- var i18nextScanner = require('i18next-scanner');
7
- var fs = require('node:fs');
8
- var path = require('node:path');
9
- var prompts = require('prompts');
10
- var console$1 = require('console');
11
-
12
- function _construct(t, e, r) {
13
- if (_isNativeReflectConstruct()) return Reflect.construct.apply(null, arguments);
14
- var o = [null];
15
- o.push.apply(o, e);
16
- var p = new (t.bind.apply(t, o))();
17
- return r && _setPrototypeOf(p, r.prototype), p;
18
- }
19
- function _isNativeReflectConstruct() {
20
- try {
21
- var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
22
- } catch (t) {}
23
- return (_isNativeReflectConstruct = function () {
24
- return !!t;
25
- })();
26
- }
27
- function _regeneratorRuntime() {
28
- _regeneratorRuntime = function () {
29
- return e;
30
- };
31
- var t,
32
- e = {},
33
- r = Object.prototype,
34
- n = r.hasOwnProperty,
35
- o = Object.defineProperty || function (t, e, r) {
36
- t[e] = r.value;
37
- },
38
- i = "function" == typeof Symbol ? Symbol : {},
39
- a = i.iterator || "@@iterator",
40
- c = i.asyncIterator || "@@asyncIterator",
41
- u = i.toStringTag || "@@toStringTag";
42
- function define(t, e, r) {
43
- return Object.defineProperty(t, e, {
44
- value: r,
45
- enumerable: !0,
46
- configurable: !0,
47
- writable: !0
48
- }), t[e];
49
- }
50
- try {
51
- define({}, "");
52
- } catch (t) {
53
- define = function (t, e, r) {
54
- return t[e] = r;
55
- };
56
- }
57
- function wrap(t, e, r, n) {
58
- var i = e && e.prototype instanceof Generator ? e : Generator,
59
- a = Object.create(i.prototype),
60
- c = new Context(n || []);
61
- return o(a, "_invoke", {
62
- value: makeInvokeMethod(t, r, c)
63
- }), a;
64
- }
65
- function tryCatch(t, e, r) {
66
- try {
67
- return {
68
- type: "normal",
69
- arg: t.call(e, r)
70
- };
71
- } catch (t) {
72
- return {
73
- type: "throw",
74
- arg: t
75
- };
76
- }
77
- }
78
- e.wrap = wrap;
79
- var h = "suspendedStart",
80
- l = "suspendedYield",
81
- f = "executing",
82
- s = "completed",
83
- y = {};
84
- function Generator() {}
85
- function GeneratorFunction() {}
86
- function GeneratorFunctionPrototype() {}
87
- var p = {};
88
- define(p, a, function () {
89
- return this;
90
- });
91
- var d = Object.getPrototypeOf,
92
- v = d && d(d(values([])));
93
- v && v !== r && n.call(v, a) && (p = v);
94
- var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
95
- function defineIteratorMethods(t) {
96
- ["next", "throw", "return"].forEach(function (e) {
97
- define(t, e, function (t) {
98
- return this._invoke(e, t);
99
- });
100
- });
101
- }
102
- function AsyncIterator(t, e) {
103
- function invoke(r, o, i, a) {
104
- var c = tryCatch(t[r], t, o);
105
- if ("throw" !== c.type) {
106
- var u = c.arg,
107
- h = u.value;
108
- return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
109
- invoke("next", t, i, a);
110
- }, function (t) {
111
- invoke("throw", t, i, a);
112
- }) : e.resolve(h).then(function (t) {
113
- u.value = t, i(u);
114
- }, function (t) {
115
- return invoke("throw", t, i, a);
116
- });
117
- }
118
- a(c.arg);
119
- }
120
- var r;
121
- o(this, "_invoke", {
122
- value: function (t, n) {
123
- function callInvokeWithMethodAndArg() {
124
- return new e(function (e, r) {
125
- invoke(t, n, e, r);
126
- });
127
- }
128
- return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
129
- }
130
- });
131
- }
132
- function makeInvokeMethod(e, r, n) {
133
- var o = h;
134
- return function (i, a) {
135
- if (o === f) throw Error("Generator is already running");
136
- if (o === s) {
137
- if ("throw" === i) throw a;
138
- return {
139
- value: t,
140
- done: !0
141
- };
142
- }
143
- for (n.method = i, n.arg = a;;) {
144
- var c = n.delegate;
145
- if (c) {
146
- var u = maybeInvokeDelegate(c, n);
147
- if (u) {
148
- if (u === y) continue;
149
- return u;
150
- }
151
- }
152
- if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
153
- if (o === h) throw o = s, n.arg;
154
- n.dispatchException(n.arg);
155
- } else "return" === n.method && n.abrupt("return", n.arg);
156
- o = f;
157
- var p = tryCatch(e, r, n);
158
- if ("normal" === p.type) {
159
- if (o = n.done ? s : l, p.arg === y) continue;
160
- return {
161
- value: p.arg,
162
- done: n.done
163
- };
164
- }
165
- "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
166
- }
167
- };
168
- }
169
- function maybeInvokeDelegate(e, r) {
170
- var n = r.method,
171
- o = e.iterator[n];
172
- if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
173
- var i = tryCatch(o, e.iterator, r.arg);
174
- if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
175
- var a = i.arg;
176
- return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
177
- }
178
- function pushTryEntry(t) {
179
- var e = {
180
- tryLoc: t[0]
181
- };
182
- 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
183
- }
184
- function resetTryEntry(t) {
185
- var e = t.completion || {};
186
- e.type = "normal", delete e.arg, t.completion = e;
187
- }
188
- function Context(t) {
189
- this.tryEntries = [{
190
- tryLoc: "root"
191
- }], t.forEach(pushTryEntry, this), this.reset(!0);
192
- }
193
- function values(e) {
194
- if (e || "" === e) {
195
- var r = e[a];
196
- if (r) return r.call(e);
197
- if ("function" == typeof e.next) return e;
198
- if (!isNaN(e.length)) {
199
- var o = -1,
200
- i = function next() {
201
- for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
202
- return next.value = t, next.done = !0, next;
203
- };
204
- return i.next = i;
205
- }
206
- }
207
- throw new TypeError(typeof e + " is not iterable");
208
- }
209
- return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
210
- value: GeneratorFunctionPrototype,
211
- configurable: !0
212
- }), o(GeneratorFunctionPrototype, "constructor", {
213
- value: GeneratorFunction,
214
- configurable: !0
215
- }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
216
- var e = "function" == typeof t && t.constructor;
217
- return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
218
- }, e.mark = function (t) {
219
- return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
220
- }, e.awrap = function (t) {
221
- return {
222
- __await: t
223
- };
224
- }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
225
- return this;
226
- }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
227
- void 0 === i && (i = Promise);
228
- var a = new AsyncIterator(wrap(t, r, n, o), i);
229
- return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
230
- return t.done ? t.value : a.next();
231
- });
232
- }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
233
- return this;
234
- }), define(g, "toString", function () {
235
- return "[object Generator]";
236
- }), e.keys = function (t) {
237
- var e = Object(t),
238
- r = [];
239
- for (var n in e) r.push(n);
240
- return r.reverse(), function next() {
241
- for (; r.length;) {
242
- var t = r.pop();
243
- if (t in e) return next.value = t, next.done = !1, next;
244
- }
245
- return next.done = !0, next;
246
- };
247
- }, e.values = values, Context.prototype = {
248
- constructor: Context,
249
- reset: function (e) {
250
- if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
251
- },
252
- stop: function () {
253
- this.done = !0;
254
- var t = this.tryEntries[0].completion;
255
- if ("throw" === t.type) throw t.arg;
256
- return this.rval;
257
- },
258
- dispatchException: function (e) {
259
- if (this.done) throw e;
260
- var r = this;
261
- function handle(n, o) {
262
- return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
263
- }
264
- for (var o = this.tryEntries.length - 1; o >= 0; --o) {
265
- var i = this.tryEntries[o],
266
- a = i.completion;
267
- if ("root" === i.tryLoc) return handle("end");
268
- if (i.tryLoc <= this.prev) {
269
- var c = n.call(i, "catchLoc"),
270
- u = n.call(i, "finallyLoc");
271
- if (c && u) {
272
- if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
273
- if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
274
- } else if (c) {
275
- if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
276
- } else {
277
- if (!u) throw Error("try statement without catch or finally");
278
- if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
279
- }
280
- }
281
- }
282
- },
283
- abrupt: function (t, e) {
284
- for (var r = this.tryEntries.length - 1; r >= 0; --r) {
285
- var o = this.tryEntries[r];
286
- if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
287
- var i = o;
288
- break;
289
- }
290
- }
291
- i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
292
- var a = i ? i.completion : {};
293
- return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
294
- },
295
- complete: function (t, e) {
296
- if ("throw" === t.type) throw t.arg;
297
- return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
298
- },
299
- finish: function (t) {
300
- for (var e = this.tryEntries.length - 1; e >= 0; --e) {
301
- var r = this.tryEntries[e];
302
- if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
303
- }
304
- },
305
- catch: function (t) {
306
- for (var e = this.tryEntries.length - 1; e >= 0; --e) {
307
- var r = this.tryEntries[e];
308
- if (r.tryLoc === t) {
309
- var n = r.completion;
310
- if ("throw" === n.type) {
311
- var o = n.arg;
312
- resetTryEntry(r);
313
- }
314
- return o;
315
- }
316
- }
317
- throw Error("illegal catch attempt");
318
- },
319
- delegateYield: function (e, r, n) {
320
- return this.delegate = {
321
- iterator: values(e),
322
- resultName: r,
323
- nextLoc: n
324
- }, "next" === this.method && (this.arg = t), y;
325
- }
326
- }, e;
327
- }
328
- function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
329
- try {
330
- var info = gen[key](arg);
331
- var value = info.value;
332
- } catch (error) {
333
- reject(error);
334
- return;
335
- }
336
- if (info.done) {
337
- resolve(value);
338
- } else {
339
- Promise.resolve(value).then(_next, _throw);
340
- }
341
- }
342
- function _asyncToGenerator(fn) {
343
- return function () {
344
- var self = this,
345
- args = arguments;
346
- return new Promise(function (resolve, reject) {
347
- var gen = fn.apply(self, args);
348
- function _next(value) {
349
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
350
- }
351
- function _throw(err) {
352
- asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
353
- }
354
- _next(undefined);
355
- });
356
- };
357
- }
358
- function _extends() {
359
- _extends = Object.assign ? Object.assign.bind() : function (target) {
360
- for (var i = 1; i < arguments.length; i++) {
361
- var source = arguments[i];
362
- for (var key in source) {
363
- if (Object.prototype.hasOwnProperty.call(source, key)) {
364
- target[key] = source[key];
365
- }
366
- }
367
- }
368
- return target;
369
- };
370
- return _extends.apply(this, arguments);
371
- }
372
- function _inheritsLoose(subClass, superClass) {
373
- subClass.prototype = Object.create(superClass.prototype);
374
- subClass.prototype.constructor = subClass;
375
- _setPrototypeOf(subClass, superClass);
376
- }
377
- function _getPrototypeOf(o) {
378
- _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
379
- return o.__proto__ || Object.getPrototypeOf(o);
380
- };
381
- return _getPrototypeOf(o);
382
- }
383
- function _setPrototypeOf(o, p) {
384
- _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
385
- o.__proto__ = p;
386
- return o;
387
- };
388
- return _setPrototypeOf(o, p);
389
- }
390
- function _isNativeFunction(fn) {
391
- try {
392
- return Function.toString.call(fn).indexOf("[native code]") !== -1;
393
- } catch (e) {
394
- return typeof fn === "function";
395
- }
396
- }
397
- function _wrapNativeSuper(Class) {
398
- var _cache = typeof Map === "function" ? new Map() : undefined;
399
- _wrapNativeSuper = function _wrapNativeSuper(Class) {
400
- if (Class === null || !_isNativeFunction(Class)) return Class;
401
- if (typeof Class !== "function") {
402
- throw new TypeError("Super expression must either be null or a function");
403
- }
404
- if (typeof _cache !== "undefined") {
405
- if (_cache.has(Class)) return _cache.get(Class);
406
- _cache.set(Class, Wrapper);
407
- }
408
- function Wrapper() {
409
- return _construct(Class, arguments, _getPrototypeOf(this).constructor);
410
- }
411
- Wrapper.prototype = Object.create(Class.prototype, {
412
- constructor: {
413
- value: Wrapper,
414
- enumerable: false,
415
- writable: true,
416
- configurable: true
417
- }
418
- });
419
- return _setPrototypeOf(Wrapper, Class);
420
- };
421
- return _wrapNativeSuper(Class);
422
- }
423
- function _unsupportedIterableToArray(o, minLen) {
424
- if (!o) return;
425
- if (typeof o === "string") return _arrayLikeToArray(o, minLen);
426
- var n = Object.prototype.toString.call(o).slice(8, -1);
427
- if (n === "Object" && o.constructor) n = o.constructor.name;
428
- if (n === "Map" || n === "Set") return Array.from(o);
429
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
430
- }
431
- function _arrayLikeToArray(arr, len) {
432
- if (len == null || len > arr.length) len = arr.length;
433
- for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
434
- return arr2;
435
- }
436
- function _createForOfIteratorHelperLoose(o, allowArrayLike) {
437
- var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
438
- if (it) return (it = it.call(o)).next.bind(it);
439
- if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
440
- if (it) o = it;
441
- var i = 0;
442
- return function () {
443
- if (i >= o.length) return {
444
- done: true
445
- };
446
- return {
447
- done: false,
448
- value: o[i++]
449
- };
450
- };
451
- }
452
- throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
453
- }
454
-
455
- var languages = [{
456
- label: "Deutsch",
457
- name: "German",
458
- value: "de"
459
- }, {
460
- label: "English",
461
- name: "English",
462
- value: "en"
463
- }, {
464
- label: "Español",
465
- name: "Spanish",
466
- value: "es"
467
- }, {
468
- label: "Français",
469
- name: "French",
470
- value: "fr"
471
- }, {
472
- label: "Dansk",
473
- name: "Danish",
474
- value: "dk"
475
- }, {
476
- label: "中文",
477
- name: "Chinese",
478
- value: "cn"
479
- }, {
480
- label: "Русский",
481
- name: "Russian",
482
- value: "ru"
483
- }, {
484
- label: "Italiano",
485
- name: "Italian",
486
- value: "it"
487
- }, {
488
- label: "Nederlands",
489
- name: "Dutch",
490
- value: "nl"
491
- }, {
492
- label: "Português",
493
- name: "Portuguese",
494
- value: "pt"
495
- }, {
496
- label: "Türkçe",
497
- name: "Turkish",
498
- value: "tr"
499
- }, {
500
- label: "Polski",
501
- name: "Polish",
502
- value: "pl"
503
- }, {
504
- label: "Українська",
505
- name: "Ukrainian",
506
- value: "ua"
507
- }, {
508
- label: "Suomi",
509
- name: "Finnish",
510
- value: "fi"
511
- }, {
512
- label: "Norsk",
513
- name: "Norwegian",
514
- value: "no"
515
- }, {
516
- label: "Svenska",
517
- name: "Swedish",
518
- value: "sv"
519
- }, {
520
- label: "Čeština",
521
- name: "Czech",
522
- value: "cz"
523
- }, {
524
- label: "Ελληνικά",
525
- name: "Greek",
526
- value: "gr"
527
- }, {
528
- label: "日本語",
529
- name: "Japanese",
530
- value: "jp"
531
- }, {
532
- label: "한국어",
533
- name: "Korean",
534
- value: "kr"
535
- }, {
536
- label: "Română",
537
- name: "Romanian",
538
- value: "ro"
539
- }, {
540
- label: "Hrvatski",
541
- name: "Croatian",
542
- value: "hr"
543
- }, {
544
- label: "Magyar",
545
- name: "Hungarian",
546
- value: "hu"
547
- }, {
548
- label: "Slovensky",
549
- name: "Slovak",
550
- value: "sk"
551
- }, {
552
- label: "हिन्दी",
553
- name: "Hindi",
554
- value: "hi"
555
- }, {
556
- label: "தமிழ்",
557
- name: "Tamil",
558
- value: "ta"
559
- }, {
560
- label: "Bahasa Indonesia",
561
- name: "Indonesian",
562
- value: "id"
563
- }, {
564
- label: "Tiếng Việt",
565
- name: "Vietnamese",
566
- value: "vn"
567
- }];
568
-
569
- var loadConfig = function loadConfig(_ref) {
570
- var _ref$configPath = _ref.configPath,
571
- configPath = _ref$configPath === void 0 ? "i18n-magic.js" : _ref$configPath;
572
- var filePath = path.join(process.cwd(), configPath);
573
- if (!fs.existsSync(filePath)) {
574
- console.error("Config file does not exist:", filePath);
575
- process.exit(1);
576
- }
577
- try {
578
- var config = require(filePath);
579
- // Validate config if needed
580
- return config;
581
- } catch (error) {
582
- console.error("Error while loading config:", error);
583
- process.exit(1);
584
- }
585
- };
586
- function removeDuplicatesFromArray(arr) {
587
- return arr.filter(function (item, index) {
588
- return arr.indexOf(item) === index;
589
- });
590
- }
591
- var translateKey = /*#__PURE__*/function () {
592
- var _ref3 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(_ref2) {
593
- var inputLanguage, context, object, openai, outputLanguage, model, entries, chunks, i, result, existingInput, existingOutput, input, output, _i, _chunks, chunk, chunkObject, completion, translatedChunk;
594
- return _regeneratorRuntime().wrap(function _callee$(_context) {
595
- while (1) switch (_context.prev = _context.next) {
596
- case 0:
597
- inputLanguage = _ref2.inputLanguage, context = _ref2.context, object = _ref2.object, openai = _ref2.openai, outputLanguage = _ref2.outputLanguage, model = _ref2.model;
598
- // Split object into chunks of 100 keys
599
- entries = Object.entries(object);
600
- chunks = [];
601
- for (i = 0; i < entries.length; i += 100) {
602
- chunks.push(entries.slice(i, i + 100));
603
- }
604
- result = {};
605
- existingInput = languages.find(function (l) {
606
- return l.value === inputLanguage;
607
- });
608
- existingOutput = languages.find(function (l) {
609
- return l.value === outputLanguage;
610
- });
611
- input = (existingInput == null ? void 0 : existingInput.label) || inputLanguage;
612
- output = (existingOutput == null ? void 0 : existingOutput.label) || outputLanguage; // Translate each chunk
613
- _i = 0, _chunks = chunks;
614
- case 10:
615
- if (!(_i < _chunks.length)) {
616
- _context.next = 23;
617
- break;
618
- }
619
- chunk = _chunks[_i];
620
- chunkObject = Object.fromEntries(chunk);
621
- _context.next = 15;
622
- return openai.beta.chat.completions.parse({
623
- model: model,
624
- messages: [{
625
- content: "You are a bot that translates the values of a locales JSON. " + (context ? "The user provided some additional context or guidelines about what to fill in the blanks: \"" + context + "\". " : "") + "The user provides you a JSON with a field named \"inputLanguage\", which defines the language the values of the JSON are defined in. It also has a field named \"outputLanguage\", which defines the language you should translate the values to. The last field is named \"data\", which includes the object with the values to translate. The keys of the values should never be changed. You output only a JSON, which has the same keys as the input, but with translated values. I give you an example input: {\"inputLanguage\": \"English\", outputLanguage: \"German\", \"keys\": {\"hello\": \"Hello\", \"world\": \"World\"}}. The output should be {\"hello\": \"Hallo\", \"world\": \"Welt\"}.",
626
- role: "system"
627
- }, {
628
- content: JSON.stringify({
629
- inputLanguage: input,
630
- outputLanguage: output,
631
- data: chunkObject
632
- }),
633
- role: "user"
634
- }],
635
- response_format: {
636
- type: "json_object"
637
- }
638
- });
639
- case 15:
640
- completion = _context.sent;
641
- translatedChunk = JSON.parse(completion.choices[0].message.content); // Merge translated chunk with result
642
- result = _extends({}, result, translatedChunk);
643
- // Optional: Add a small delay between chunks to avoid rate limiting
644
- _context.next = 20;
645
- return new Promise(function (resolve) {
646
- return setTimeout(resolve, 100);
647
- });
648
- case 20:
649
- _i++;
650
- _context.next = 10;
651
- break;
652
- case 23:
653
- return _context.abrupt("return", result);
654
- case 24:
655
- case "end":
656
- return _context.stop();
657
- }
658
- }, _callee);
659
- }));
660
- return function translateKey(_x) {
661
- return _ref3.apply(this, arguments);
662
- };
663
- }();
664
- var loadLocalesFile = /*#__PURE__*/function () {
665
- var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(loadPath, locale, namespace) {
666
- var resolvedPath, content, json;
667
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
668
- while (1) switch (_context2.prev = _context2.next) {
669
- case 0:
670
- if (!(typeof loadPath === "string")) {
671
- _context2.next = 11;
672
- break;
673
- }
674
- resolvedPath = loadPath.replace("{{lng}}", locale).replace("{{ns}}", namespace);
675
- content = fs.readFileSync(resolvedPath, "utf-8");
676
- _context2.prev = 3;
677
- json = JSON.parse(content);
678
- return _context2.abrupt("return", json);
679
- case 8:
680
- _context2.prev = 8;
681
- _context2.t0 = _context2["catch"](3);
682
- throw new TranslationError("Invalid JSON in locale file for " + locale + ":" + namespace + ". Path: " + resolvedPath, locale, namespace, _context2.t0 instanceof Error ? _context2.t0 : undefined);
683
- case 11:
684
- return _context2.abrupt("return", loadPath(locale, namespace));
685
- case 12:
686
- case "end":
687
- return _context2.stop();
688
- }
689
- }, _callee2, null, [[3, 8]]);
690
- }));
691
- return function loadLocalesFile(_x2, _x3, _x4) {
692
- return _ref4.apply(this, arguments);
693
- };
694
- }();
695
- var writeLocalesFile = /*#__PURE__*/function () {
696
- var _ref5 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(savePath, locale, namespace, data) {
697
- var resolvedSavePath;
698
- return _regeneratorRuntime().wrap(function _callee3$(_context3) {
699
- while (1) switch (_context3.prev = _context3.next) {
700
- case 0:
701
- if (!(typeof savePath === "string")) {
702
- _context3.next = 4;
703
- break;
704
- }
705
- resolvedSavePath = savePath.replace("{{lng}}", locale).replace("{{ns}}", namespace);
706
- fs.writeFileSync(resolvedSavePath, JSON.stringify(data, null, 2));
707
- return _context3.abrupt("return");
708
- case 4:
709
- _context3.next = 6;
710
- return savePath(locale, namespace, data);
711
- case 6:
712
- case "end":
713
- return _context3.stop();
714
- }
715
- }, _callee3);
716
- }));
717
- return function writeLocalesFile(_x5, _x6, _x7, _x8) {
718
- return _ref5.apply(this, arguments);
719
- };
720
- }();
721
- var getPureKey = function getPureKey(key, namespace, isDefault) {
722
- var splitted = key.split(":");
723
- if (splitted.length === 1) {
724
- if (isDefault) {
725
- return key;
726
- }
727
- return null;
728
- }
729
- if (splitted[0] === namespace) {
730
- return splitted[1];
731
- }
732
- return null;
733
- };
734
- var getMissingKeys = /*#__PURE__*/function () {
735
- var _ref7 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(_ref6) {
736
- var globPatterns, namespaces, defaultNamespace, defaultLocale, loadPath, parser, files, keys, _iterator, _step, file, content, uniqueKeys, newKeys, _iterator2, _step2, namespace, existingKeys, _iterator3, _step3, key, pureKey;
737
- return _regeneratorRuntime().wrap(function _callee4$(_context4) {
738
- while (1) switch (_context4.prev = _context4.next) {
739
- case 0:
740
- globPatterns = _ref6.globPatterns, namespaces = _ref6.namespaces, defaultNamespace = _ref6.defaultNamespace, defaultLocale = _ref6.defaultLocale, loadPath = _ref6.loadPath;
741
- parser = new i18nextScanner.Parser({
742
- nsSeparator: false,
743
- keySeparator: false
744
- });
745
- _context4.next = 4;
746
- return glob([].concat(globPatterns, ["!**/node_modules/**"]));
747
- case 4:
748
- files = _context4.sent;
749
- keys = [];
750
- for (_iterator = _createForOfIteratorHelperLoose(files); !(_step = _iterator()).done;) {
751
- file = _step.value;
752
- content = fs.readFileSync(file, "utf-8");
753
- parser.parseFuncFromString(content, {
754
- list: ["t"]
755
- }, function (key) {
756
- keys.push(key);
757
- });
758
- }
759
- uniqueKeys = removeDuplicatesFromArray(keys);
760
- newKeys = [];
761
- _iterator2 = _createForOfIteratorHelperLoose(namespaces);
762
- case 10:
763
- if ((_step2 = _iterator2()).done) {
764
- _context4.next = 27;
765
- break;
766
- }
767
- namespace = _step2.value;
768
- _context4.next = 14;
769
- return loadLocalesFile(loadPath, defaultLocale, namespace);
770
- case 14:
771
- existingKeys = _context4.sent;
772
- console.log(Object.keys(existingKeys).length, "existing keys");
773
- _iterator3 = _createForOfIteratorHelperLoose(uniqueKeys);
774
- case 17:
775
- if ((_step3 = _iterator3()).done) {
776
- _context4.next = 25;
777
- break;
778
- }
779
- key = _step3.value;
780
- pureKey = getPureKey(key, namespace, namespace === defaultNamespace);
781
- if (pureKey) {
782
- _context4.next = 22;
783
- break;
784
- }
785
- return _context4.abrupt("continue", 23);
786
- case 22:
787
- if (!existingKeys[pureKey]) {
788
- newKeys.push({
789
- key: pureKey,
790
- namespace: namespace
791
- });
792
- }
793
- case 23:
794
- _context4.next = 17;
795
- break;
796
- case 25:
797
- _context4.next = 10;
798
- break;
799
- case 27:
800
- return _context4.abrupt("return", newKeys);
801
- case 28:
802
- case "end":
803
- return _context4.stop();
804
- }
805
- }, _callee4);
806
- }));
807
- return function getMissingKeys(_x9) {
808
- return _ref7.apply(this, arguments);
809
- };
810
- }();
811
- var getTextInput = /*#__PURE__*/function () {
812
- var _ref8 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(prompt) {
813
- var input;
814
- return _regeneratorRuntime().wrap(function _callee5$(_context5) {
815
- while (1) switch (_context5.prev = _context5.next) {
816
- case 0:
817
- _context5.next = 2;
818
- return prompts({
819
- name: "value",
820
- type: "text",
821
- message: prompt,
822
- onState: function onState(state) {
823
- if (state.aborted) {
824
- process.nextTick(function () {
825
- process.exit(0);
826
- });
827
- }
828
- }
829
- });
830
- case 2:
831
- input = _context5.sent;
832
- return _context5.abrupt("return", input.value);
833
- case 4:
834
- case "end":
835
- return _context5.stop();
836
- }
837
- }, _callee5);
838
- }));
839
- return function getTextInput(_x10) {
840
- return _ref8.apply(this, arguments);
841
- };
842
- }();
843
- var checkAllKeysExist = /*#__PURE__*/function () {
844
- var _ref10 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(_ref9) {
845
- var namespaces, defaultLocale, loadPath, locales, context, openai, savePath, disableTranslation, model, _iterator4, _step4, namespace, defaultLocaleKeys, _iterator5, _step5, locale, localeKeys, missingKeys, _i2, _Object$entries, _Object$entries$_i, key, value, translatedValues, updatedLocaleKeys;
846
- return _regeneratorRuntime().wrap(function _callee6$(_context6) {
847
- while (1) switch (_context6.prev = _context6.next) {
848
- case 0:
849
- namespaces = _ref9.namespaces, defaultLocale = _ref9.defaultLocale, loadPath = _ref9.loadPath, locales = _ref9.locales, context = _ref9.context, openai = _ref9.openai, savePath = _ref9.savePath, disableTranslation = _ref9.disableTranslation, model = _ref9.model;
850
- if (!disableTranslation) {
851
- _context6.next = 3;
852
- break;
853
- }
854
- return _context6.abrupt("return");
855
- case 3:
856
- _iterator4 = _createForOfIteratorHelperLoose(namespaces);
857
- case 4:
858
- if ((_step4 = _iterator4()).done) {
859
- _context6.next = 31;
860
- break;
861
- }
862
- namespace = _step4.value;
863
- _context6.next = 8;
864
- return loadLocalesFile(loadPath, defaultLocale, namespace);
865
- case 8:
866
- defaultLocaleKeys = _context6.sent;
867
- _iterator5 = _createForOfIteratorHelperLoose(locales);
868
- case 10:
869
- if ((_step5 = _iterator5()).done) {
870
- _context6.next = 29;
871
- break;
872
- }
873
- locale = _step5.value;
874
- if (!(locale === defaultLocale)) {
875
- _context6.next = 14;
876
- break;
877
- }
878
- return _context6.abrupt("continue", 27);
879
- case 14:
880
- _context6.next = 16;
881
- return loadLocalesFile(loadPath, locale, namespace);
882
- case 16:
883
- localeKeys = _context6.sent;
884
- missingKeys = {}; // Check which keys from default locale are missing in current locale
885
- for (_i2 = 0, _Object$entries = Object.entries(defaultLocaleKeys); _i2 < _Object$entries.length; _i2++) {
886
- _Object$entries$_i = _Object$entries[_i2], key = _Object$entries$_i[0], value = _Object$entries$_i[1];
887
- if (!localeKeys[key]) {
888
- missingKeys[key] = value;
889
- }
890
- }
891
- // If there are missing keys, translate them
892
- if (!(Object.keys(missingKeys).length > 0)) {
893
- _context6.next = 27;
894
- break;
895
- }
896
- console.log("Found " + Object.keys(missingKeys).length + " missing keys in " + locale + " (namespace: " + namespace + ")");
897
- _context6.next = 23;
898
- return translateKey({
899
- inputLanguage: defaultLocale,
900
- outputLanguage: locale,
901
- context: context,
902
- object: missingKeys,
903
- openai: openai,
904
- model: model
905
- });
906
- case 23:
907
- translatedValues = _context6.sent;
908
- // Merge translated values with existing ones
909
- updatedLocaleKeys = _extends({}, localeKeys, translatedValues); // Save the updated translations
910
- writeLocalesFile(savePath, locale, namespace, updatedLocaleKeys);
911
- console.log("\u2713 Translated and saved missing keys for " + locale + " (namespace: " + namespace + ")");
912
- case 27:
913
- _context6.next = 10;
914
- break;
915
- case 29:
916
- _context6.next = 4;
917
- break;
918
- case 31:
919
- case "end":
920
- return _context6.stop();
921
- }
922
- }, _callee6);
923
- }));
924
- return function checkAllKeysExist(_x11) {
925
- return _ref10.apply(this, arguments);
926
- };
927
- }();
928
- var TranslationError = /*#__PURE__*/function (_Error) {
929
- function TranslationError(message, locale, namespace, cause) {
930
- var _this;
931
- _this = _Error.call(this, message) || this;
932
- _this.locale = void 0;
933
- _this.namespace = void 0;
934
- _this.cause = void 0;
935
- _this.locale = locale;
936
- _this.namespace = namespace;
937
- _this.cause = cause;
938
- _this.name = "TranslationError";
939
- return _this;
940
- }
941
- _inheritsLoose(TranslationError, _Error);
942
- return TranslationError;
943
- }( /*#__PURE__*/_wrapNativeSuper(Error));
944
-
945
- var checkMissing = /*#__PURE__*/function () {
946
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
947
- var newKeys;
948
- return _regeneratorRuntime().wrap(function _callee$(_context) {
949
- while (1) switch (_context.prev = _context.next) {
950
- case 0:
951
- _context.next = 2;
952
- return getMissingKeys(config);
953
- case 2:
954
- newKeys = _context.sent;
955
- if (newKeys.length > 0) {
956
- console.error("Error: Missing translations found!");
957
- process.exit(1);
958
- }
959
- case 4:
960
- case "end":
961
- return _context.stop();
962
- }
963
- }, _callee);
964
- }));
965
- return function checkMissing(_x) {
966
- return _ref.apply(this, arguments);
967
- };
968
- }();
969
-
970
- var removeUnusedKeys = /*#__PURE__*/function () {
971
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
972
- var globPatterns, namespaces, defaultNamespace, locales, loadPath, savePath, parser, files, extractedKeys, _iterator, _step, file, content, uniqueExtractedKeys, stats, _iterator2, _step2, namespace, usedKeysSet, _iterator3, _step3, key, pureKey, _iterator4, _step4, locale, existingKeys, existingKeysCount, cleanedKeys, removedCount, _i, _Object$entries, _Object$entries$_i, _key, value;
973
- return _regeneratorRuntime().wrap(function _callee$(_context) {
974
- while (1) switch (_context.prev = _context.next) {
975
- case 0:
976
- globPatterns = config.globPatterns, namespaces = config.namespaces, defaultNamespace = config.defaultNamespace, locales = config.locales, loadPath = config.loadPath, savePath = config.savePath; // Set up the parser
977
- parser = new i18nextScanner.Parser({
978
- nsSeparator: false,
979
- keySeparator: false
980
- }); // Find all files to scan
981
- _context.next = 4;
982
- return glob([].concat(globPatterns, ["!**/node_modules/**"]));
983
- case 4:
984
- files = _context.sent;
985
- // Extract all translation keys from the codebase
986
- extractedKeys = [];
987
- for (_iterator = _createForOfIteratorHelperLoose(files); !(_step = _iterator()).done;) {
988
- file = _step.value;
989
- content = fs.readFileSync(file, "utf-8");
990
- parser.parseFuncFromString(content, {
991
- list: ["t"]
992
- }, function (key) {
993
- extractedKeys.push(key);
994
- });
995
- }
996
- // Remove duplicates
997
- uniqueExtractedKeys = removeDuplicatesFromArray(extractedKeys); // Track stats for reporting
998
- stats = {
999
- total: 0,
1000
- removed: 0
1001
- }; // Process each namespace and locale
1002
- _iterator2 = _createForOfIteratorHelperLoose(namespaces);
1003
- case 10:
1004
- if ((_step2 = _iterator2()).done) {
1005
- _context.next = 37;
1006
- break;
1007
- }
1008
- namespace = _step2.value;
1009
- // Build a set of pure keys that are actually used in the codebase for this namespace
1010
- usedKeysSet = new Set();
1011
- for (_iterator3 = _createForOfIteratorHelperLoose(uniqueExtractedKeys); !(_step3 = _iterator3()).done;) {
1012
- key = _step3.value;
1013
- pureKey = getPureKey(key, namespace, namespace === defaultNamespace);
1014
- if (pureKey) {
1015
- usedKeysSet.add(pureKey);
1016
- }
1017
- }
1018
- // Process each locale
1019
- _iterator4 = _createForOfIteratorHelperLoose(locales);
1020
- case 15:
1021
- if ((_step4 = _iterator4()).done) {
1022
- _context.next = 35;
1023
- break;
1024
- }
1025
- locale = _step4.value;
1026
- _context.next = 19;
1027
- return loadLocalesFile(loadPath, locale, namespace);
1028
- case 19:
1029
- existingKeys = _context.sent;
1030
- existingKeysCount = Object.keys(existingKeys).length;
1031
- stats.total += existingKeysCount;
1032
- // Create a new object with only the keys that are used
1033
- cleanedKeys = {};
1034
- removedCount = 0;
1035
- for (_i = 0, _Object$entries = Object.entries(existingKeys); _i < _Object$entries.length; _i++) {
1036
- _Object$entries$_i = _Object$entries[_i], _key = _Object$entries$_i[0], value = _Object$entries$_i[1];
1037
- if (usedKeysSet.has(_key)) {
1038
- cleanedKeys[_key] = value;
1039
- } else {
1040
- removedCount++;
1041
- }
1042
- }
1043
- stats.removed += removedCount;
1044
- // Only write the file if keys were removed
1045
- if (!(removedCount > 0)) {
1046
- _context.next = 32;
1047
- break;
1048
- }
1049
- _context.next = 29;
1050
- return writeLocalesFile(savePath, locale, namespace, cleanedKeys);
1051
- case 29:
1052
- console.log("\u2713 Removed " + removedCount + " unused keys from " + locale + ":" + namespace + " (" + Object.keys(cleanedKeys).length + " keys remaining)");
1053
- _context.next = 33;
1054
- break;
1055
- case 32:
1056
- console.log("No unused keys found in " + locale + ":" + namespace);
1057
- case 33:
1058
- _context.next = 15;
1059
- break;
1060
- case 35:
1061
- _context.next = 10;
1062
- break;
1063
- case 37:
1064
- if (stats.removed > 0) {
1065
- console.log("\u2705 Removed " + stats.removed + " unused keys (out of " + stats.total + " total keys)");
1066
- } else {
1067
- console.log("\u2705 No unused keys found in the project (" + stats.total + " total keys)");
1068
- }
1069
- case 38:
1070
- case "end":
1071
- return _context.stop();
1072
- }
1073
- }, _callee);
1074
- }));
1075
- return function removeUnusedKeys(_x) {
1076
- return _ref.apply(this, arguments);
1077
- };
1078
- }();
1079
-
1080
- var createPrunedNamespace = /*#__PURE__*/function () {
1081
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
1082
- var namespaces, loadPath, savePath, locales, defaultNamespace, sourceNamespaceResponse, sourceNamespace, newNamespaceResponse, newNamespace, globPatternsResponse, selectedGlobPatterns, parser, files, extractedKeys, _iterator, _step, file, content, uniqueExtractedKeys, relevantKeys, _iterator2, _step2, key, pureKey, _iterator3, _step3, locale, sourceTranslations, newNamespaceTranslations, _iterator4, _step4, _key;
1083
- return _regeneratorRuntime().wrap(function _callee$(_context) {
1084
- while (1) switch (_context.prev = _context.next) {
1085
- case 0:
1086
- namespaces = config.namespaces, loadPath = config.loadPath, savePath = config.savePath, locales = config.locales, defaultNamespace = config.defaultNamespace; // Step 1: Ask for source namespace
1087
- _context.next = 3;
1088
- return prompts({
1089
- type: "select",
1090
- name: "value",
1091
- message: "Select source namespace to create pruned version from:",
1092
- choices: namespaces.map(function (namespace) {
1093
- return {
1094
- title: namespace,
1095
- value: namespace
1096
- };
1097
- }),
1098
- onState: function onState(state) {
1099
- if (state.aborted) {
1100
- process.nextTick(function () {
1101
- process.exit(0);
1102
- });
1103
- }
1104
- }
1105
- });
1106
- case 3:
1107
- sourceNamespaceResponse = _context.sent;
1108
- sourceNamespace = sourceNamespaceResponse.value; // Step 2: Ask for new namespace name
1109
- _context.next = 7;
1110
- return prompts({
1111
- type: "text",
1112
- name: "value",
1113
- message: "Enter the name for the new namespace:",
1114
- validate: function validate(value) {
1115
- if (!value) return "Namespace name cannot be empty";
1116
- if (namespaces.includes(value)) return "Namespace already exists";
1117
- return true;
1118
- },
1119
- onState: function onState(state) {
1120
- if (state.aborted) {
1121
- process.nextTick(function () {
1122
- process.exit(0);
1123
- });
1124
- }
1125
- }
1126
- });
1127
- case 7:
1128
- newNamespaceResponse = _context.sent;
1129
- newNamespace = newNamespaceResponse.value; // Step 3: Ask for glob patterns to find relevant keys
1130
- _context.next = 11;
1131
- return prompts({
1132
- type: "list",
1133
- name: "value",
1134
- message: "Enter glob patterns to find relevant keys (comma separated):",
1135
- initial: config.globPatterns.join(","),
1136
- separator: ",",
1137
- onState: function onState(state) {
1138
- if (state.aborted) {
1139
- process.nextTick(function () {
1140
- process.exit(0);
1141
- });
1142
- }
1143
- }
1144
- });
1145
- case 11:
1146
- globPatternsResponse = _context.sent;
1147
- selectedGlobPatterns = globPatternsResponse.value;
1148
- console.log("Finding keys used in files matching: " + selectedGlobPatterns.join(", "));
1149
- // Extract keys from files matching the glob patterns
1150
- parser = new i18nextScanner.Parser({
1151
- nsSeparator: false,
1152
- keySeparator: false
1153
- });
1154
- _context.next = 17;
1155
- return glob([].concat(selectedGlobPatterns, ["!**/node_modules/**"]));
1156
- case 17:
1157
- files = _context.sent;
1158
- console.log("Found " + files.length + " files to scan");
1159
- extractedKeys = [];
1160
- for (_iterator = _createForOfIteratorHelperLoose(files); !(_step = _iterator()).done;) {
1161
- file = _step.value;
1162
- content = fs.readFileSync(file, "utf-8");
1163
- parser.parseFuncFromString(content, {
1164
- list: ["t"]
1165
- }, function (key) {
1166
- extractedKeys.push(key);
1167
- });
1168
- }
1169
- uniqueExtractedKeys = removeDuplicatesFromArray(extractedKeys);
1170
- console.log("Found " + uniqueExtractedKeys.length + " unique translation keys");
1171
- // Filter keys that belong to the source namespace
1172
- relevantKeys = [];
1173
- for (_iterator2 = _createForOfIteratorHelperLoose(uniqueExtractedKeys); !(_step2 = _iterator2()).done;) {
1174
- key = _step2.value;
1175
- pureKey = getPureKey(key, sourceNamespace, sourceNamespace === defaultNamespace);
1176
- if (pureKey) {
1177
- relevantKeys.push(pureKey);
1178
- }
1179
- }
1180
- console.log("Found " + relevantKeys.length + " keys from namespace '" + sourceNamespace + "'");
1181
- if (!(relevantKeys.length === 0)) {
1182
- _context.next = 29;
1183
- break;
1184
- }
1185
- console.log("No relevant keys found. Exiting...");
1186
- return _context.abrupt("return");
1187
- case 29:
1188
- _iterator3 = _createForOfIteratorHelperLoose(locales);
1189
- case 30:
1190
- if ((_step3 = _iterator3()).done) {
1191
- _context.next = 48;
1192
- break;
1193
- }
1194
- locale = _step3.value;
1195
- _context.prev = 32;
1196
- _context.next = 35;
1197
- return loadLocalesFile(loadPath, locale, sourceNamespace);
1198
- case 35:
1199
- sourceTranslations = _context.sent;
1200
- // Create new namespace with only the keys used in the glob pattern files
1201
- newNamespaceTranslations = {};
1202
- for (_iterator4 = _createForOfIteratorHelperLoose(relevantKeys); !(_step4 = _iterator4()).done;) {
1203
- _key = _step4.value;
1204
- if (sourceTranslations[_key]) {
1205
- newNamespaceTranslations[_key] = sourceTranslations[_key];
1206
- }
1207
- }
1208
- // Write the new namespace file
1209
- _context.next = 40;
1210
- return writeLocalesFile(savePath, locale, newNamespace, newNamespaceTranslations);
1211
- case 40:
1212
- console.log("Created pruned namespace '" + newNamespace + "' for locale '" + locale + "' with " + Object.keys(newNamespaceTranslations).length + " keys");
1213
- _context.next = 46;
1214
- break;
1215
- case 43:
1216
- _context.prev = 43;
1217
- _context.t0 = _context["catch"](32);
1218
- console.error("Error creating pruned namespace for locale '" + locale + "':", _context.t0);
1219
- case 46:
1220
- _context.next = 30;
1221
- break;
1222
- case 48:
1223
- console.log("\u2705 Successfully created pruned namespace '" + newNamespace + "'");
1224
- case 49:
1225
- case "end":
1226
- return _context.stop();
1227
- }
1228
- }, _callee, null, [[32, 43]]);
1229
- }));
1230
- return function createPrunedNamespace(_x) {
1231
- return _ref.apply(this, arguments);
1232
- };
1233
- }();
1234
-
1235
- var createPrunedNamespaceAutomated = /*#__PURE__*/function () {
1236
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config, options) {
1237
- var namespaces, loadPath, savePath, locales, defaultNamespace, sourceNamespace, newNamespace, globPatterns, parser, files, extractedKeys, _iterator, _step, file, content, uniqueExtractedKeys, relevantKeys, _iterator2, _step2, key, pureKey, results, _iterator3, _step3, locale, sourceTranslations, newNamespaceTranslations, _iterator4, _step4, _key, keyCount;
1238
- return _regeneratorRuntime().wrap(function _callee$(_context) {
1239
- while (1) switch (_context.prev = _context.next) {
1240
- case 0:
1241
- namespaces = config.namespaces, loadPath = config.loadPath, savePath = config.savePath, locales = config.locales, defaultNamespace = config.defaultNamespace;
1242
- sourceNamespace = options.sourceNamespace, newNamespace = options.newNamespace, globPatterns = options.globPatterns; // Validate inputs
1243
- if (namespaces.includes(sourceNamespace)) {
1244
- _context.next = 4;
1245
- break;
1246
- }
1247
- throw new Error("Source namespace '" + sourceNamespace + "' not found in configuration");
1248
- case 4:
1249
- if (!namespaces.includes(newNamespace)) {
1250
- _context.next = 6;
1251
- break;
1252
- }
1253
- throw new Error("Namespace '" + newNamespace + "' already exists");
1254
- case 6:
1255
- console.log("Creating pruned namespace '" + newNamespace + "' from '" + sourceNamespace + "'");
1256
- console.log("Using glob patterns: " + globPatterns.join(", "));
1257
- // Extract keys from files matching the glob patterns
1258
- parser = new i18nextScanner.Parser({
1259
- nsSeparator: false,
1260
- keySeparator: false
1261
- });
1262
- _context.next = 11;
1263
- return glob([].concat(globPatterns, ["!**/node_modules/**"]));
1264
- case 11:
1265
- files = _context.sent;
1266
- console.log("Found " + files.length + " files to scan");
1267
- extractedKeys = [];
1268
- for (_iterator = _createForOfIteratorHelperLoose(files); !(_step = _iterator()).done;) {
1269
- file = _step.value;
1270
- content = fs.readFileSync(file, "utf-8");
1271
- parser.parseFuncFromString(content, {
1272
- list: ["t"]
1273
- }, function (key) {
1274
- extractedKeys.push(key);
1275
- });
1276
- }
1277
- uniqueExtractedKeys = removeDuplicatesFromArray(extractedKeys);
1278
- console.log("Found " + uniqueExtractedKeys.length + " unique translation keys");
1279
- // Filter keys that belong to the source namespace
1280
- relevantKeys = [];
1281
- for (_iterator2 = _createForOfIteratorHelperLoose(uniqueExtractedKeys); !(_step2 = _iterator2()).done;) {
1282
- key = _step2.value;
1283
- pureKey = getPureKey(key, sourceNamespace, sourceNamespace === defaultNamespace);
1284
- if (pureKey) {
1285
- relevantKeys.push(pureKey);
1286
- }
1287
- }
1288
- console.log("Found " + relevantKeys.length + " keys from namespace '" + sourceNamespace + "'");
1289
- if (!(relevantKeys.length === 0)) {
1290
- _context.next = 23;
1291
- break;
1292
- }
1293
- console.log("No relevant keys found. Exiting...");
1294
- return _context.abrupt("return", {
1295
- success: false,
1296
- message: "No relevant keys found",
1297
- keysCount: 0
1298
- });
1299
- case 23:
1300
- // Get translations from source namespace and create new namespace files
1301
- results = [];
1302
- _iterator3 = _createForOfIteratorHelperLoose(locales);
1303
- case 25:
1304
- if ((_step3 = _iterator3()).done) {
1305
- _context.next = 46;
1306
- break;
1307
- }
1308
- locale = _step3.value;
1309
- _context.prev = 27;
1310
- _context.next = 30;
1311
- return loadLocalesFile(loadPath, locale, sourceNamespace);
1312
- case 30:
1313
- sourceTranslations = _context.sent;
1314
- // Create new namespace with only the keys used in the glob pattern files
1315
- newNamespaceTranslations = {};
1316
- for (_iterator4 = _createForOfIteratorHelperLoose(relevantKeys); !(_step4 = _iterator4()).done;) {
1317
- _key = _step4.value;
1318
- if (sourceTranslations[_key]) {
1319
- newNamespaceTranslations[_key] = sourceTranslations[_key];
1320
- }
1321
- }
1322
- // Write the new namespace file
1323
- _context.next = 35;
1324
- return writeLocalesFile(savePath, locale, newNamespace, newNamespaceTranslations);
1325
- case 35:
1326
- keyCount = Object.keys(newNamespaceTranslations).length;
1327
- console.log("Created pruned namespace '" + newNamespace + "' for locale '" + locale + "' with " + keyCount + " keys");
1328
- results.push({
1329
- locale: locale,
1330
- keyCount: keyCount,
1331
- success: true
1332
- });
1333
- _context.next = 44;
1334
- break;
1335
- case 40:
1336
- _context.prev = 40;
1337
- _context.t0 = _context["catch"](27);
1338
- console.error("Error creating pruned namespace for locale '" + locale + "':", _context.t0);
1339
- results.push({
1340
- locale: locale,
1341
- keyCount: 0,
1342
- success: false,
1343
- error: _context.t0 instanceof Error ? _context.t0.message : String(_context.t0)
1344
- });
1345
- case 44:
1346
- _context.next = 25;
1347
- break;
1348
- case 46:
1349
- console.log("\u2705 Successfully created pruned namespace '" + newNamespace + "'");
1350
- return _context.abrupt("return", {
1351
- success: true,
1352
- message: "Created pruned namespace '" + newNamespace + "' with " + relevantKeys.length + " keys",
1353
- keysCount: relevantKeys.length,
1354
- results: results
1355
- });
1356
- case 48:
1357
- case "end":
1358
- return _context.stop();
1359
- }
1360
- }, _callee, null, [[27, 40]]);
1361
- }));
1362
- return function createPrunedNamespaceAutomated(_x, _x2) {
1363
- return _ref.apply(this, arguments);
1364
- };
1365
- }();
1366
-
1367
- var getKeyToReplace = /*#__PURE__*/function () {
1368
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(keys) {
1369
- var keyToReplace;
1370
- return _regeneratorRuntime().wrap(function _callee$(_context) {
1371
- while (1) switch (_context.prev = _context.next) {
1372
- case 0:
1373
- _context.next = 2;
1374
- return getTextInput("Enter the key to replace the translation for: ");
1375
- case 2:
1376
- keyToReplace = _context.sent;
1377
- if (keys[keyToReplace]) {
1378
- _context.next = 8;
1379
- break;
1380
- }
1381
- console.log("The key \"" + keyToReplace + "\" does not exist.");
1382
- _context.next = 7;
1383
- return getKeyToReplace(keys);
1384
- case 7:
1385
- return _context.abrupt("return", _context.sent);
1386
- case 8:
1387
- console.log("The key \"" + keyToReplace + "\" exists.");
1388
- return _context.abrupt("return", keyToReplace);
1389
- case 10:
1390
- case "end":
1391
- return _context.stop();
1392
- }
1393
- }, _callee);
1394
- }));
1395
- return function getKeyToReplace(_x) {
1396
- return _ref.apply(this, arguments);
1397
- };
1398
- }();
1399
- var replaceTranslation = /*#__PURE__*/function () {
1400
- var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(config, key) {
1401
- var loadPath, savePath, defaultLocale, defaultNamespace, locales, context, openai, keys, keyToReplace, newTranslation, _iterator, _step, locale, newValue, _object, translation, existingKeys;
1402
- return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1403
- while (1) switch (_context2.prev = _context2.next) {
1404
- case 0:
1405
- loadPath = config.loadPath, savePath = config.savePath, defaultLocale = config.defaultLocale, defaultNamespace = config.defaultNamespace, locales = config.locales, context = config.context, openai = config.openai;
1406
- _context2.next = 3;
1407
- return loadLocalesFile(config.loadPath, config.defaultLocale, config.defaultNamespace);
1408
- case 3:
1409
- keys = _context2.sent;
1410
- if (!key) {
1411
- _context2.next = 16;
1412
- break;
1413
- }
1414
- if (!keys[key]) {
1415
- _context2.next = 10;
1416
- break;
1417
- }
1418
- keyToReplace = key;
1419
- console.log("The key \"" + keyToReplace + "\" exists.");
1420
- _context2.next = 14;
1421
- break;
1422
- case 10:
1423
- console.log("The key \"" + key + "\" does not exist.");
1424
- _context2.next = 13;
1425
- return getKeyToReplace(keys);
1426
- case 13:
1427
- keyToReplace = _context2.sent;
1428
- case 14:
1429
- _context2.next = 19;
1430
- break;
1431
- case 16:
1432
- _context2.next = 18;
1433
- return getKeyToReplace(keys);
1434
- case 18:
1435
- keyToReplace = _context2.sent;
1436
- case 19:
1437
- console.log("The current translation in " + defaultLocale + " for \"" + keyToReplace + "\" is \"" + keys[keyToReplace] + "\".");
1438
- _context2.next = 22;
1439
- return getTextInput("Enter the new translation: ");
1440
- case 22:
1441
- newTranslation = _context2.sent;
1442
- _iterator = _createForOfIteratorHelperLoose(locales);
1443
- case 24:
1444
- if ((_step = _iterator()).done) {
1445
- _context2.next = 43;
1446
- break;
1447
- }
1448
- locale = _step.value;
1449
- newValue = "";
1450
- if (!(locale === defaultLocale)) {
1451
- _context2.next = 31;
1452
- break;
1453
- }
1454
- newValue = newTranslation;
1455
- _context2.next = 35;
1456
- break;
1457
- case 31:
1458
- _context2.next = 33;
1459
- return translateKey({
1460
- context: context,
1461
- inputLanguage: defaultLocale,
1462
- outputLanguage: locale,
1463
- object: (_object = {}, _object[keyToReplace] = newTranslation, _object),
1464
- openai: openai,
1465
- model: config.model
1466
- });
1467
- case 33:
1468
- translation = _context2.sent;
1469
- newValue = translation[keyToReplace];
1470
- case 35:
1471
- _context2.next = 37;
1472
- return loadLocalesFile(loadPath, locale, defaultNamespace);
1473
- case 37:
1474
- existingKeys = _context2.sent;
1475
- existingKeys[keyToReplace] = newValue;
1476
- writeLocalesFile(savePath, locale, defaultNamespace, existingKeys);
1477
- console.log("The new translation for \"" + keyToReplace + "\" in " + locale + " is \"" + newValue + "\".");
1478
- case 41:
1479
- _context2.next = 24;
1480
- break;
1481
- case 43:
1482
- case "end":
1483
- return _context2.stop();
1484
- }
1485
- }, _callee2);
1486
- }));
1487
- return function replaceTranslation(_x2, _x3) {
1488
- return _ref2.apply(this, arguments);
1489
- };
1490
- }();
1491
-
1492
- var translateMissing = /*#__PURE__*/function () {
1493
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
1494
- var loadPath, savePath, defaultLocale, namespaces, locales, context, openai, disableTranslation, autoClear, newKeys, newKeysWithDefaultLocale, _iterator, _step, newKey, answer, newKeysObject, allLocales, _iterator2, _step2, locale, translatedValues, _loop, _iterator3, _step3;
1495
- return _regeneratorRuntime().wrap(function _callee$(_context2) {
1496
- while (1) switch (_context2.prev = _context2.next) {
1497
- case 0:
1498
- loadPath = config.loadPath, savePath = config.savePath, defaultLocale = config.defaultLocale, namespaces = config.namespaces, locales = config.locales, context = config.context, openai = config.openai, disableTranslation = config.disableTranslation, autoClear = config.autoClear; // Run clean command first if autoClear is enabled
1499
- if (!autoClear) {
1500
- _context2.next = 6;
1501
- break;
1502
- }
1503
- console$1.log("🧹 Auto-clearing unused translations before scanning...");
1504
- _context2.next = 5;
1505
- return removeUnusedKeys(config);
1506
- case 5:
1507
- console$1.log("✅ Auto-clear completed. Now scanning for missing translations...\n");
1508
- case 6:
1509
- _context2.next = 8;
1510
- return getMissingKeys(config);
1511
- case 8:
1512
- newKeys = _context2.sent;
1513
- if (!(newKeys.length === 0)) {
1514
- _context2.next = 14;
1515
- break;
1516
- }
1517
- console$1.log("No new keys found.");
1518
- _context2.next = 13;
1519
- return checkAllKeysExist(config);
1520
- case 13:
1521
- return _context2.abrupt("return");
1522
- case 14:
1523
- console$1.log(newKeys.length + " keys are missing. Please provide the values for the following keys in " + defaultLocale + ":");
1524
- newKeysWithDefaultLocale = [];
1525
- _iterator = _createForOfIteratorHelperLoose(newKeys);
1526
- case 17:
1527
- if ((_step = _iterator()).done) {
1528
- _context2.next = 25;
1529
- break;
1530
- }
1531
- newKey = _step.value;
1532
- _context2.next = 21;
1533
- return getTextInput(newKey.key);
1534
- case 21:
1535
- answer = _context2.sent;
1536
- newKeysWithDefaultLocale.push({
1537
- key: newKey.key,
1538
- namespace: newKey.namespace,
1539
- value: answer
1540
- });
1541
- case 23:
1542
- _context2.next = 17;
1543
- break;
1544
- case 25:
1545
- newKeysObject = newKeysWithDefaultLocale.reduce(function (prev, next) {
1546
- prev[next.key] = next.value;
1547
- return prev;
1548
- }, {});
1549
- allLocales = disableTranslation ? [defaultLocale] : locales;
1550
- _iterator2 = _createForOfIteratorHelperLoose(allLocales);
1551
- case 28:
1552
- if ((_step2 = _iterator2()).done) {
1553
- _context2.next = 48;
1554
- break;
1555
- }
1556
- locale = _step2.value;
1557
- translatedValues = {};
1558
- if (!(locale === defaultLocale)) {
1559
- _context2.next = 35;
1560
- break;
1561
- }
1562
- translatedValues = newKeysObject;
1563
- _context2.next = 38;
1564
- break;
1565
- case 35:
1566
- _context2.next = 37;
1567
- return translateKey({
1568
- inputLanguage: defaultLocale,
1569
- outputLanguage: locale,
1570
- context: context,
1571
- object: newKeysObject,
1572
- openai: openai,
1573
- model: config.model
1574
- });
1575
- case 37:
1576
- translatedValues = _context2.sent;
1577
- case 38:
1578
- _loop = /*#__PURE__*/_regeneratorRuntime().mark(function _loop() {
1579
- var namespace, existingKeys, relevantKeys, _iterator4, _step4, key;
1580
- return _regeneratorRuntime().wrap(function _loop$(_context) {
1581
- while (1) switch (_context.prev = _context.next) {
1582
- case 0:
1583
- namespace = _step3.value;
1584
- _context.next = 3;
1585
- return loadLocalesFile(loadPath, locale, namespace);
1586
- case 3:
1587
- existingKeys = _context.sent;
1588
- relevantKeys = newKeysWithDefaultLocale.filter(function (key) {
1589
- return key.namespace === namespace;
1590
- });
1591
- if (!(relevantKeys.length === 0)) {
1592
- _context.next = 7;
1593
- break;
1594
- }
1595
- return _context.abrupt("return", 1);
1596
- case 7:
1597
- for (_iterator4 = _createForOfIteratorHelperLoose(relevantKeys); !(_step4 = _iterator4()).done;) {
1598
- key = _step4.value;
1599
- existingKeys[key.key] = translatedValues[key.key];
1600
- }
1601
- writeLocalesFile(savePath, locale, namespace, existingKeys);
1602
- case 9:
1603
- case "end":
1604
- return _context.stop();
1605
- }
1606
- }, _loop);
1607
- });
1608
- _iterator3 = _createForOfIteratorHelperLoose(namespaces);
1609
- case 40:
1610
- if ((_step3 = _iterator3()).done) {
1611
- _context2.next = 46;
1612
- break;
1613
- }
1614
- return _context2.delegateYield(_loop(), "t0", 42);
1615
- case 42:
1616
- if (!_context2.t0) {
1617
- _context2.next = 44;
1618
- break;
1619
- }
1620
- return _context2.abrupt("continue", 44);
1621
- case 44:
1622
- _context2.next = 40;
1623
- break;
1624
- case 46:
1625
- _context2.next = 28;
1626
- break;
1627
- case 48:
1628
- _context2.next = 50;
1629
- return checkAllKeysExist(config);
1630
- case 50:
1631
- console$1.log("Successfully translated " + newKeys.length + " keys.");
1632
- case 51:
1633
- case "end":
1634
- return _context2.stop();
1635
- }
1636
- }, _callee);
1637
- }));
1638
- return function translateMissing(_x) {
1639
- return _ref.apply(this, arguments);
1640
- };
1641
- }();
1642
-
1643
- var syncLocales = /*#__PURE__*/function () {
1644
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(config) {
1645
- var loadPath, savePath, defaultLocale, namespaces, locales, context, openai, _iterator, _step, namespace, defaultLocaleKeys, _iterator2, _step2, locale, localeKeys, missingKeys, _i, _Object$entries, _Object$entries$_i, key, value, translatedValues, updatedLocaleKeys;
1646
- return _regeneratorRuntime().wrap(function _callee$(_context) {
1647
- while (1) switch (_context.prev = _context.next) {
1648
- case 0:
1649
- loadPath = config.loadPath, savePath = config.savePath, defaultLocale = config.defaultLocale, namespaces = config.namespaces, locales = config.locales, context = config.context, openai = config.openai;
1650
- _context.prev = 1;
1651
- _iterator = _createForOfIteratorHelperLoose(namespaces);
1652
- case 3:
1653
- if ((_step = _iterator()).done) {
1654
- _context.next = 62;
1655
- break;
1656
- }
1657
- namespace = _step.value;
1658
- defaultLocaleKeys = void 0;
1659
- _context.prev = 6;
1660
- _context.next = 9;
1661
- return loadLocalesFile(loadPath, defaultLocale, namespace);
1662
- case 9:
1663
- defaultLocaleKeys = _context.sent;
1664
- _context.next = 15;
1665
- break;
1666
- case 12:
1667
- _context.prev = 12;
1668
- _context.t0 = _context["catch"](6);
1669
- throw new TranslationError("Failed to load default locale file for namespace \"" + namespace + "\"", defaultLocale, namespace, _context.t0 instanceof Error ? _context.t0 : undefined);
1670
- case 15:
1671
- _iterator2 = _createForOfIteratorHelperLoose(locales);
1672
- case 16:
1673
- if ((_step2 = _iterator2()).done) {
1674
- _context.next = 60;
1675
- break;
1676
- }
1677
- locale = _step2.value;
1678
- if (!(locale === defaultLocale)) {
1679
- _context.next = 20;
1680
- break;
1681
- }
1682
- return _context.abrupt("continue", 58);
1683
- case 20:
1684
- localeKeys = void 0;
1685
- _context.prev = 21;
1686
- _context.next = 24;
1687
- return loadLocalesFile(loadPath, locale, namespace);
1688
- case 24:
1689
- localeKeys = _context.sent;
1690
- _context.next = 31;
1691
- break;
1692
- case 27:
1693
- _context.prev = 27;
1694
- _context.t1 = _context["catch"](21);
1695
- console.warn("Warning: Could not load locale file for " + locale + " (namespace: " + namespace + "). Creating new file.");
1696
- localeKeys = {};
1697
- case 31:
1698
- missingKeys = {}; // Check which keys from default locale are missing in current locale
1699
- for (_i = 0, _Object$entries = Object.entries(defaultLocaleKeys); _i < _Object$entries.length; _i++) {
1700
- _Object$entries$_i = _Object$entries[_i], key = _Object$entries$_i[0], value = _Object$entries$_i[1];
1701
- if (!localeKeys[key]) {
1702
- missingKeys[key] = value;
1703
- }
1704
- }
1705
- // If there are missing keys, translate them
1706
- if (!(Object.keys(missingKeys).length > 0)) {
1707
- _context.next = 57;
1708
- break;
1709
- }
1710
- console.log("Found " + Object.keys(missingKeys).length + " missing keys in " + locale + " (namespace: " + namespace + ")");
1711
- translatedValues = void 0;
1712
- _context.prev = 36;
1713
- _context.next = 39;
1714
- return translateKey({
1715
- inputLanguage: defaultLocale,
1716
- outputLanguage: locale,
1717
- context: context,
1718
- object: missingKeys,
1719
- openai: openai,
1720
- model: config.model
1721
- });
1722
- case 39:
1723
- translatedValues = _context.sent;
1724
- _context.next = 45;
1725
- break;
1726
- case 42:
1727
- _context.prev = 42;
1728
- _context.t2 = _context["catch"](36);
1729
- throw new TranslationError("Failed to translate keys for locale \"" + locale + "\" (namespace: " + namespace + ")", locale, namespace, _context.t2 instanceof Error ? _context.t2 : undefined);
1730
- case 45:
1731
- // Merge translated values with existing ones
1732
- updatedLocaleKeys = _extends({}, localeKeys, translatedValues);
1733
- _context.prev = 46;
1734
- _context.next = 49;
1735
- return writeLocalesFile(savePath, locale, namespace, updatedLocaleKeys);
1736
- case 49:
1737
- _context.next = 54;
1738
- break;
1739
- case 51:
1740
- _context.prev = 51;
1741
- _context.t3 = _context["catch"](46);
1742
- throw new TranslationError("Failed to save translations for locale \"" + locale + "\" (namespace: " + namespace + ")", locale, namespace, _context.t3 instanceof Error ? _context.t3 : undefined);
1743
- case 54:
1744
- console.log("Successfully translated and saved " + Object.keys(missingKeys).length + " keys for " + locale + " (namespace: " + namespace + ")");
1745
- _context.next = 58;
1746
- break;
1747
- case 57:
1748
- console.log("No missing keys found for " + locale + " (namespace: " + namespace + ")");
1749
- case 58:
1750
- _context.next = 16;
1751
- break;
1752
- case 60:
1753
- _context.next = 3;
1754
- break;
1755
- case 62:
1756
- _context.next = 69;
1757
- break;
1758
- case 64:
1759
- _context.prev = 64;
1760
- _context.t4 = _context["catch"](1);
1761
- if (!(_context.t4 instanceof TranslationError)) {
1762
- _context.next = 68;
1763
- break;
1764
- }
1765
- throw _context.t4;
1766
- case 68:
1767
- throw new TranslationError("An unexpected error occurred during translation", undefined, undefined, _context.t4 instanceof Error ? _context.t4 : undefined);
1768
- case 69:
1769
- case "end":
1770
- return _context.stop();
1771
- }
1772
- }, _callee, null, [[1, 64], [6, 12], [21, 27], [36, 42], [46, 51]]);
1773
- }));
1774
- return function syncLocales(_x) {
1775
- return _ref.apply(this, arguments);
1776
- };
1777
- }();
1778
-
1779
- exports.checkMissing = checkMissing;
1780
- exports.createPrunedNamespace = createPrunedNamespace;
1781
- exports.createPrunedNamespaceAutomated = createPrunedNamespaceAutomated;
1782
- exports.loadConfig = loadConfig;
1783
- exports.removeUnusedKeys = removeUnusedKeys;
1784
- exports.replaceTranslation = replaceTranslation;
1785
- exports.syncLocales = syncLocales;
1786
- exports.translateMissing = translateMissing;
1787
- //# sourceMappingURL=i18n-magic.cjs.development.js.map