mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-15 03:05:41 +00:00
Merge pull request #11144 from overleaf/jpa-translations-helper-scripts
[web] scripts: add script for checking coverage of non-en translations GitOrigin-RevId: ccde0d5b56b9e3b8f2a32916ecf1b442482edd12
This commit is contained in:
parent
b91f43f4f2
commit
0b7e28432d
2 changed files with 58 additions and 0 deletions
35
services/web/scripts/translations/checkCoverage.js
Normal file
35
services/web/scripts/translations/checkCoverage.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
const fs = require('fs')
|
||||
const Path = require('path')
|
||||
|
||||
const LOCALES = Path.join(__dirname, '../../locales')
|
||||
const SORT_BY_PROGRESS = process.argv.includes('--sort-by-progress')
|
||||
|
||||
function count(file) {
|
||||
return Object.keys(require(Path.join(LOCALES, file))).length
|
||||
}
|
||||
|
||||
async function main() {
|
||||
const EN = count('en.json')
|
||||
const rows = []
|
||||
|
||||
for (const file of await fs.promises.readdir(LOCALES)) {
|
||||
if (file === 'README.md') continue
|
||||
const n = count(file)
|
||||
const name = file.replace('.json', '')
|
||||
rows.push({
|
||||
name,
|
||||
done: n,
|
||||
missing: EN - n,
|
||||
progress: ((100 * n) / EN).toFixed(2).padStart(5, ' ') + '%',
|
||||
})
|
||||
}
|
||||
if (SORT_BY_PROGRESS) {
|
||||
rows.sort((a, b) => b.done - a.done)
|
||||
}
|
||||
console.table(rows)
|
||||
}
|
||||
|
||||
main().catch(error => {
|
||||
console.error(error)
|
||||
process.exit(1)
|
||||
})
|
|
@ -4,6 +4,7 @@ const { execSync } = require('child_process')
|
|||
|
||||
const EN_JSON = Path.join(__dirname, '../../locales/en.json')
|
||||
const CHECK = process.argv.includes('--check')
|
||||
const SYNC_NON_EN = process.argv.includes('--sync-non-en')
|
||||
|
||||
async function main() {
|
||||
const locales = JSON.parse(await fs.promises.readFile(EN_JSON, 'utf-8'))
|
||||
|
@ -82,6 +83,28 @@ async function main() {
|
|||
unusedKeys.push(key)
|
||||
}
|
||||
}
|
||||
|
||||
if (SYNC_NON_EN) {
|
||||
if (CHECK) {
|
||||
throw new Error('--check is incompatible with --sync-non-en')
|
||||
}
|
||||
const LOCALES = Path.join(__dirname, '../../locales')
|
||||
for (const name of await fs.promises.readdir(LOCALES)) {
|
||||
if (name === 'README.md') continue
|
||||
if (name === 'en.json') continue
|
||||
const path = Path.join(LOCALES, name)
|
||||
const locales = JSON.parse(await fs.promises.readFile(path, 'utf-8'))
|
||||
for (const key of Object.keys(locales)) {
|
||||
if (!found.has(key)) {
|
||||
delete locales[key]
|
||||
}
|
||||
}
|
||||
const sorted =
|
||||
JSON.stringify(locales, Object.keys(locales).sort(), 2) + '\n'
|
||||
await fs.promises.writeFile(path, sorted)
|
||||
}
|
||||
}
|
||||
|
||||
if (unusedKeys.length === 0) {
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue