Skip to content

Commit 0a497f8

Browse files
authored
Merge pull request #12738 from ethereum/crowdin-reports
feat: Crowdin generateReviewReport script
2 parents be1281d + ab3a828 commit 0a497f8

File tree

4 files changed

+123
-0
lines changed

4 files changed

+123
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Generate Crowdin translation review report
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
generate_report:
8+
runs-on: ubuntu-latest
9+
steps:
10+
- name: Check out code
11+
uses: actions/checkout@v3
12+
13+
- name: Set up Node.js
14+
uses: actions/setup-node@v3
15+
with:
16+
node-version: 18
17+
18+
- name: Install dependencies
19+
run: yarn install
20+
21+
- name: Install ts-node
22+
run: yarn global add ts-node
23+
24+
- name: Run script
25+
run: npx ts-node -O '{"module":"commonjs"}' ./src/scripts/crowdin/reports/generateReviewReport.ts
26+
env:
27+
CROWDIN_API_KEY: ${{ secrets.CROWDIN_API_KEY }}
28+
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}
29+
30+
- name: Upload output as artifact
31+
uses: actions/upload-artifact@v2
32+
with:
33+
name: output
34+
path: ./src/data/crowdin/bucketsAwaitingReviewReport.csv

.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/bucketsAwaitingReviewReport.csv

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"crowdin-import": "ts-node src/scripts/crowdin-import.ts",
2121
"markdown-checker": "ts-node -O '{ \"module\": \"commonjs\" }' src/scripts/markdownChecker.ts",
2222
"events-import": "ts-node -O '{ \"module\": \"commonjs\" }' src/scripts/events-import.ts",
23+
"crowdin-needs-review": "ts-node -O '{ \"module\": \"commonjs\" }' src/scripts/crowdin/reports/generateReviewReport.ts",
2324
"theme": "chakra-cli tokens ./src/@chakra-ui/theme.ts",
2425
"theme:watch": "chakra-cli tokens ./src/@chakra-ui/theme.ts --watch"
2526
},
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
/**
12+
* Generates a report of words needing review for each content bucket in all languages.
13+
* Report in CSV format with columns: Language, Bucket Name, Words needing review.
14+
* To run:
15+
* - Ensure CROWDIN_API_KEY is set in the .env file (.env.local will not work)
16+
* 1. https://crowdin.com/settings#api-key
17+
* 2. Click: "New token"
18+
* 3. Give token a name
19+
* 4. Select "Translation Status" under "Projects" for scope
20+
* 5. Click: "Create" and authenticate
21+
* 6. Copy the token to the .env file
22+
* - Can be run with `yarn crowdin-needs-review`
23+
* - Results are saved to src/data/crowdin/bucketsAwaitingReviewReport.csv
24+
* - Report is git ignored, and should not be committed
25+
*/
26+
async function main() {
27+
const projectId = Number(process.env.CROWDIN_PROJECT_ID) || 363359
28+
29+
const reportSummary = [] as SummaryItem[]
30+
31+
const directories = dirs.sort((a, b) => a.name.localeCompare(b.name))
32+
33+
// Loop through list of content buckets (dirs)
34+
for (const dir of directories) {
35+
console.log(`Processing: ${dir.name}...`)
36+
37+
// Get translation progress for bucket (dir.id) in all languages
38+
const { data } =
39+
await crowdinClient.translationStatusApi.getDirectoryProgress(
40+
projectId,
41+
dir.id,
42+
{ limit: CROWDIN_API_MAX_LIMIT }
43+
)
44+
45+
// Loop through supported languages
46+
i18n.forEach(({ crowdinCode }) => {
47+
const match = data.find(
48+
({ data: { languageId } }) => languageId === crowdinCode
49+
)
50+
if (!match) return
51+
const { words, translationProgress } = match.data
52+
if (translationProgress < 100) return
53+
const needsReview = words.translated - words.approved
54+
if (needsReview === 0) return
55+
// If match, 100% translation progress, and not full reviewed, add to summary
56+
reportSummary.push([crowdinCode, dir.name, needsReview])
57+
})
58+
}
59+
60+
// Sort first by language code, then by bucket name
61+
const sorted = reportSummary.sort((a, b) =>
62+
a[0] === b[0] ? a[1].localeCompare(b[1]) : a[0].localeCompare(b[0])
63+
)
64+
// Transform to çsv string
65+
const csvArray = sorted.map((item) => item.join(","))
66+
// Insert header names at beginning of csv array
67+
csvArray.unshift("Language,Bucket Name,Words needing review")
68+
const csv = csvArray.join("\n")
69+
70+
// Write csv to file to fs
71+
const csvPath = path.resolve(
72+
process.cwd(),
73+
"src/data/crowdin/bucketsAwaitingReviewReport.csv"
74+
)
75+
fs.writeFileSync(csvPath, csv)
76+
77+
// Log summary
78+
console.log("\nReport summary:\n")
79+
console.log(csv)
80+
console.log(`\n✅ Report saved to ${csvPath}`)
81+
}
82+
83+
main()
84+
85+
export default main

0 commit comments

Comments
 (0)