fix(csr): preserve translations across navigation
This commit is contained in:
@@ -380,6 +380,27 @@ export const NAV_RUNTIME = String.raw`
|
||||
var current = window.__wrnI18n || {};
|
||||
var translator = current.t;
|
||||
var setter = current.set;
|
||||
function mergeCatalog(base, update) {
|
||||
var output = {};
|
||||
Object.keys(base && typeof base === "object" ? base : {}).forEach(function (key) {
|
||||
var value = base[key];
|
||||
output[key] = value && typeof value === "object" && !Array.isArray(value)
|
||||
? mergeCatalog(value, {})
|
||||
: value;
|
||||
});
|
||||
Object.keys(update && typeof update === "object" ? update : {}).forEach(function (key) {
|
||||
var left = output[key];
|
||||
var right = update[key];
|
||||
output[key] = left && right && typeof left === "object" && typeof right === "object" && !Array.isArray(left) && !Array.isArray(right)
|
||||
? mergeCatalog(left, right)
|
||||
: right;
|
||||
});
|
||||
return output;
|
||||
}
|
||||
if (current.lang && current.lang === incoming.lang) {
|
||||
incoming.messages = mergeCatalog(current.messages, incoming.messages);
|
||||
incoming.fallbackMessages = mergeCatalog(current.fallbackMessages, incoming.fallbackMessages);
|
||||
}
|
||||
window.__wrnI18n = incoming;
|
||||
if (translator) window.__wrnI18n.t = translator;
|
||||
if (setter) window.__wrnI18n.set = setter;
|
||||
|
||||
Reference in New Issue
Block a user