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

@ -43,7 +43,7 @@ async function translateMissingKeyDeeply(sourceObj, targetObject, toLanguage) {
targetObject[key] = translation
}
catch {
console.error(`Error translating ${sourceObj[key]}(${key}) to ${toLanguage}`)
console.error(`Error translating "${sourceObj[key]}" to ${toLanguage}. Key: ${key}`)
}
}
}
@ -59,6 +59,14 @@ async function autoGenTrans(fileName, toGenLanguage) {
const toGenLanguageFilePath = path.join(__dirname, toGenLanguage, `${fileName}.ts`)
// eslint-disable-next-line sonarjs/code-eval
const fullKeyContent = eval(transpile(fs.readFileSync(fullKeyFilePath, 'utf8')))
// if toGenLanguageFilePath is not exist, create it
if (!fs.existsSync(toGenLanguageFilePath)) {
fs.writeFileSync(toGenLanguageFilePath, `const translation = {
}
export default translation
`)
}
// To keep object format and format it for magicast to work: const translation = { ... } => export default {...}
const readContent = await loadFile(toGenLanguageFilePath)
const { code: toGenContent } = generateCode(readContent)