i18next-scanner.config.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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-toolbox',
  43. 'app-transfer',
  44. 'app-treasury',
  45. 'apps',
  46. 'apps-routing',
  47. 'react-api',
  48. 'react-components',
  49. 'react-params',
  50. 'react-query',
  51. 'react-signer',
  52. 'ui'
  53. ],
  54. defaultNs: 'ui',
  55. resource: {
  56. loadPath: 'packages/apps/public/locales/{{lng}}/{{ns}}.json',
  57. savePath: 'packages/apps/public/locales/{{lng}}/{{ns}}.json',
  58. jsonIndent: 2,
  59. lineEnding: '\n'
  60. },
  61. nsSeparator: false, // namespace separator
  62. keySeparator: false // key separator
  63. },
  64. transform: function transform (file, enc, done) {
  65. const { ext } = path.parse(file.path);
  66. if (ext === '.tsx') {
  67. const content = fs.readFileSync(file.path, enc);
  68. const { outputText } = typescript.transpileModule(content, {
  69. compilerOptions: {
  70. target: 'es2018'
  71. },
  72. fileName: path.basename(file.path)
  73. });
  74. const parserHandler = (key, options) => {
  75. options.defaultValue = key;
  76. options.ns = /packages\/(.*?)\/src/g.exec(file.path)[1];
  77. this.parser.set(key, options);
  78. };
  79. this.parser.parseFuncFromString(outputText, parserHandler);
  80. }
  81. done();
  82. }
  83. };