i18next-scanner.config.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. const fs = require('fs');
  2. const path = require('path');
  3. const typescript = require('typescript');
  4. module.exports = {
  5. input: [
  6. 'packages/*/src/**/*.{ts,tsx}',
  7. // Use ! to filter out files or directories
  8. '!packages/*/src/**/*.spec.{ts,tsx}',
  9. '!packages/*/src/i18n/**',
  10. '!**/node_modules/**'
  11. ],
  12. output: './',
  13. options: {
  14. debug: true,
  15. func: {
  16. list: ['t', 'i18next.t', 'i18n.t'],
  17. extensions: ['.tsx']
  18. },
  19. trans: {
  20. component: 'Trans'
  21. },
  22. lngs: ['en'],
  23. defaultLng: 'en',
  24. ns: [
  25. 'app-123code',
  26. 'app-accounts',
  27. 'app-address-book',
  28. 'app-claims',
  29. 'app-contracts',
  30. 'app-council',
  31. 'app-dashboard',
  32. 'app-democracy',
  33. 'app-explorer',
  34. 'app-extrinsics',
  35. 'app-generic-asset',
  36. 'app-js',
  37. 'app-parachains',
  38. 'app-settings',
  39. 'app-staking',
  40. 'app-storage',
  41. 'app-sudo',
  42. 'app-tech-comm',
  43. 'app-toolbox',
  44. 'app-transfer',
  45. 'app-treasury',
  46. 'apps',
  47. 'apps-routing',
  48. 'react-api',
  49. 'react-components',
  50. 'react-params',
  51. 'react-query',
  52. 'react-signer',
  53. 'ui'
  54. ],
  55. defaultNs: 'ui',
  56. resource: {
  57. loadPath: 'packages/apps/public/locales/{{lng}}/{{ns}}.json',
  58. savePath: 'packages/apps/public/locales/{{lng}}/{{ns}}.json',
  59. jsonIndent: 2,
  60. lineEnding: '\n'
  61. },
  62. nsSeparator: false, // namespace separator
  63. keySeparator: false // key separator
  64. },
  65. transform: function transform (file, enc, done) {
  66. const { ext } = path.parse(file.path);
  67. if (ext === '.tsx') {
  68. const content = fs.readFileSync(file.path, enc);
  69. const { outputText } = typescript.transpileModule(content, {
  70. compilerOptions: {
  71. target: 'es2018'
  72. },
  73. fileName: path.basename(file.path)
  74. });
  75. const parserHandler = (key, options) => {
  76. options.defaultValue = key;
  77. options.ns = /packages\/(.*?)\/src/g.exec(file.path)[1];
  78. this.parser.set(key, options);
  79. };
  80. this.parser.parseFuncFromString(outputText, parserHandler);
  81. }
  82. done();
  83. }
  84. };