Skip to content

Commit

Permalink
Merge pull request #12738 from ethereum/crowdin-reports
Browse files Browse the repository at this point in the history
feat: Crowdin generateReviewReport script
  • Loading branch information
wackerow authored Apr 30, 2024
2 parents be1281d + ab3a828 commit 0a497f8
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 0 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/generate-review-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Generate Crowdin translation review report

on:
workflow_dispatch:

jobs:
generate_report:
runs-on: ubuntu-latest
steps:
- name: Check out code
uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: 18

- name: Install dependencies
run: yarn install

- name: Install ts-node
run: yarn global add ts-node

- name: Run script
run: npx ts-node -O '{"module":"commonjs"}' ./src/scripts/crowdin/reports/generateReviewReport.ts
env:
CROWDIN_API_KEY: ${{ secrets.CROWDIN_API_KEY }}
CROWDIN_PROJECT_ID: ${{ secrets.CROWDIN_PROJECT_ID }}

- name: Upload output as artifact
uses: actions/upload-artifact@v2
with:
name: output
path: ./src/data/crowdin/bucketsAwaitingReviewReport.csv
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ robots.txt

# vscode workplace configuration
.vscode

# Crowdin report output
src/data/crowdin/bucketsAwaitingReviewReport.csv
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"crowdin-import": "ts-node src/scripts/crowdin-import.ts",
"markdown-checker": "ts-node -O '{ \"module\": \"commonjs\" }' src/scripts/markdownChecker.ts",
"events-import": "ts-node -O '{ \"module\": \"commonjs\" }' src/scripts/events-import.ts",
"crowdin-needs-review": "ts-node -O '{ \"module\": \"commonjs\" }' src/scripts/crowdin/reports/generateReviewReport.ts",
"theme": "chakra-cli tokens ./src/@chakra-ui/theme.ts",
"theme:watch": "chakra-cli tokens ./src/@chakra-ui/theme.ts --watch"
},
Expand Down
85 changes: 85 additions & 0 deletions src/scripts/crowdin/reports/generateReviewReport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import fs from "fs"
import path from "path"

import i18n from "../../../../i18n.config.json"
import dirs from "../../../data/crowdin/translation-buckets-dirs.json"
import { CROWDIN_API_MAX_LIMIT } from "../../../lib/constants"
import crowdinClient from "../api-client/crowdinClient"

type SummaryItem = [code: string, bucket: string, needsReview: number]

/**
* Generates a report of words needing review for each content bucket in all languages.
* Report in CSV format with columns: Language, Bucket Name, Words needing review.
* To run:
* - Ensure CROWDIN_API_KEY is set in the .env file (.env.local will not work)
* 1. https://crowdin.com/settings#api-key
* 2. Click: "New token"
* 3. Give token a name
* 4. Select "Translation Status" under "Projects" for scope
* 5. Click: "Create" and authenticate
* 6. Copy the token to the .env file
* - Can be run with `yarn crowdin-needs-review`
* - Results are saved to src/data/crowdin/bucketsAwaitingReviewReport.csv
* - Report is git ignored, and should not be committed
*/
async function main() {
const projectId = Number(process.env.CROWDIN_PROJECT_ID) || 363359

const reportSummary = [] as SummaryItem[]

const directories = dirs.sort((a, b) => a.name.localeCompare(b.name))

// Loop through list of content buckets (dirs)
for (const dir of directories) {
console.log(`Processing: ${dir.name}...`)

// Get translation progress for bucket (dir.id) in all languages
const { data } =
await crowdinClient.translationStatusApi.getDirectoryProgress(
projectId,
dir.id,
{ limit: CROWDIN_API_MAX_LIMIT }
)

// Loop through supported languages
i18n.forEach(({ crowdinCode }) => {
const match = data.find(
({ data: { languageId } }) => languageId === crowdinCode
)
if (!match) return
const { words, translationProgress } = match.data
if (translationProgress < 100) return
const needsReview = words.translated - words.approved
if (needsReview === 0) return
// If match, 100% translation progress, and not full reviewed, add to summary
reportSummary.push([crowdinCode, dir.name, needsReview])
})
}

// Sort first by language code, then by bucket name
const sorted = reportSummary.sort((a, b) =>
a[0] === b[0] ? a[1].localeCompare(b[1]) : a[0].localeCompare(b[0])
)
// Transform to çsv string
const csvArray = sorted.map((item) => item.join(","))
// Insert header names at beginning of csv array
csvArray.unshift("Language,Bucket Name,Words needing review")
const csv = csvArray.join("\n")

// Write csv to file to fs
const csvPath = path.resolve(
process.cwd(),
"src/data/crowdin/bucketsAwaitingReviewReport.csv"
)
fs.writeFileSync(csvPath, csv)

// Log summary
console.log("\nReport summary:\n")
console.log(csv)
console.log(`\n✅ Report saved to ${csvPath}`)
}

main()

export default main

0 comments on commit 0a497f8

Please sign in to comment.