From 77950e48c76f4a3b29d01831d43039caba29888a Mon Sep 17 00:00:00 2001
From: wwf <1971391498@qq.com>
Date: 星期二, 18 十一月 2025 14:12:42 +0800
Subject: [PATCH] 修改
---
i18n/auto-gen-i18n.js | 27 ++++-----------------------
1 files changed, 4 insertions(+), 23 deletions(-)
diff --git a/i18n/auto-gen-i18n.js b/i18n/auto-gen-i18n.js
index a03b3aa..6b9c5e5 100644
--- a/i18n/auto-gen-i18n.js
+++ b/i18n/auto-gen-i18n.js
@@ -30,20 +30,15 @@
}
else {
try {
- const source = sourceObj[key]
- if (!source) {
+ if (!sourceObj[key]) {
targetObject[key] = ''
return
}
- // not support translate with '(' or ')'
- if (source.includes('(') || source.includes(')'))
- return
-
const { translation } = await translate(sourceObj[key], null, languageKeyMap[toLanguage])
targetObject[key] = translation
}
- catch {
- console.error(`Error translating "${sourceObj[key]}" to ${toLanguage}. Key: ${key}`)
+ catch (e) {
+ console.error(`Error translating ${sourceObj[key]}(${key}) to ${toLanguage}`)
}
}
}
@@ -57,16 +52,7 @@
async function autoGenTrans(fileName, toGenLanguage) {
const fullKeyFilePath = path.join(__dirname, targetLanguage, `${fileName}.ts`)
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)
@@ -96,12 +82,7 @@
await Promise.all(files.map(async (file) => {
await Promise.all(Object.keys(languageKeyMap).map(async (language) => {
- try {
- await autoGenTrans(file, language)
- }
- catch (e) {
- console.error(`Error translating ${file} to ${language}`, e)
- }
+ await autoGenTrans(file, language)
}))
}))
}
--
Gitblit v1.8.0