diff --git a/.i18nrc.cjs b/.i18nrc.cjs index a53543933..df3590444 100644 --- a/.i18nrc.cjs +++ b/.i18nrc.cjs @@ -1,4 +1,4 @@ -// This file is intentionally kept in CommonJS format (.cjs) +// This file is intentionally kept in CommonJS format (.cjs) // to resolve compatibility issues with dependencies that require CommonJS. // Do not convert this file to ESModule format unless all dependencies support it. const { defineConfig } = require('@lobehub/i18n-cli'); diff --git a/lint-staged.config.js b/lint-staged.config.js index 216d0674e..f5682f495 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -8,9 +8,11 @@ export default { 'tsc-strict' ], - './src/locales/*.json': (stagedFiles) => [ - 'lobe-i18n locale', - ...formatFiles(stagedFiles) + './src/locales/en.json': () => ['lobe-i18n locale'], + + './src/constants/coreSettings.ts': () => [ + 'tsx scripts/update-setting-locale.ts', + 'lobe-i18n locale' ] } diff --git a/scripts/update-setting-locale.ts b/scripts/update-setting-locale.ts new file mode 100644 index 000000000..601535495 --- /dev/null +++ b/scripts/update-setting-locale.ts @@ -0,0 +1,32 @@ +import fs from 'fs' +import { CORE_SETTINGS } from '../src/constants/coreSettings' + +interface SettingLocale { + name: string + tooltip?: string +} + +const extractLocaleStrings = (): Record => { + return Object.fromEntries( + CORE_SETTINGS.sort((a, b) => a.id.localeCompare(b.id)).map((setting) => [ + // '.' is not allowed in JSON keys, so we replace it with '_' + setting.id.replace(/\./g, '_'), + { + name: setting.name, + tooltip: setting.tooltip + } + ]) + ) +} + +const main = () => { + const localeStrings = extractLocaleStrings() + const localePath = './src/locales/en.json' + const globalLocale = JSON.parse(fs.readFileSync(localePath, 'utf-8')) + fs.writeFileSync( + localePath, + JSON.stringify({ ...globalLocale, settingsDialog: localeStrings }, null, 2) + ) +} + +main() diff --git a/src/components/dialog/content/setting/SettingItem.vue b/src/components/dialog/content/setting/SettingItem.vue index 83b4fcc0b..03df2f427 100644 --- a/src/components/dialog/content/setting/SettingItem.vue +++ b/src/components/dialog/content/setting/SettingItem.vue @@ -1,6 +1,6 @@