fix: auto translate failed when there is a new file in english (#19671)

This commit is contained in:
Joel 2025-05-14 16:01:35 +08:00 • committed by GitHub
commit 1c91736a6d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
237 changed files with 7543 additions and 23 deletions

View file

@ -27,9 +27,14 @@ async function getKeysFromLanuage(language) {
// console.log(camelCaseFileName)
const content = fs.readFileSync(filePath, 'utf8')
// eslint-disable-next-line sonarjs/code-eval
const translation = eval(transpile(content))
const translationObj = eval(transpile(content))
// console.log(translation)
const keys = Object.keys(translation)
if(!translationObj || typeof translationObj !== 'object') {
console.error(`Error parsing file: ${filePath}`)
reject(new Error(`Error parsing file: ${filePath}`))
return
}
const keys = Object.keys(translationObj)
const nestedKeys = []
const iterateKeys = (obj, prefix = '') => {
for (const key in obj) {
@ -39,7 +44,7 @@ async function getKeysFromLanuage(language) {
iterateKeys(obj[key], nestedKey)
}
}
iterateKeys(translation)
iterateKeys(translationObj)
allKeys = [...keys, ...nestedKeys].map(
key => `${camelCaseFileName}.${key}`,