From 663aace58657c4d33ac4b0c134e49d1483cb7395 Mon Sep 17 00:00:00 2001 From: Jakob Ackermann Date: Tue, 7 Feb 2023 14:58:25 +0000 Subject: [PATCH] Merge pull request #11674 from overleaf/jpa-check-extracted-translations-in-ci [web] check extracted translations in CI GitOrigin-RevId: 27e13f5fd1fe08db65b68ffbff639adb83d99f74 --- services/web/bin/lint_locales | 21 +++++++++++++++++++ .../translations/cleanupUnusedLocales.js | 15 +++++++++++++ 2 files changed, 36 insertions(+) diff --git a/services/web/bin/lint_locales b/services/web/bin/lint_locales index ea4d30e803..86dd5145ce 100755 --- a/services/web/bin/lint_locales +++ b/services/web/bin/lint_locales @@ -8,6 +8,27 @@ node scripts/translations/sort.js --check # Ensure all locales are still in use node scripts/translations/cleanupUnusedLocales.js --check +# Ensure all locales used in the frontend are tracked +OUTPUT=data/dumpFolder/i18next-scanner +trap "rm -rf $OUTPUT" EXIT +npx i18next-scanner --output "$OUTPUT" +ACTUAL=frontend/extracted-translations.json +EXPECTED="$OUTPUT/frontend/extracted-translations.json" +if ! diff "$ACTUAL" "$EXPECTED"; then + cat <&2 + +services/web/frontend/extracted-translations.json is not up-to-date. + +--- +Try running: + + internal$ bin/run web npm run extract-translations + +--- +MSG + exit 1 +fi + # Ensure no locales contain single quotes. LOCALES_WITH_SINGLE_QUOTE=$(\ grep \ diff --git a/services/web/scripts/translations/cleanupUnusedLocales.js b/services/web/scripts/translations/cleanupUnusedLocales.js index 2490b081cb..6489a8447b 100644 --- a/services/web/scripts/translations/cleanupUnusedLocales.js +++ b/services/web/scripts/translations/cleanupUnusedLocales.js @@ -6,12 +6,23 @@ 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') +const COUNT_SUFFIXES = [ + '_plural', + '_zero', + '_one', + '_two', + '_few', + '_many', + '_other', +] + async function main() { const locales = JSON.parse(await fs.promises.readFile(EN_JSON, 'utf-8')) const src = execSync( // - find all the app source files in web // - exclude data files + // - exclude list of locales used in frontend // - exclude locales files // - exclude public assets // - exclude third-party dependencies @@ -19,6 +30,7 @@ async function main() { ` find . -type f \ -not -path './data/*' \ + -not -path './frontend/extracted-translations.json' \ -not -path './locales/*' \ -not -path './public/*' \ -not -path '*node_modules/*' \ @@ -75,6 +87,9 @@ async function main() { let m while ((m = matcher.exec(src))) { found.add(m[0]) + for (const suffix of COUNT_SUFFIXES) { + found.add(m[0] + suffix) + } } const unusedKeys = []