2022-03-21 06:26:25 -04:00
|
|
|
const fs = require('node:fs')
|
|
|
|
const path = require('node:path')
|
|
|
|
const typescript = require('typescript')
|
|
|
|
|
2021-02-10 04:50:06 -05:00
|
|
|
module.exports = {
|
|
|
|
input: [
|
2022-03-21 06:26:25 -04:00
|
|
|
'frontend/js/**/*.{js,jsx,ts,tsx}',
|
|
|
|
'modules/**/*.{js,jsx,ts,tsx}',
|
2021-04-27 03:52:58 -04:00
|
|
|
'!frontend/js/vendor/**',
|
2021-02-10 04:50:06 -05:00
|
|
|
],
|
|
|
|
output: './',
|
|
|
|
options: {
|
|
|
|
sort: true,
|
|
|
|
func: {
|
|
|
|
list: ['t'],
|
2021-04-27 03:52:58 -04:00
|
|
|
extensions: ['.js', '.jsx'],
|
2021-02-10 04:50:06 -05:00
|
|
|
},
|
|
|
|
trans: {
|
|
|
|
component: 'Trans',
|
|
|
|
i18nKey: 'i18nKey',
|
|
|
|
defaultsKey: 'defaults',
|
|
|
|
extensions: ['.js', '.jsx'],
|
2021-04-27 03:52:58 -04:00
|
|
|
fallbackKey: false,
|
2021-02-10 04:50:06 -05:00
|
|
|
},
|
|
|
|
resource: {
|
|
|
|
savePath: 'frontend/extracted-translations.json',
|
|
|
|
jsonIndent: 2,
|
2021-04-27 03:52:58 -04:00
|
|
|
lineEnding: '\n',
|
|
|
|
},
|
|
|
|
},
|
2022-03-21 06:26:25 -04:00
|
|
|
// adapted from https://github.com/nucleartux/i18next-scanner-typescript/blob/master/src/index.js
|
|
|
|
transform: function (file, enc, done) {
|
|
|
|
const { base, ext } = path.parse(file.path)
|
|
|
|
|
|
|
|
if (['.ts', '.tsx'].includes(ext) && !base.endsWith('.d.ts')) {
|
|
|
|
const content = fs.readFileSync(file.path, enc)
|
|
|
|
|
|
|
|
const { outputText } = typescript.transpileModule(content, {
|
|
|
|
compilerOptions: { target: 'es2018', jsx: 'preserve' },
|
|
|
|
fileName: base,
|
|
|
|
})
|
|
|
|
|
|
|
|
this.parser.parseTransFromString(outputText)
|
|
|
|
this.parser.parseFuncFromString(outputText)
|
|
|
|
}
|
|
|
|
|
|
|
|
done()
|
|
|
|
},
|
2021-02-10 04:50:06 -05:00
|
|
|
}
|