🐛 fix: locale resolve bug with ESM module loading (#11018)

* 🐛 fix: simplify translation key access and add fallback logic

- Remove special handling for 'models' and 'providers' namespaces in create.ts
- Use flat key structure (direct object access) instead of nested get()
- Add fallback to default module when locale JSON is missing
- Add tests for missing key fallback behavior

* 🐛 fix: locale resolve bug with ESM module loading

Fix locale resolution in desktop and server environments by properly handling ESM module loading and adding fallback logic for translation namespaces.

Also move lexical from devDependencies to dependencies in builtin-tool-page-agent to fix type-check issues.
This commit is contained in:
Innei
2025-12-29 13:19:51 +08:00
committed by GitHub
parent 63224dd1a4
commit 770c87256b
8 changed files with 131 additions and 28 deletions

View File

@@ -175,6 +175,7 @@ export class I18nManager {
try {
logger.debug(`Loading namespace: ${lng}/${ns}`);
const resources = await loadResources(lng, ns);
this.i18n.addResourceBundle(lng, ns, resources, true, true);
return true;
} catch (error) {

View File

@@ -22,7 +22,9 @@ export const loadResources = async (lng: string, ns: string) => {
}
try {
return await import(`@/../../resources/locales/${lng}/${ns}.json`);
const { default: content } = await import(`@/../../resources/locales/${lng}/${ns}.json`);
return content;
} catch (error) {
console.error(`无法加载翻译文件: ${lng} - ${ns}`, error);
return {};