Kaynağa Gözat

Merge pull request #11674 from overleaf/jpa-check-extracted-translations-in-ci

[web] check extracted translations in CI

GitOrigin-RevId: 27e13f5fd1fe08db65b68ffbff639adb83d99f74
Jakob Ackermann 3 yıl önce
ebeveyn
işleme
663aace586

+ 21 - 0
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 <<MSG >&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 \

+ 15 - 0
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 = []