checkSanitizeOptions.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. const Path = require('path')
  2. const fs = require('fs')
  3. const { sanitize } = require('./sanitize')
  4. async function main() {
  5. let ok = true
  6. const base = Path.join(__dirname, '/../../locales')
  7. for (const name of await fs.promises.readdir(base)) {
  8. if (name === 'README.md') continue
  9. const blob = await fs.promises.readFile(
  10. Path.join(__dirname, '/../../locales', name),
  11. 'utf-8'
  12. )
  13. const locales = JSON.parse(blob)
  14. for (const key of Object.keys(locales)) {
  15. const want = locales[key]
  16. const got = sanitize(locales[key])
  17. if (got !== want) {
  18. if (want === 'Editor & PDF' && got === 'Editor & PDF') {
  19. // Ignore this mismatch. React cannot handle escaped labels.
  20. continue
  21. }
  22. ok = false
  23. console.warn(`${name}: ${key}: want: ${want}`)
  24. console.warn(`${name}: ${key}: got: ${got}`)
  25. }
  26. }
  27. }
  28. if (!ok) {
  29. throw new Error('Check the logs, some values changed.')
  30. }
  31. }
  32. main()
  33. .then(() => {
  34. process.exit(0)
  35. })
  36. .catch(error => {
  37. console.error(error)
  38. process.exit(1)
  39. })