@lingual/i18n-check 0.7.4 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin/index.js CHANGED
@@ -203,7 +203,7 @@ const printTranslationResult = ({ missingKeys, invalidKeys, }) => {
203
203
  console.log(chalk_1.default.red((0, errorReporters_1.summaryReporter)(getSummaryRows(invalidKeys))));
204
204
  }
205
205
  else {
206
- console.log(chalk_1.default.red((0, errorReporters_1.standardReporter)(getStandardRows(invalidKeys))));
206
+ console.log(chalk_1.default.red((0, errorReporters_1.standardReporter)(getStandardRows(invalidKeys), true)));
207
207
  }
208
208
  }
209
209
  else if (invalidKeys) {
@@ -242,7 +242,7 @@ const printUndefinedKeysResult = ({ undefinedKeys, }) => {
242
242
  console.log(chalk_1.default.green("\nNo undefined keys found!"));
243
243
  }
244
244
  };
245
- const truncate = (chars) => chars.length > 80 ? `${chars.substring(0, 80)}...` : chars;
245
+ const truncate = (chars, len = 80) => chars.length > 80 ? `${chars.substring(0, len)}...` : chars;
246
246
  const getSummaryRows = (checkResult) => {
247
247
  const formattedRows = [];
248
248
  for (const [file, keys] of Object.entries(checkResult)) {
@@ -256,11 +256,20 @@ const getSummaryRows = (checkResult) => {
256
256
  const getStandardRows = (checkResult) => {
257
257
  const formattedRows = [];
258
258
  for (const [file, keys] of Object.entries(checkResult)) {
259
- for (const key of keys) {
260
- formattedRows.push({
261
- file: truncate(file),
262
- key: truncate(key),
263
- });
259
+ for (const entry of keys) {
260
+ if (typeof entry === "object") {
261
+ formattedRows.push({
262
+ file: truncate(file),
263
+ key: truncate(entry.key),
264
+ msg: truncate(entry.msg, 120),
265
+ });
266
+ }
267
+ else {
268
+ formattedRows.push({
269
+ file: truncate(file),
270
+ key: truncate(entry),
271
+ });
272
+ }
264
273
  }
265
274
  }
266
275
  return formattedRows;
@@ -37,11 +37,13 @@ Found missing keys!
37
37
  └───────────────────────────────────────────────┴───────────────────────┘
38
38
 
39
39
  Found invalid keys!
40
- ┌───────────────────────────────────────────────┬──────────────────┐
41
- file key
42
- ├───────────────────────────────────────────────┼──────────────────┤
43
- │ translations/folderExample/de-DE/index.json message.select │
44
- └───────────────────────────────────────────────┴──────────────────┘
40
+ ┌────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
41
+ info result
42
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
43
+ file │ translations/folderExample/de-DE/index.json
44
+ │ key │ message.select │
45
+ │ msg │ Expected element of type "select" but received "argument", Unexpected date element, Unexpected date element... │
46
+ └────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
45
47
 
46
48
  `);
47
49
  done();
@@ -62,12 +64,17 @@ Found missing keys!
62
64
  └──────────────────────────────────────────────────────────┴───────────────────────┘
63
65
 
64
66
  Found invalid keys!
65
- ┌────────────────────────────────────────────────────────────┬─────────────────────┐
66
- file key
67
- ├────────────────────────────────────────────────────────────┼─────────────────────┤
68
- │ translations/multipleFilesFolderExample/de-DE/one.json message.select │
69
- translations/multipleFilesFolderExample/de-DE/three.json multipleVariables
70
- └────────────────────────────────────────────────────────────┴─────────────────────┘
67
+ ┌────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
68
+ info result
69
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
70
+ file │ translations/multipleFilesFolderExample/de-DE/one.json
71
+ key message.select
72
+ │ msg │ Expected element of type "select" but received "argument", Unexpected date element, Unexpected date element... │
73
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
74
+ │ file │ translations/multipleFilesFolderExample/de-DE/three.json │
75
+ │ key │ multipleVariables │
76
+ │ msg │ Expected argument to contain "user" but received "name" │
77
+ └────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
71
78
 
72
79
  `);
73
80
  done();
@@ -90,14 +97,25 @@ Found missing keys!
90
97
  └───────────────────────────────────────────────────────────────────────┴───────────────────────┘
91
98
 
92
99
  Found invalid keys!
93
- ┌─────────────────────────────────────────────────────────────────────────┬───────────────────────┐
94
- file key
95
- ├─────────────────────────────────────────────────────────────────────────┼───────────────────────┤
96
- │ translations/multipleFoldersExample/spaceOne/locales/de-DE/one.json message.select │
97
- translations/multipleFoldersExample/spaceOne/locales/de-DE/three.json multipleVariables
98
- translations/multipleFoldersExample/spaceTwo/locales/de-DE/one.json message.text-format
99
- │ translations/multipleFoldersExample/spaceTwo/locales/de-DE/three.json │ numberFormat │
100
- └─────────────────────────────────────────────────────────────────────────┴───────────────────────┘
100
+ ┌────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
101
+ info result
102
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
103
+ file │ translations/multipleFoldersExample/spaceOne/locales/de-DE/one.json
104
+ key message.select
105
+ msg Expected element of type "select" but received "argument", Unexpected date element, Unexpected date element...
106
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
107
+ │ file │ translations/multipleFoldersExample/spaceOne/locales/de-DE/three.json │
108
+ │ key │ multipleVariables │
109
+ │ msg │ Expected argument to contain "user" but received "name" │
110
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
111
+ │ file │ translations/multipleFoldersExample/spaceTwo/locales/de-DE/one.json │
112
+ │ key │ message.text-format │
113
+ │ msg │ Expected element of type "tag" but received "number", Unexpected tag element │
114
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
115
+ │ file │ translations/multipleFoldersExample/spaceTwo/locales/de-DE/three.json │
116
+ │ key │ numberFormat │
117
+ │ msg │ Missing element number │
118
+ └────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
101
119
 
102
120
  `);
103
121
  done();
@@ -120,14 +138,25 @@ Found missing keys!
120
138
  └───────────────────────────────────────────────────────────────────────┴───────────────────────┘
121
139
 
122
140
  Found invalid keys!
123
- ┌─────────────────────────────────────────────────────────────────────────┬───────────────────────┐
124
- file key
125
- ├─────────────────────────────────────────────────────────────────────────┼───────────────────────┤
126
- │ translations/multipleFoldersExample/spaceOne/locales/de-DE/one.json message.select │
127
- translations/multipleFoldersExample/spaceOne/locales/de-DE/three.json multipleVariables
128
- translations/multipleFoldersExample/spaceTwo/locales/de-DE/one.json message.text-format
129
- │ translations/multipleFoldersExample/spaceTwo/locales/de-DE/three.json │ numberFormat │
130
- └─────────────────────────────────────────────────────────────────────────┴───────────────────────┘
141
+ ┌────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
142
+ info result
143
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
144
+ file │ translations/multipleFoldersExample/spaceOne/locales/de-DE/one.json
145
+ key message.select
146
+ msg Expected element of type "select" but received "argument", Unexpected date element, Unexpected date element...
147
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
148
+ │ file │ translations/multipleFoldersExample/spaceOne/locales/de-DE/three.json │
149
+ │ key │ multipleVariables │
150
+ │ msg │ Expected argument to contain "user" but received "name" │
151
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
152
+ │ file │ translations/multipleFoldersExample/spaceTwo/locales/de-DE/one.json │
153
+ │ key │ message.text-format │
154
+ │ msg │ Expected element of type "tag" but received "number", Unexpected tag element │
155
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
156
+ │ file │ translations/multipleFoldersExample/spaceTwo/locales/de-DE/three.json │
157
+ │ key │ numberFormat │
158
+ │ msg │ Missing element number │
159
+ └────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
131
160
 
132
161
  `);
133
162
  done();
@@ -154,11 +183,13 @@ Found missing keys!
154
183
  └───────────────────────────────────────────┴────────────────────────────────┘
155
184
 
156
185
  Found invalid keys!
157
- ┌───────────────────────────────────────────┬─────────────────────┐
158
- file key
159
- ├───────────────────────────────────────────┼─────────────────────┤
160
- │ translations/messageExamples/de-de.json │ multipleVariables │
161
- └───────────────────────────────────────────┴─────────────────────┘
186
+ ┌────────┬───────────────────────────────────────────┐
187
+ info result
188
+ ├────────┼───────────────────────────────────────────┤
189
+ file │ translations/messageExamples/de-de.json │
190
+ │ key │ multipleVariables │
191
+ │ msg │ Unexpected date element │
192
+ └────────┴───────────────────────────────────────────┘
162
193
 
163
194
  `);
164
195
  done();
@@ -181,12 +212,17 @@ Found missing keys!
181
212
  └──────────────────────────────────────────────────────────┴────────────────────────────────┘
182
213
 
183
214
  Found invalid keys!
184
- ┌────────────────────────────────────────────────────────────┬─────────────────────┐
185
- file key
186
- ├────────────────────────────────────────────────────────────┼─────────────────────┤
187
- │ translations/multipleFilesFolderExample/de-DE/one.json message.select │
188
- translations/multipleFilesFolderExample/de-DE/three.json multipleVariables
189
- └────────────────────────────────────────────────────────────┴─────────────────────┘
215
+ ┌────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
216
+ info result
217
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
218
+ file │ translations/multipleFilesFolderExample/de-DE/one.json
219
+ key message.select
220
+ │ msg │ Expected element of type "select" but received "argument", Unexpected date element, Unexpected date element... │
221
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
222
+ │ file │ translations/multipleFilesFolderExample/de-DE/three.json │
223
+ │ key │ multipleVariables │
224
+ │ msg │ Expected argument to contain "user" but received "name" │
225
+ └────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
190
226
 
191
227
  `);
192
228
  done();
@@ -211,11 +247,13 @@ Found missing keys!
211
247
  └───────────────────────────────────────────┴────────────┘
212
248
 
213
249
  Found invalid keys!
214
- ┌───────────────────────────────────────────┬─────────────────────┐
215
- file key
216
- ├───────────────────────────────────────────┼─────────────────────┤
217
- │ translations/messageExamples/de-de.json │ multipleVariables │
218
- └───────────────────────────────────────────┴─────────────────────┘
250
+ ┌────────┬───────────────────────────────────────────┐
251
+ info result
252
+ ├────────┼───────────────────────────────────────────┤
253
+ file │ translations/messageExamples/de-de.json │
254
+ │ key │ multipleVariables │
255
+ │ msg │ Unexpected date element │
256
+ └────────┴───────────────────────────────────────────┘
219
257
 
220
258
  `);
221
259
  done();
@@ -240,11 +278,13 @@ Found missing keys!
240
278
  └───────────────────────────────────────────┴────────────┘
241
279
 
242
280
  Found invalid keys!
243
- ┌───────────────────────────────────────────┬─────────────────────┐
244
- file key
245
- ├───────────────────────────────────────────┼─────────────────────┤
246
- │ translations/messageExamples/de-de.json │ multipleVariables │
247
- └───────────────────────────────────────────┴─────────────────────┘
281
+ ┌────────┬───────────────────────────────────────────┐
282
+ info result
283
+ ├────────┼───────────────────────────────────────────┤
284
+ file │ translations/messageExamples/de-de.json │
285
+ │ key │ multipleVariables │
286
+ │ msg │ Unexpected date element │
287
+ └────────┴───────────────────────────────────────────┘
248
288
 
249
289
  `);
250
290
  done();
@@ -347,17 +387,17 @@ Found undefined keys!
347
387
  ┌──────────────────────────────────────────────────────────────────┬───────────────────┐
348
388
  │ file │ key │
349
389
  ├──────────────────────────────────────────────────────────────────┼───────────────────┤
350
- │ translations/codeExamples/next-intl/src/Basic.tsx │ message.select │
351
- │ translations/codeExamples/next-intl/src/StrictTypesExample.tsx │ unknown.unknown │
352
390
  │ translations/codeExamples/next-intl/src/StrictTypesExample.tsx │ About.unknown │
353
- │ translations/codeExamples/next-intl/src/StrictTypesExample.tsx │ unknown │
354
- │ translations/codeExamples/next-intl/src/StrictTypesExample.tsx │ Test.title │
355
- │ translations/codeExamples/next-intl/src/StrictTypesExample.tsx │ title │
356
- │ translations/codeExamples/next-intl/src/StrictTypesExample.tsx │ unknown.unknown │
357
391
  │ translations/codeExamples/next-intl/src/StrictTypesExample.tsx │ About.unknown │
358
- │ translations/codeExamples/next-intl/src/StrictTypesExample.tsx │ unknown │
359
392
  │ translations/codeExamples/next-intl/src/StrictTypesExample.tsx │ Test.title │
393
+ │ translations/codeExamples/next-intl/src/StrictTypesExample.tsx │ Test.title │
394
+ │ translations/codeExamples/next-intl/src/StrictTypesExample.tsx │ title │
360
395
  │ translations/codeExamples/next-intl/src/StrictTypesExample.tsx │ title │
396
+ │ translations/codeExamples/next-intl/src/StrictTypesExample.tsx │ unknown │
397
+ │ translations/codeExamples/next-intl/src/StrictTypesExample.tsx │ unknown │
398
+ │ translations/codeExamples/next-intl/src/StrictTypesExample.tsx │ unknown.unknown │
399
+ │ translations/codeExamples/next-intl/src/StrictTypesExample.tsx │ unknown.unknown │
400
+ │ translations/codeExamples/next-intl/src/Basic.tsx │ message.select │
361
401
  └──────────────────────────────────────────────────────────────────┴───────────────────┘
362
402
 
363
403
  `);
@@ -400,11 +440,13 @@ Found missing keys!
400
440
  └────────────────────────────────────────────────────┴───────────────────────┘
401
441
 
402
442
  Found invalid keys!
403
- ┌────────────────────────────────────────────────────┬──────────────────┐
404
- file key
405
- ├────────────────────────────────────────────────────┼──────────────────┤
406
- │ translations/yaml/folderExample/de-DE/index.yaml message.select │
407
- └────────────────────────────────────────────────────┴──────────────────┘
443
+ ┌────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
444
+ info result
445
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
446
+ file │ translations/yaml/folderExample/de-DE/index.yaml
447
+ │ key │ message.select │
448
+ │ msg │ Expected element of type "select" but received "argument", Unexpected date element, Unexpected date element... │
449
+ └────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
408
450
 
409
451
  `);
410
452
  done();
@@ -425,12 +467,17 @@ Found missing keys!
425
467
  └───────────────────────────────────────────────────────────────┴───────────────────────┘
426
468
 
427
469
  Found invalid keys!
428
- ┌─────────────────────────────────────────────────────────────────┬─────────────────────┐
429
- file key
430
- ├─────────────────────────────────────────────────────────────────┼─────────────────────┤
431
- │ translations/yaml/multipleFilesFolderExample/de-DE/one.yaml message.select │
432
- translations/yaml/multipleFilesFolderExample/de-DE/three.yaml multipleVariables
433
- └─────────────────────────────────────────────────────────────────┴─────────────────────┘
470
+ ┌────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
471
+ info result
472
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
473
+ file │ translations/yaml/multipleFilesFolderExample/de-DE/one.yaml
474
+ key message.select
475
+ │ msg │ Expected element of type "select" but received "argument", Unexpected date element, Unexpected date element... │
476
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
477
+ │ file │ translations/yaml/multipleFilesFolderExample/de-DE/three.yaml │
478
+ │ key │ multipleVariables │
479
+ │ msg │ Expected argument to contain "user" but received "name" │
480
+ └────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
434
481
 
435
482
  `);
436
483
  done();
@@ -453,14 +500,25 @@ Found missing keys!
453
500
  └────────────────────────────────────────────────────────────────────────────┴───────────────────────┘
454
501
 
455
502
  Found invalid keys!
456
- ┌──────────────────────────────────────────────────────────────────────────────┬───────────────────────┐
457
- file key
458
- ├──────────────────────────────────────────────────────────────────────────────┼───────────────────────┤
459
- │ translations/yaml/multipleFoldersExample/spaceOne/locales/de-DE/one.yaml message.select │
460
- translations/yaml/multipleFoldersExample/spaceOne/locales/de-DE/three.yaml multipleVariables
461
- translations/yaml/multipleFoldersExample/spaceTwo/locales/de-DE/one.yaml message.text-format
462
- │ translations/yaml/multipleFoldersExample/spaceTwo/locales/de-DE/three.yaml │ numberFormat │
463
- └──────────────────────────────────────────────────────────────────────────────┴───────────────────────┘
503
+ ┌────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
504
+ info result
505
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
506
+ file │ translations/yaml/multipleFoldersExample/spaceOne/locales/de-DE/one.yaml
507
+ key message.select
508
+ msg Expected element of type "select" but received "argument", Unexpected date element, Unexpected date element...
509
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
510
+ │ file │ translations/yaml/multipleFoldersExample/spaceOne/locales/de-DE/three.yaml │
511
+ │ key │ multipleVariables │
512
+ │ msg │ Expected argument to contain "user" but received "name" │
513
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
514
+ │ file │ translations/yaml/multipleFoldersExample/spaceTwo/locales/de-DE/one.yaml │
515
+ │ key │ message.text-format │
516
+ │ msg │ Expected element of type "tag" but received "number", Unexpected tag element │
517
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
518
+ │ file │ translations/yaml/multipleFoldersExample/spaceTwo/locales/de-DE/three.yaml │
519
+ │ key │ numberFormat │
520
+ │ msg │ Missing element number │
521
+ └────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
464
522
 
465
523
  `);
466
524
  done();
@@ -483,14 +541,25 @@ Found missing keys!
483
541
  └────────────────────────────────────────────────────────────────────────────┴───────────────────────┘
484
542
 
485
543
  Found invalid keys!
486
- ┌──────────────────────────────────────────────────────────────────────────────┬───────────────────────┐
487
- file key
488
- ├──────────────────────────────────────────────────────────────────────────────┼───────────────────────┤
489
- │ translations/yaml/multipleFoldersExample/spaceOne/locales/de-DE/one.yaml message.select │
490
- translations/yaml/multipleFoldersExample/spaceOne/locales/de-DE/three.yaml multipleVariables
491
- translations/yaml/multipleFoldersExample/spaceTwo/locales/de-DE/one.yaml message.text-format
492
- │ translations/yaml/multipleFoldersExample/spaceTwo/locales/de-DE/three.yaml │ numberFormat │
493
- └──────────────────────────────────────────────────────────────────────────────┴───────────────────────┘
544
+ ┌────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
545
+ info result
546
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
547
+ file │ translations/yaml/multipleFoldersExample/spaceOne/locales/de-DE/one.yaml
548
+ key message.select
549
+ msg Expected element of type "select" but received "argument", Unexpected date element, Unexpected date element...
550
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
551
+ │ file │ translations/yaml/multipleFoldersExample/spaceOne/locales/de-DE/three.yaml │
552
+ │ key │ multipleVariables │
553
+ │ msg │ Expected argument to contain "user" but received "name" │
554
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
555
+ │ file │ translations/yaml/multipleFoldersExample/spaceTwo/locales/de-DE/one.yaml │
556
+ │ key │ message.text-format │
557
+ │ msg │ Expected element of type "tag" but received "number", Unexpected tag element │
558
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
559
+ │ file │ translations/yaml/multipleFoldersExample/spaceTwo/locales/de-DE/three.yaml │
560
+ │ key │ numberFormat │
561
+ │ msg │ Missing element number │
562
+ └────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
494
563
 
495
564
  `);
496
565
  done();
@@ -517,11 +586,13 @@ Found missing keys!
517
586
  └────────────────────────────────────────────────┴────────────────────────────────┘
518
587
 
519
588
  Found invalid keys!
520
- ┌────────────────────────────────────────────────┬─────────────────────┐
521
- file key
522
- ├────────────────────────────────────────────────┼─────────────────────┤
523
- │ translations/yaml/messageExamples/de-de.yaml │ multipleVariables │
524
- └────────────────────────────────────────────────┴─────────────────────┘
589
+ ┌────────┬────────────────────────────────────────────────┐
590
+ info result
591
+ ├────────┼────────────────────────────────────────────────┤
592
+ file │ translations/yaml/messageExamples/de-de.yaml │
593
+ │ key │ multipleVariables │
594
+ │ msg │ Unexpected date element │
595
+ └────────┴────────────────────────────────────────────────┘
525
596
 
526
597
  `);
527
598
  done();
@@ -544,12 +615,17 @@ Found missing keys!
544
615
  └───────────────────────────────────────────────────────────────┴────────────────────────────────┘
545
616
 
546
617
  Found invalid keys!
547
- ┌─────────────────────────────────────────────────────────────────┬─────────────────────┐
548
- file key
549
- ├─────────────────────────────────────────────────────────────────┼─────────────────────┤
550
- │ translations/yaml/multipleFilesFolderExample/de-DE/one.yaml message.select │
551
- translations/yaml/multipleFilesFolderExample/de-DE/three.yaml multipleVariables
552
- └─────────────────────────────────────────────────────────────────┴─────────────────────┘
618
+ ┌────────┬──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
619
+ info result
620
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
621
+ file │ translations/yaml/multipleFilesFolderExample/de-DE/one.yaml
622
+ key message.select
623
+ │ msg │ Expected element of type "select" but received "argument", Unexpected date element, Unexpected date element... │
624
+ ├────────┼──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
625
+ │ file │ translations/yaml/multipleFilesFolderExample/de-DE/three.yaml │
626
+ │ key │ multipleVariables │
627
+ │ msg │ Expected argument to contain "user" but received "name" │
628
+ └────────┴──────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
553
629
 
554
630
  `);
555
631
  done();
@@ -1,12 +1,15 @@
1
+ export type StandardReporter = {
2
+ file: string;
3
+ key: string;
4
+ msg?: string;
5
+ };
1
6
  export declare const CheckOptions: string[];
2
7
  export type Context = (typeof CheckOptions)[number];
3
8
  export declare const contextMapping: Record<Context, string>;
4
- export declare const standardReporter: (result: {
5
- file: string;
6
- key: string;
7
- }[]) => string;
9
+ export declare const standardReporter: (result: StandardReporter[], flatten?: boolean) => string;
8
10
  export declare const summaryReporter: (result: {
9
11
  file: string;
10
12
  total: number;
11
13
  }[]) => string;
12
14
  export declare const createTable: (input: unknown[]) => string;
15
+ export declare const createVerticalTable: (input: unknown[]) => string;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createTable = exports.summaryReporter = exports.standardReporter = exports.contextMapping = exports.CheckOptions = void 0;
3
+ exports.createVerticalTable = exports.createTable = exports.summaryReporter = exports.standardReporter = exports.contextMapping = exports.CheckOptions = void 0;
4
4
  const console_1 = require("console");
5
5
  const stream_1 = require("stream");
6
6
  exports.CheckOptions = [
@@ -15,8 +15,17 @@ exports.contextMapping = {
15
15
  unused: "unused",
16
16
  undefined: "undefined",
17
17
  };
18
- const standardReporter = (result) => {
19
- return (0, exports.createTable)(result.map(({ file, key }) => ({ file, key })));
18
+ const standardReporter = (result, flatten = false) => {
19
+ if (flatten) {
20
+ const data = result.reduce((acc, row) => {
21
+ Object.entries(row).forEach(([info, result]) => {
22
+ acc.push({ info, result });
23
+ });
24
+ return acc;
25
+ }, []);
26
+ return (0, exports.createVerticalTable)(data);
27
+ }
28
+ return (0, exports.createTable)(result);
20
29
  };
21
30
  exports.standardReporter = standardReporter;
22
31
  const summaryReporter = (result) => {
@@ -35,7 +44,8 @@ const createTable = (input) => {
35
44
  const table = (ts.read() || "").toString();
36
45
  // https://stackoverflow.com/a/69874540
37
46
  let output = "";
38
- for (let line of table.split(/[\r\n]+/)) {
47
+ const lines = table.split(/[\r\n]+/);
48
+ for (let line of lines) {
39
49
  output += `${line
40
50
  .replace(/[^┬]*┬/, "┌")
41
51
  .replace(/^├─*┼/, "├")
@@ -46,3 +56,37 @@ const createTable = (input) => {
46
56
  return output.replace(/\n\n$/, "");
47
57
  };
48
58
  exports.createTable = createTable;
59
+ const createVerticalTable = (input) => {
60
+ // https://stackoverflow.com/a/67859384
61
+ const ts = new stream_1.Transform({
62
+ transform(chunk, enc, cb) {
63
+ cb(null, chunk);
64
+ },
65
+ });
66
+ const logger = new console_1.Console({ stdout: ts });
67
+ logger.table(input);
68
+ const table = (ts.read() || "").toString();
69
+ // https://stackoverflow.com/a/69874540
70
+ let output = "";
71
+ let firstLine = "";
72
+ let index = 0;
73
+ const lines = table.split(/[\r\n]+/);
74
+ for (let line of lines) {
75
+ const transformedLine = `${line
76
+ .replace(/[^┬]*┬/, "┌")
77
+ .replace(/^├─*┼/, "├")
78
+ .replace(/│[^│]*/, "")
79
+ .replace(/^└─*┴/, "└")
80
+ .replace(/'/g, " ")}\n`;
81
+ output += transformedLine;
82
+ if (index === 2) {
83
+ firstLine = transformedLine;
84
+ }
85
+ if (index > 3 && (index + 1) % 3 === 0 && index !== lines.length - 3) {
86
+ output += firstLine;
87
+ }
88
+ index++;
89
+ }
90
+ return output.replace(/\n\n$/, "");
91
+ };
92
+ exports.createVerticalTable = createVerticalTable;
package/dist/index.js CHANGED
@@ -108,11 +108,33 @@ const findUnusedI18NextTranslations = async (source, filesToParse, componentFunc
108
108
  const findUnusedNextIntlTranslations = async (translationFiles, filesToParse) => {
109
109
  let unusedKeys = {};
110
110
  const extracted = (0, nextIntlSrcParser_1.extract)(filesToParse);
111
- const extractedResultSet = new Set(extracted.map(({ key }) => key));
111
+ const dynamicNamespaces = extracted.flatMap((namespace) => {
112
+ if (namespace.meta.dynamic) {
113
+ return [namespace.key];
114
+ }
115
+ return [];
116
+ });
117
+ const extractedResultSet = new Set(extracted.flatMap((namespace) => {
118
+ if (!namespace.meta.dynamic) {
119
+ return [namespace.key];
120
+ }
121
+ return [];
122
+ }));
112
123
  translationFiles.forEach(({ name, content }) => {
113
124
  const keysInSource = Object.keys(content);
114
125
  const found = [];
115
126
  for (const keyInSource of keysInSource) {
127
+ // Check if key is part of a dynamic namespace
128
+ // Skip the key if it is part of the dynamic namespace
129
+ const isDynamicNamespace = dynamicNamespaces.find((dynamicNamespace) => {
130
+ const keyInSourceNamespaces = keyInSource.split(".");
131
+ return dynamicNamespace.split(".").every((namePart, index) => {
132
+ return namePart === keyInSourceNamespaces[index];
133
+ });
134
+ });
135
+ if (isDynamicNamespace) {
136
+ continue;
137
+ }
116
138
  if (!extractedResultSet.has(keyInSource)) {
117
139
  found.push(keyInSource);
118
140
  }
@@ -188,7 +210,7 @@ const findUndefinedNextIntlKeys = async (translationFiles, filesToParse) => {
188
210
  const extractedResult = (0, nextIntlSrcParser_1.extract)(filesToParse);
189
211
  let undefinedKeys = {};
190
212
  extractedResult.forEach(({ key, meta }) => {
191
- if (!sourceKeys.has(key)) {
213
+ if (!meta.dynamic && !sourceKeys.has(key)) {
192
214
  // @ts-ignore
193
215
  const file = meta.file;
194
216
  if (!undefinedKeys[file]) {
@@ -1,5 +1,8 @@
1
1
  import { MessageFormatElement } from "@formatjs/icu-messageformat-parser";
2
2
  import { Translation } from "../types";
3
3
  export declare const findInvalidTranslations: (source: Translation, files: Record<string, Translation>) => {};
4
- export declare const compareTranslationFiles: (a: Translation, b: Translation) => string[];
4
+ export declare const compareTranslationFiles: (a: Translation, b: Translation) => {
5
+ key: string;
6
+ msg: string;
7
+ }[];
5
8
  export declare const hasDiff: (a: MessageFormatElement[], b: MessageFormatElement[]) => boolean;