diff --git a/package.json b/package.json index ea76359d7d..d2eee548c3 100644 --- a/package.json +++ b/package.json @@ -54,8 +54,8 @@ "typecheck": "concurrently -n \"node,web\" -c \"cyan,magenta\" \"npm run typecheck:node\" \"npm run typecheck:web\"", "typecheck:node": "tsgo --noEmit -p tsconfig.node.json --composite false", "typecheck:web": "tsgo --noEmit -p tsconfig.web.json --composite false", - "check:i18n": "tsx scripts/check-i18n.ts", - "sync:i18n": "tsx scripts/sync-i18n.ts", + "check:i18n": "dotenv -e .env -- tsx scripts/check-i18n.ts", + "sync:i18n": "dotenv -e .env -- tsx scripts/sync-i18n.ts", "update:i18n": "dotenv -e .env -- tsx scripts/update-i18n.ts", "auto:i18n": "dotenv -e .env -- tsx scripts/auto-translate-i18n.ts", "update:languages": "tsx scripts/update-languages.ts", diff --git a/scripts/auto-translate-i18n.ts b/scripts/auto-translate-i18n.ts index ef42c8da41..6a90f5b23f 100644 --- a/scripts/auto-translate-i18n.ts +++ b/scripts/auto-translate-i18n.ts @@ -9,8 +9,9 @@ import * as path from 'path' const localesDir = path.join(__dirname, '../src/renderer/src/i18n/locales') const translateDir = path.join(__dirname, '../src/renderer/src/i18n/translate') -const baseLocale = 'zh-cn' +const baseLocale = process.env.BASE_LOCALE ?? 'zh-cn' const baseFileName = `${baseLocale}.json` +const baseLocalePath = path.join(__dirname, '../src/renderer/src/i18n/locales', baseFileName) type I18NValue = string | { [key: string]: I18NValue } type I18N = { [key: string]: I18NValue } @@ -105,6 +106,9 @@ const translateRecursively = async (originObj: I18N, systemPrompt: string): Prom } const main = async () => { + if (!fs.existsSync(baseLocalePath)) { + throw new Error(`${baseLocalePath} not found.`) + } const localeFiles = fs .readdirSync(localesDir) .filter((file) => file.endsWith('.json') && file !== baseFileName) diff --git a/scripts/check-i18n.ts b/scripts/check-i18n.ts index cb357aef09..5735474106 100644 --- a/scripts/check-i18n.ts +++ b/scripts/check-i18n.ts @@ -4,7 +4,7 @@ import * as path from 'path' import { sortedObjectByKeys } from './sort' const translationsDir = path.join(__dirname, '../src/renderer/src/i18n/locales') -const baseLocale = 'zh-cn' +const baseLocale = process.env.BASE_LOCALE ?? 'zh-cn' const baseFileName = `${baseLocale}.json` const baseFilePath = path.join(translationsDir, baseFileName) diff --git a/scripts/sync-i18n.ts b/scripts/sync-i18n.ts index aa13bddefd..6b58756a5d 100644 --- a/scripts/sync-i18n.ts +++ b/scripts/sync-i18n.ts @@ -5,7 +5,7 @@ import { sortedObjectByKeys } from './sort' const localesDir = path.join(__dirname, '../src/renderer/src/i18n/locales') const translateDir = path.join(__dirname, '../src/renderer/src/i18n/translate') -const baseLocale = 'zh-cn' +const baseLocale = process.env.BASE_LOCALE ?? 'zh-cn' const baseFileName = `${baseLocale}.json` const baseFilePath = path.join(localesDir, baseFileName)