i18n.js 512 B

1234567891011121314151617181920212223
  1. 'use strict';
  2. const { Pattern } = require('hexo-util');
  3. const { extname } = require('path');
  4. exports.process = file => {
  5. const { path } = file.params;
  6. const ext = extname(path);
  7. const name = path.substring(0, path.length - ext.length);
  8. const { i18n } = file.box;
  9. if (file.type === 'delete') {
  10. i18n.remove(name);
  11. return;
  12. }
  13. return file.render().then(data => {
  14. if (typeof data !== 'object') return;
  15. i18n.set(name, data);
  16. });
  17. };
  18. exports.pattern = new Pattern('languages/*path');