Skip to content

Commit 8be6ebb

Browse files
committed
*: refactor language generation script
- Make data more internally consistent - Move presentation concerns into component - Ensure proper tsconfig support for scripts
1 parent 5419cc7 commit 8be6ebb

File tree

5 files changed

+104
-37
lines changed

5 files changed

+104
-37
lines changed

docs/docs/contributing/translation.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TranslationStatus } from "@site/src/components/TranslationStatus";
1+
import { TranslationStatus } from "@site/src/components/TranslationStatusV2";
22
import translationData from "../translation-status.json";
33

44
# Translations
@@ -7,7 +7,7 @@ Before getting started, you should ensure you read the general [contribution gui
77

88
## Status
99

10-
<TranslationStatus data={translationData} />
10+
<TranslationStatus {...translationData} />
1111

1212
## Architecture
1313

docs/docs/translation-status.json

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
[
2-
{
3-
"name": "English",
4-
"code": "en",
5-
"completed": 207,
6-
"missing": 0,
7-
"percent": 100
8-
},
9-
{
10-
"name": "Nederlands",
11-
"code": "nl",
12-
"completed": 146,
13-
"missing": 61,
14-
"percent": 71
15-
}
16-
]
1+
{
2+
"total": 207,
3+
"statuses": [
4+
{
5+
"name": "English",
6+
"code": "en",
7+
"completed": 207
8+
},
9+
{
10+
"name": "Nederlands",
11+
"code": "nl",
12+
"completed": 146
13+
}
14+
]
15+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import type React from "react";
2+
3+
type TranslationStatus = {
4+
name: string;
5+
code: string;
6+
completed: number;
7+
};
8+
9+
type Props = {
10+
total: number;
11+
statuses: TranslationStatus[];
12+
};
13+
14+
export const TranslationStatus: React.FC<Props> = ({ total, statuses }) => {
15+
return (
16+
<table style={{ borderCollapse: "collapse", width: "100%" }}>
17+
<thead>
18+
<tr>
19+
<th style={{ padding: "8px", textAlign: "left" }}>Language</th>
20+
<th style={{ padding: "8px", textAlign: "right" }}>Completed</th>
21+
<th style={{ padding: "8px", textAlign: "right" }}>Missing</th>
22+
<th style={{ padding: "8px", textAlign: "right" }}>Percent Complete</th>
23+
</tr>
24+
</thead>
25+
<tbody>
26+
{statuses.map(({ name, code, completed }) => {
27+
const missing = total - completed;
28+
const percent = Math.round((completed / total) * 100);
29+
return (
30+
<tr key={code}>
31+
<td style={{ padding: "8px" }}>
32+
{name} ({code})
33+
</td>
34+
<td style={{ padding: "8px" }}>{completed}</td>
35+
<td style={{ padding: "8px" }}>{missing}</td>
36+
<td style={{ padding: "8px" }}>
37+
<div style={{ display: "flex", alignItems: "center", gap: "8px" }}>
38+
<span style={{ width: "8ch" }}>{percent}%</span>
39+
<progress value={completed} max={completed + missing} />
40+
</div>
41+
</td>
42+
</tr>
43+
);
44+
})}
45+
</tbody>
46+
</table>
47+
);
48+
};

plugin/scripts/gen-lang-status.ts

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
import { registry } from "../src/i18n";
12
import { writeFileSync } from "node:fs";
23
import { join } from "node:path";
3-
import { registry } from "../src/i18n";
44

55
const countKeys = (obj: Record<string, unknown>): number => {
66
let count = 0;
@@ -16,24 +16,44 @@ const countKeys = (obj: Record<string, unknown>): number => {
1616
return count;
1717
};
1818

19-
const totalKeys = countKeys(registry.en.translations);
19+
type TranslationStatus = {
20+
name: string;
21+
code: string;
22+
completed: number;
23+
};
24+
25+
const tabulateTranslations = (reg: typeof registry): TranslationStatus[] => {
26+
const result: TranslationStatus[] = [];
27+
28+
for (const definition of Object.values(reg)) {
29+
const completed = countKeys(definition.translations);
30+
31+
result.push({
32+
name: definition.name,
33+
code: definition.code,
34+
completed,
35+
});
36+
}
37+
38+
return result;
39+
};
40+
41+
type Output = {
42+
total: number;
43+
statuses: TranslationStatus[];
44+
};
2045

21-
// biome-ignore lint/suspicious/noExplicitAny: <explanation>
22-
const result: any[] = [];
46+
const generateOutput = () => {
47+
const total = countKeys(registry.en.translations);
48+
const statuses = tabulateTranslations(registry);
2349

24-
for (const definition of Object.values(registry)) {
25-
const keys = countKeys(definition.translations);
26-
const missing = totalKeys - keys;
27-
const percent = Math.round((keys / totalKeys) * 100);
50+
const result: Output = {
51+
total,
52+
statuses,
53+
};
2854

29-
result.push({
30-
name: definition.name,
31-
code: definition.code,
32-
completed: keys,
33-
missing,
34-
percent,
35-
});
36-
}
55+
const outputFilePath = join(__dirname, "..", "..", "docs", "docs", "translation-status.json");
56+
writeFileSync(outputFilePath, JSON.stringify(result, null, 2));
57+
};
3758

38-
const outputFilePath = join(__dirname, "..", "..", "docs", "docs", "translation-status.json");
39-
writeFileSync(outputFilePath, JSON.stringify(result, null, 2));
59+
generateOutput();

plugin/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"include": ["src/**/*", "./vitest-setup.ts"],
2+
"include": ["src/**/*", "./vitest-setup.ts", "scripts/**/*"],
33
"exclude": ["node_modules/*"],
44
"compilerOptions": {
55
"jsx": "react-jsx",

0 commit comments

Comments
 (0)