|
|
@@ -40,28 +40,28 @@ const deepMerge = (target: any, source: any) => {
|
|
|
|
|
|
export const loadAdminTranslations = async (lang?: string) => {
|
|
|
const targetLang = lang || (i18n.global as any).locale.value;
|
|
|
- console.log(`[i18n] Loading admin translations for: ${targetLang}`);
|
|
|
+ console.log(`[i18n] Loading admin translations for: ${targetLang}...`);
|
|
|
try {
|
|
|
const module = await import(`./locales/${targetLang}.admin.json`);
|
|
|
let newMessages = module.default || module;
|
|
|
|
|
|
- // Ensure we are working with the admin sub-key if it exists at root,
|
|
|
- // otherwise wrap it if it seems to be just the content
|
|
|
+ // Ensure the structure is correct: { admin: { ... } }
|
|
|
if (!newMessages.admin && (newMessages.tabs || newMessages.actions || newMessages.managementCenter)) {
|
|
|
newMessages = { admin: newMessages };
|
|
|
}
|
|
|
|
|
|
+ // getLocaleMessage returns a copy in Composer mode
|
|
|
const currentMessages = i18n.global.getLocaleMessage(targetLang);
|
|
|
|
|
|
- // Perform merge directly on the current messages object
|
|
|
- deepMerge(currentMessages, newMessages);
|
|
|
+ // Perform deep merge
|
|
|
+ const merged = deepMerge({ ...currentMessages }, newMessages);
|
|
|
|
|
|
- // Re-set to trigger reactivity
|
|
|
- i18n.global.setLocaleMessage(targetLang, currentMessages);
|
|
|
+ // Explicitly set the updated message object back to the locale
|
|
|
+ i18n.global.setLocaleMessage(targetLang, merged);
|
|
|
|
|
|
- console.log(`[i18n] Admin translations successfully merged for: ${targetLang}`);
|
|
|
+ console.log(`[i18n] Admin translations successfully loaded and merged for: ${targetLang}`);
|
|
|
} catch (error) {
|
|
|
- console.error(`[i18n] Failed to load admin translations for ${targetLang}`, error);
|
|
|
+ console.error(`[i18n] Failed to load admin translations for ${targetLang}:`, error);
|
|
|
}
|
|
|
};
|
|
|
|