|
| 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