overleaf/services/web/i18next-scanner.config.js
Jakob Ackermann afca054a22 Merge pull request #18136 from overleaf/jpa-fix-i18n-scanner-glob
[web] instruct i18next-scanner to look at frontend code only

GitOrigin-RevId: 094cc571810f142b535d0813c2002944a0e1ab9d
2024-04-29 08:04:45 +00:00

49 lines
1.3 KiB
JavaScript

const fs = require('node:fs')
const path = require('node:path')
const typescript = require('typescript')
module.exports = {
input: [
'frontend/js/**/*.{js,jsx,ts,tsx}',
'modules/*/frontend/js/**/*.{js,jsx,ts,tsx}',
'!frontend/js/vendor/**',
],
output: './',
options: {
sort: true,
func: {
list: ['t', 'phrase'],
extensions: ['.js', '.jsx'],
},
trans: {
component: 'Trans',
i18nKey: 'i18nKey',
defaultsKey: 'defaults',
extensions: ['.js', '.jsx'],
fallbackKey: false,
},
resource: {
savePath: 'frontend/extracted-translations.json',
jsonIndent: 2,
lineEnding: '\n',
},
},
// 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()
},
}