language.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. 'use strict';
  2. const Fs = require('fs');
  3. const Path = require('path');
  4. let template = Fs.readFileSync(Path.join(__dirname, './template.txt'), 'utf-8');
  5. /**
  6. * 创建新的语言包
  7. * @param {string} name
  8. * @return {Promise}
  9. */
  10. let create = function (name) {
  11. let js = template.replace('{{name}}', name);
  12. let url = `db://assets/resources/i18n/${name}.js`;
  13. return new Promise((resolve, reject) => {
  14. Editor.assetdb.create(url, js, (error) => {
  15. if (error) {
  16. Editor.assetdb.error('Failed to create asset %s, %s', url, error.stack);
  17. reject();
  18. return;
  19. }
  20. resolve();
  21. });
  22. });
  23. };
  24. /**
  25. * 删除语言包
  26. * @param {string} name
  27. */
  28. let remove = function (name) {
  29. let url = `db://assets/resources/i18n/${name}.js`;
  30. return new Promise((resolve, reject) => {
  31. Editor.assetdb.delete([url], (error, results) => {
  32. if (error) {
  33. Editor.assetdb.error('Failed to delete asset %s, %s', path, error.stack);
  34. reject();
  35. return;
  36. }
  37. resolve();
  38. });
  39. });
  40. };
  41. exports.create = create;
  42. exports.remove = remove;