You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

update-translation.js 889B

1234567891011121314151617181920212223242526272829303132333435363738
  1. /* eslint-disable */
  2. const fs = require('fs');
  3. const process = require('process');
  4. const traverse = require('traverse');
  5. const mainLang = require('./main.json');
  6. const [ targetLangFile ] = process.argv.slice(-1);
  7. if (!targetLangFile) {
  8. console.log('No target language file specified');
  9. process.exit(1);
  10. }
  11. const targetLang = require(`./${targetLangFile}`);
  12. const paths = traverse(mainLang).reduce(function(acc, item) {
  13. if (this.isLeaf) {
  14. acc.push(this.path);
  15. }
  16. return acc;
  17. }, []);
  18. const result = {};
  19. for (const path of paths) {
  20. if (traverse(targetLang).has(path)) {
  21. traverse(result).set(path, traverse(targetLang).get(path));
  22. } else {
  23. //console.log(`${path.join('.')} is missing`);
  24. traverse(result).set(path, '');
  25. }
  26. }
  27. const data = JSON.stringify(result, undefined, 4);
  28. fs.writeFileSync(`./${targetLangFile}`, data);