Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

prevent-translation-commits.js 1.6 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
  1. #!/usr/bin/env node
  2. // [start-readme]
  3. //
  4. // This script is run as a git precommit hook (installed by husky after npm install).
  5. // It detects changes to files the in the translations folder and prevents the commit
  6. // if any changes exist.
  7. //
  8. // [end-readme]
  9. require('dotenv').config()
  10. // Ignore this hook in GitHub Actions workflows
  11. if (process.env.CI) process.exit()
  12. // Allow this hook to be overriden with an environment variable
  13. if (process.env.ALLOW_TRANSLATION_COMMITS) process.exit()
  14. const { execSync } = require('child_process')
  15. const filenames = execSync('git diff --cached --name-only').toString().trim().split('\n')
  16. const localizedFilenames = filenames.filter(filename => filename.startsWith('translations/'))
  17. if (localizedFilenames.length) {
  18. console.error('\n✋ Uh oh! Detected changes to the following files in the `/translations` directory:')
  19. console.table(localizedFilenames.join('\n'))
  20. console.error('The content in this directory is managed by our Crowdin integration and should not be edited directly in the repo.')
  21. console.error('For more information on how the localization process works, see translations/README.md')
  22. console.error('\nIf you have accidentally edited these files, you can unstage these changes on the command line using `git restore --staged translations`\n')
  23. console.error('\nIf you are performing a merge from `main`, you should bypass this hook by using ` git commit --no-verify`\n')
  24. console.error('\nIf you need to edit translated files often, you can set `ALLOW_TRANSLATION_COMMITS=true` in your .env file.`\n')
  25. process.exit(1)
  26. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...