Skip to content

Commit 9aaa128

Browse files
committed
feat: add wordsNeedingReview report script
1 parent be5d928 commit 9aaa128

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@ robots.txt
5252

5353
# vscode workplace configuration
5454
.vscode
55+
56+
# Crowdin report output
57+
src/data/crowdin/report.csv

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"crowdin-clean": "rm -rf .crowdin && mkdir .crowdin",
1919
"crowdin-import": "ts-node src/scripts/crowdin-import.ts",
2020
"events-import": "ts-node -O '{ \"module\": \"commonjs\" }' src/scripts/events-import.ts",
21+
"crowdin-needs-review": "ts-node -O '{ \"module\": \"commonjs\" }' src/scripts/crowdin/reports/wordsNeedingReview.ts",
2122
"markdown-checker": "ts-node -O '{ \"module\": \"commonjs\" }' src/scripts/markdownChecker.ts"
2223
},
2324
"dependencies": {
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import fs from "fs"
2+
import path from "path"
3+
4+
import i18n from "../../../../i18n.config.json"
5+
import dirs from "../../../data/crowdin/translation-buckets-dirs.json"
6+
import { CROWDIN_API_MAX_LIMIT } from "../../../lib/constants"
7+
import crowdinClient from "../api-client/crowdinClient"
8+
9+
type SummaryItem = [code: string, bucket: string, needsReview: number]
10+
11+
async function main() {
12+
const projectId = Number(process.env.CROWDIN_PROJECT_ID) || 363359
13+
14+
const reportSummary = [] as SummaryItem[]
15+
16+
const directories = dirs.sort((a, b) => a.name.localeCompare(b.name))
17+
18+
// Loop through list of content buckets (dirs)
19+
for (const dir of directories) {
20+
console.log(`Processing: ${dir.name}...`)
21+
22+
// Get translation progress for bucket (dir.id) in all languages
23+
const { data } =
24+
await crowdinClient.translationStatusApi.getDirectoryProgress(
25+
projectId,
26+
dir.id,
27+
{ limit: CROWDIN_API_MAX_LIMIT }
28+
)
29+
30+
// Loop through supported languages
31+
i18n.forEach(({ crowdinCode }) => {
32+
const match = data.find(
33+
({ data: { languageId } }) => languageId === crowdinCode
34+
)
35+
if (!match) return
36+
const { words, translationProgress } = match.data
37+
if (translationProgress < 100) return
38+
const needsReview = words.translated - words.approved
39+
if (needsReview === 0) return
40+
// If match, 100% translation progress, and not full reviewed, add to summary
41+
reportSummary.push([crowdinCode, dir.name, needsReview])
42+
})
43+
}
44+
45+
// Transform to çsv string
46+
const csvArray = reportSummary.map((item) => item.join(","))
47+
// Insert header names at beginning of csv array
48+
csvArray.unshift("Language,Bucket Name,Words needing review")
49+
const csv = csvArray.join("\n")
50+
51+
// Write csv to file to fs
52+
const csvPath = path.resolve(process.cwd(), "src/data/crowdin/report.csv")
53+
fs.writeFileSync(csvPath, csv)
54+
55+
// Log summary
56+
console.log("\nReport summary:\n")
57+
console.log(csv)
58+
console.log(`\n✅ Report saved to ${csvPath}`)
59+
}
60+
61+
main()
62+
63+
export default main

0 commit comments

Comments
 (0)