mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-25 03:10:08 +08:00
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
This commit is contained in:
parent
e5232b1fbb
commit
2e60db80df
61
i18next-scanner.config.js
Normal file
61
i18next-scanner.config.js
Normal file
@ -0,0 +1,61 @@
|
||||
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()
|
||||
}
|
||||
}
|
||||
@ -57,6 +57,7 @@
|
||||
"i18n:check": "dotenv -e .env -- tsx scripts/check-i18n.ts",
|
||||
"i18n:sync": "dotenv -e .env -- tsx scripts/sync-i18n.ts",
|
||||
"i18n:auto": "dotenv -e .env -- tsx scripts/auto-translate-i18n.ts",
|
||||
"i18n:scan": "i18next-scanner && yarn format",
|
||||
"update:languages": "tsx scripts/update-languages.ts",
|
||||
"test": "vitest run --silent",
|
||||
"test:main": "vitest run --project main",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user