Skip to content

Commit 852a110

Browse files
committed
refactor: usage table
1 parent e2daf86 commit 852a110

2 files changed

Lines changed: 27 additions & 101 deletions

File tree

packages/cli/src/cli/cmd/status.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,19 +333,20 @@ export default new Command()
333333

334334
// Create a new table instance with cli-table3
335335
const table = new Table({
336-
head: ["Language", "Status", "Complete", "Missing", "Updated", "Words"],
336+
head: ["Language", "Status", "Complete", "Missing", "Updated", "Total Keys", "Words to Translate"],
337337
style: {
338338
head: ["white"], // White color for headers
339339
border: [], // No color for borders
340340
},
341-
colWidths: [12, 20, 18, 12, 12, 15], // Explicit column widths, making Status column wider
341+
colWidths: [12, 20, 18, 12, 12, 12, 15], // Explicit column widths, making Status column wider
342342
});
343343

344344
// Data rows
345345
let totalWordsToTranslate = 0;
346346
for (const locale of targetLocales) {
347347
const stats = languageStats[locale];
348348
const percentComplete = ((stats.complete / totalSourceKeyCount) * 100).toFixed(1);
349+
const totalNeeded = stats.missing + stats.updated;
349350

350351
// Determine status text and color
351352
let statusText;
@@ -378,6 +379,7 @@ export default new Command()
378379
`${stats.complete}/${totalSourceKeyCount} (${percentComplete}%)`,
379380
stats.missing > 0 ? chalk.red(stats.missing.toString()) : "0",
380381
stats.updated > 0 ? chalk.yellow(stats.updated.toString()) : "0",
382+
totalNeeded > 0 ? chalk.magenta(totalNeeded.toString()) : "0",
381383
words > 0 ? `~${words.toLocaleString()}` : "0",
382384
]);
383385
}
@@ -388,8 +390,9 @@ export default new Command()
388390
// Total usage summary
389391
console.log(chalk.bold(`\n📊 USAGE ESTIMATE:`));
390392
console.log(
391-
`• TOTAL: ~${chalk.yellow.bold(totalWordsToTranslate.toLocaleString())} words to translate across all languages`,
393+
`• WORDS TO BE CONSUMED: ~${chalk.yellow.bold(totalWordsToTranslate.toLocaleString())} words across all languages`,
392394
);
395+
console.log(` (Words are counted from source language for keys that need translation in target languages)`);
393396

394397
// Breakdown by language if we have multiple languages
395398
if (targetLocales.length > 1) {

packages/cli/src/cli/loaders/index.ts

Lines changed: 21 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ import createAndroidLoader from "./android";
1212
import createCsvLoader from "./csv";
1313
import createHtmlLoader from "./html";
1414
import createMarkdownLoader from "./markdown";
15-
import {
16-
createDoubleSerializationLoader,
17-
createMdxFormatLoader,
18-
createMdxStructureLoader,
19-
} from "./mdx";
15+
import { createDoubleSerializationLoader, createMdxFormatLoader, createMdxStructureLoader } from "./mdx";
2016
import createPropertiesLoader from "./properties";
2117
import createXcodeStringsLoader from "./xcode-strings";
2218
import createXcodeStringsdictLoader from "./xcode-stringsdict";
@@ -59,32 +55,23 @@ export default function createBucketLoader(
5955
createAndroidLoader(),
6056
createFlatLoader(),
6157
createSyncLoader(),
62-
createUnlocalizableLoader(
63-
options.isCacheRestore,
64-
options.returnUnlocalizedKeys,
65-
),
58+
createUnlocalizableLoader(options.isCacheRestore, options.returnUnlocalizedKeys),
6659
);
6760
case "csv":
6861
return composeLoaders(
6962
createTextFileLoader(bucketPathPattern),
7063
createCsvLoader(),
7164
createFlatLoader(),
7265
createSyncLoader(),
73-
createUnlocalizableLoader(
74-
options.isCacheRestore,
75-
options.returnUnlocalizedKeys,
76-
),
66+
createUnlocalizableLoader(options.isCacheRestore, options.returnUnlocalizedKeys),
7767
);
7868
case "html":
7969
return composeLoaders(
8070
createTextFileLoader(bucketPathPattern),
8171
createPrettierLoader({ parser: "html", bucketPathPattern }),
8272
createHtmlLoader(),
8373
createSyncLoader(),
84-
createUnlocalizableLoader(
85-
options.isCacheRestore,
86-
options.returnUnlocalizedKeys,
87-
),
74+
createUnlocalizableLoader(options.isCacheRestore, options.returnUnlocalizedKeys),
8875
);
8976
case "json":
9077
return composeLoaders(
@@ -95,21 +82,15 @@ export default function createBucketLoader(
9582
createFlatLoader(),
9683
createLockedKeysLoader(lockedKeys || [], options.isCacheRestore),
9784
createSyncLoader(),
98-
createUnlocalizableLoader(
99-
options.isCacheRestore,
100-
options.returnUnlocalizedKeys,
101-
),
85+
createUnlocalizableLoader(options.isCacheRestore, options.returnUnlocalizedKeys),
10286
);
10387
case "markdown":
10488
return composeLoaders(
10589
createTextFileLoader(bucketPathPattern),
10690
createPrettierLoader({ parser: "markdown", bucketPathPattern }),
10791
createMarkdownLoader(),
10892
createSyncLoader(),
109-
createUnlocalizableLoader(
110-
options.isCacheRestore,
111-
options.returnUnlocalizedKeys,
112-
),
93+
createUnlocalizableLoader(options.isCacheRestore, options.returnUnlocalizedKeys),
11394
);
11495
case "mdx":
11596
return composeLoaders(
@@ -120,19 +101,6 @@ export default function createBucketLoader(
120101
createFlatLoader(),
121102
createMdxStructureLoader(),
122103
createSyncLoader(),
123-
createUnlocalizableLoader(
124-
options.isCacheRestore,
125-
options.returnUnlocalizedKeys,
126-
),
127-
);
128-
case "mdx":
129-
return composeLoaders(
130-
createTextFileLoader(bucketPathPattern),
131-
createPrettierLoader({ parser: "mdx", bucketPathPattern }),
132-
createMdxFormatLoader(),
133-
createFlatLoader(),
134-
createMdxStructureLoader(),
135-
createSyncLoader(),
136104
createUnlocalizableLoader(options.isCacheRestore, options.returnUnlocalizedKeys),
137105
);
138106
case "po":
@@ -142,41 +110,29 @@ export default function createBucketLoader(
142110
createFlatLoader(),
143111
createSyncLoader(),
144112
createVariableLoader({ type: "python" }),
145-
createUnlocalizableLoader(
146-
options.isCacheRestore,
147-
options.returnUnlocalizedKeys,
148-
),
113+
createUnlocalizableLoader(options.isCacheRestore, options.returnUnlocalizedKeys),
149114
);
150115
case "properties":
151116
return composeLoaders(
152117
createTextFileLoader(bucketPathPattern),
153118
createPropertiesLoader(),
154119
createSyncLoader(),
155-
createUnlocalizableLoader(
156-
options.isCacheRestore,
157-
options.returnUnlocalizedKeys,
158-
),
120+
createUnlocalizableLoader(options.isCacheRestore, options.returnUnlocalizedKeys),
159121
);
160122
case "xcode-strings":
161123
return composeLoaders(
162124
createTextFileLoader(bucketPathPattern),
163125
createXcodeStringsLoader(),
164126
createSyncLoader(),
165-
createUnlocalizableLoader(
166-
options.isCacheRestore,
167-
options.returnUnlocalizedKeys,
168-
),
127+
createUnlocalizableLoader(options.isCacheRestore, options.returnUnlocalizedKeys),
169128
);
170129
case "xcode-stringsdict":
171130
return composeLoaders(
172131
createTextFileLoader(bucketPathPattern),
173132
createXcodeStringsdictLoader(),
174133
createFlatLoader(),
175134
createSyncLoader(),
176-
createUnlocalizableLoader(
177-
options.isCacheRestore,
178-
options.returnUnlocalizedKeys,
179-
),
135+
createUnlocalizableLoader(options.isCacheRestore, options.returnUnlocalizedKeys),
180136
);
181137
case "xcode-xcstrings":
182138
return composeLoaders(
@@ -187,10 +143,7 @@ export default function createBucketLoader(
187143
createFlatLoader(),
188144
createSyncLoader(),
189145
createVariableLoader({ type: "ieee" }),
190-
createUnlocalizableLoader(
191-
options.isCacheRestore,
192-
options.returnUnlocalizedKeys,
193-
),
146+
createUnlocalizableLoader(options.isCacheRestore, options.returnUnlocalizedKeys),
194147
);
195148
case "yaml":
196149
return composeLoaders(
@@ -200,10 +153,7 @@ export default function createBucketLoader(
200153
createFlatLoader(),
201154
createLockedKeysLoader(lockedKeys || [], options.isCacheRestore),
202155
createSyncLoader(),
203-
createUnlocalizableLoader(
204-
options.isCacheRestore,
205-
options.returnUnlocalizedKeys,
206-
),
156+
createUnlocalizableLoader(options.isCacheRestore, options.returnUnlocalizedKeys),
207157
);
208158
case "yaml-root-key":
209159
return composeLoaders(
@@ -213,10 +163,7 @@ export default function createBucketLoader(
213163
createRootKeyLoader(true),
214164
createFlatLoader(),
215165
createSyncLoader(),
216-
createUnlocalizableLoader(
217-
options.isCacheRestore,
218-
options.returnUnlocalizedKeys,
219-
),
166+
createUnlocalizableLoader(options.isCacheRestore, options.returnUnlocalizedKeys),
220167
);
221168
case "flutter":
222169
return composeLoaders(
@@ -226,84 +173,60 @@ export default function createBucketLoader(
226173
createFlutterLoader(),
227174
createFlatLoader(),
228175
createSyncLoader(),
229-
createUnlocalizableLoader(
230-
options.isCacheRestore,
231-
options.returnUnlocalizedKeys,
232-
),
176+
createUnlocalizableLoader(options.isCacheRestore, options.returnUnlocalizedKeys),
233177
);
234178
case "xliff":
235179
return composeLoaders(
236180
createTextFileLoader(bucketPathPattern),
237181
createXliffLoader(),
238182
createFlatLoader(),
239183
createSyncLoader(),
240-
createUnlocalizableLoader(
241-
options.isCacheRestore,
242-
options.returnUnlocalizedKeys,
243-
),
184+
createUnlocalizableLoader(options.isCacheRestore, options.returnUnlocalizedKeys),
244185
);
245186
case "xml":
246187
return composeLoaders(
247188
createTextFileLoader(bucketPathPattern),
248189
createXmlLoader(),
249190
createFlatLoader(),
250191
createSyncLoader(),
251-
createUnlocalizableLoader(
252-
options.isCacheRestore,
253-
options.returnUnlocalizedKeys,
254-
),
192+
createUnlocalizableLoader(options.isCacheRestore, options.returnUnlocalizedKeys),
255193
);
256194
case "srt":
257195
return composeLoaders(
258196
createTextFileLoader(bucketPathPattern),
259197
createSrtLoader(),
260198
createSyncLoader(),
261-
createUnlocalizableLoader(
262-
options.isCacheRestore,
263-
options.returnUnlocalizedKeys,
264-
),
199+
createUnlocalizableLoader(options.isCacheRestore, options.returnUnlocalizedKeys),
265200
);
266201
case "dato":
267202
return composeLoaders(
268203
createDatoLoader(bucketPathPattern),
269204
createSyncLoader(),
270205
createFlatLoader(),
271-
createUnlocalizableLoader(
272-
options.isCacheRestore,
273-
options.returnUnlocalizedKeys,
274-
),
206+
createUnlocalizableLoader(options.isCacheRestore, options.returnUnlocalizedKeys),
275207
);
276208
case "vtt":
277209
return composeLoaders(
278210
createTextFileLoader(bucketPathPattern),
279211
createVttLoader(),
280212
createSyncLoader(),
281-
createUnlocalizableLoader(
282-
options.isCacheRestore,
283-
options.returnUnlocalizedKeys,
284-
),
213+
createUnlocalizableLoader(options.isCacheRestore, options.returnUnlocalizedKeys),
285214
);
286215
case "php":
287216
return composeLoaders(
288217
createTextFileLoader(bucketPathPattern),
289218
createPhpLoader(),
290219
createSyncLoader(),
291220
createFlatLoader(),
292-
createUnlocalizableLoader(
293-
options.isCacheRestore,
294-
options.returnUnlocalizedKeys,
295-
),
221+
createUnlocalizableLoader(options.isCacheRestore, options.returnUnlocalizedKeys),
296222
);
297223
case "vue-json":
298224
return composeLoaders(
299225
createTextFileLoader(bucketPathPattern),
300226
createVueJsonLoader(),
301227
createSyncLoader(),
302228
createFlatLoader(),
303-
createUnlocalizableLoader(
304-
options.isCacheRestore,
305-
options.returnUnlocalizedKeys,
306-
),
229+
createUnlocalizableLoader(options.isCacheRestore, options.returnUnlocalizedKeys),
307230
);
308231
}
309232
}

0 commit comments

Comments
 (0)