|
|
@@ -18,12 +18,31 @@ const i18n = createI18n({
|
|
|
}
|
|
|
});
|
|
|
|
|
|
+// Helper for deep merging locale objects
|
|
|
+const deepMerge = (target: any, source: any) => {
|
|
|
+ for (const key in source) {
|
|
|
+ if (source[key] instanceof Object && key in target) {
|
|
|
+ deepMerge(target[key], source[key]);
|
|
|
+ } else {
|
|
|
+ target[key] = source[key];
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
export const loadAdminTranslations = async (lang?: string) => {
|
|
|
const targetLang = lang || (i18n.global as any).locale.value;
|
|
|
try {
|
|
|
// Dynamic import to keep admin translations in a separate chunk
|
|
|
const messages = await import(`./locales/${targetLang}.admin.json`);
|
|
|
- i18n.global.mergeLocaleMessage(targetLang, messages.default);
|
|
|
+
|
|
|
+ // Use manual deep merge instead of i18n.global.mergeLocaleMessage
|
|
|
+ // because mergeLocaleMessage might be shallow at the root level in some versions/configs
|
|
|
+ const currentMessages = i18n.global.getLocaleMessage(targetLang);
|
|
|
+ const newMessages = messages.default;
|
|
|
+
|
|
|
+ deepMerge(currentMessages, newMessages);
|
|
|
+ i18n.global.setLocaleMessage(targetLang, currentMessages);
|
|
|
+
|
|
|
} catch (error) {
|
|
|
console.error(`Failed to load admin translations for ${targetLang}`, error);
|
|
|
}
|