checkSanitizeOptions.js 1.1 KB

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