lint_locales 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/bash
  2. set -e
  3. # Ensure all locale files are sorted.
  4. node scripts/translations/sort.js --check
  5. # Ensure all locales are still in use
  6. node scripts/translations/cleanupUnusedLocales.js --check
  7. # Ensure all locales used in the frontend are tracked
  8. OUTPUT=data/dumpFolder/i18next-scanner
  9. trap "rm -rf $OUTPUT" EXIT
  10. npx i18next-scanner --output "$OUTPUT"
  11. ACTUAL=frontend/extracted-translations.json
  12. EXPECTED="$OUTPUT/frontend/extracted-translations.json"
  13. if ! diff "$ACTUAL" "$EXPECTED"; then
  14. cat <<MSG >&2
  15. services/web/frontend/extracted-translations.json is not up-to-date.
  16. ---
  17. Try running:
  18. internal$ bin/run web npm run extract-translations
  19. ---
  20. MSG
  21. exit 1
  22. fi
  23. # Ensure no locales contain single quotes.
  24. LOCALES_WITH_SINGLE_QUOTE=$(\
  25. grep \
  26. --files-with-matches \
  27. --recursive locales/ \
  28. --regex "'" \
  29. || true
  30. )
  31. for file in ${LOCALES_WITH_SINGLE_QUOTE}; do
  32. cat <<MSG >&2
  33. ERROR: $file contains a locale with a single quote.
  34. ---
  35. $(grep "$file" --regex "'")
  36. ---
  37. Using single quotes in locales can lead to Angular XSS.
  38. You will need to replace the quote with a similar looking character.
  39. ’ (\u2019) is a good candidate.
  40. Links:
  41. - https://en.wikipedia.org/wiki/Right_single_quotation_mark
  42. - https://github.com/overleaf/issues/issues/4478
  43. MSG
  44. exit 1
  45. done