Fix issues with the localizer's replacement to be more reliable
This commit is contained in:
parent
e2579e12f8
commit
f8364888f2
1 changed files with 13 additions and 5 deletions
|
|
@ -18,12 +18,20 @@ export function localizer(key, args = {}, depth = 0) {
|
||||||
return localized;
|
return localized;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Helps prevent recursion on the same key so that we aren't doing excess work.
|
||||||
|
*/
|
||||||
|
const localizedSubkeys = new Map();
|
||||||
for (const match of subkeys) {
|
for (const match of subkeys) {
|
||||||
const subkey = match.groups.key;
|
const subkey = match.groups.key;
|
||||||
localized =
|
if (localizedSubkeys.has(subkey)) continue;
|
||||||
localized.slice(0, match.index)
|
localizedSubkeys.set(subkey, localizer(subkey, args, depth + 1));
|
||||||
+ localizer(subkey, args, depth + 1)
|
|
||||||
+ localized.slice(match.index + subkey.length + 1)
|
|
||||||
};
|
};
|
||||||
return localized;
|
|
||||||
|
return localized.replace(
|
||||||
|
localizerConfig.subKeyPattern,
|
||||||
|
(_fullMatch, subkey) => {
|
||||||
|
return localizedSubkeys.get(subkey);
|
||||||
|
}
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue