cherry-studio/i18next-scanner.config.js
icarus 2e60db80df feat(i18n): add i18next scanner configuration and script
Add i18next-scanner configuration file to automate translation key extraction
Include new 'i18n:scan' script in package.json to run the scanner
Update tsconfig and oxlintrc to include the new config file
2025-10-23 21:49:49 +08:00

62 lines
1.5 KiB
JavaScript

const fs = require('fs')
const chalk = require('chalk')
module.exports = {
compatibilityJSON: 'v4',
input: [
'src/**/*.{ts,tsx}',
// Use ! to filter out files or directories
'!**/node_modules/**'
],
output: './',
options: {
debug: true,
func: {
list: ['i18next.t', 'i18n.t'],
extensions: ['.ts', '.tsx']
},
lngs: ['en-us', 'zh-cn', 'zh-tw'],
ns: ['locale'],
defaultLng: 'en-us',
defaultNs: 'locale',
defaultValue: '__STRING_NOT_TRANSLATED__',
resource: {
loadPath: 'src/renderer/src/i18n/locales/{{lng}}.json',
savePath: 'src/renderer/src/i18n/locales/{{lng}}.json',
jsonIndent: 2,
lineEnding: '\n'
},
nsSeparator: false, // namespace separator
keySeparator: '.', // key separator
interpolation: {
prefix: '{{',
suffix: '}}'
},
metadata: {},
allowDynamicKeys: false
},
transform: function customTransform(file, enc, done) {
'use strict'
const parser = this.parser
const content = fs.readFileSync(file.path, enc)
let count = 0
parser.parseFuncFromString(content, { list: ['i18next._', 'i18next.__'] }, (key, options) => {
parser.set(
key,
Object.assign({}, options, {
nsSeparator: false,
keySeparator: false
})
)
++count
})
if (count > 0) {
console.log(`i18next-scanner: count=${chalk.cyan(count)}, file=${chalk.yellow(JSON.stringify(file.relative))}`)
}
done()
}
}