From aa6e753b3520acd208d8d718362d5ac7aaa773bb Mon Sep 17 00:00:00 2001 From: chenos Date: Mon, 25 Mar 2024 09:46:45 +0800 Subject: [PATCH] fix: update the locale file requires a reboot --- packages/core/server/src/locale/locale.ts | 3 +++ packages/core/server/src/locale/resource.ts | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/core/server/src/locale/locale.ts b/packages/core/server/src/locale/locale.ts index d605ba5a4..0cf80f285 100644 --- a/packages/core/server/src/locale/locale.ts +++ b/packages/core/server/src/locale/locale.ts @@ -67,6 +67,9 @@ export class Locale { async getCacheResources(lang: string) { this.resourceCached.set(lang, true); + if (process.env.APP_ENV !== 'production') { + await this.cache.reset(); + } return await this.wrapCache(`resources:${lang}`, () => this.getResources(lang)); } diff --git a/packages/core/server/src/locale/resource.ts b/packages/core/server/src/locale/resource.ts index f9d7a56f7..43351be0a 100644 --- a/packages/core/server/src/locale/resource.ts +++ b/packages/core/server/src/locale/resource.ts @@ -25,7 +25,10 @@ export const getResource = (packageName: string, lang: string, isPlugin = true) for (const prefix of prefixes) { try { const file = `${packageName}/${prefix}/locale/${lang}`; - require.resolve(file); + const f = require.resolve(file); + if (process.env.APP_ENV !== 'production') { + delete require.cache[f]; + } const resource = requireModule(file); resources.push(resource); } catch (error) {