mirror of
https://github.com/lobehub/lobehub.git
synced 2026-03-27 13:29:15 +07:00
🐛 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:
@@ -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) {
|
||||
|
||||
@@ -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 {};
|
||||
|
||||
Reference in New Issue
Block a user