mirror of
https://gitlab.com/PronounsPage/PronounsPage.git
synced 2025-09-22 12:03:25 -04:00
(polyfill) replace (?<) lookbehind group with custom split function
This commit is contained in:
parent
1a12dce4a8
commit
eb9151112a
@ -66,6 +66,29 @@ const buildPronounFromTemplate = (key: string, template: PronounTemplate): Prono
|
||||
);
|
||||
};
|
||||
|
||||
const splitSlashes = (path: string): string[] => {
|
||||
const chunks = [];
|
||||
let escape = false;
|
||||
let currentChunk = '';
|
||||
for (const character of path) {
|
||||
if (escape) {
|
||||
currentChunk += `\`${character}`;
|
||||
escape = false;
|
||||
} else {
|
||||
if (character === '`') {
|
||||
escape = true;
|
||||
} else if (character === '/') {
|
||||
chunks.push(currentChunk);
|
||||
currentChunk = '';
|
||||
} else {
|
||||
currentChunk += character;
|
||||
}
|
||||
}
|
||||
}
|
||||
chunks.push(currentChunk);
|
||||
return chunks;
|
||||
};
|
||||
|
||||
const isModifier = (chunk: string, key: string, translator: Translator): boolean => {
|
||||
// use both locale and base translations to ensure backwards compatibility if key gets translated
|
||||
return chunk === `:${translator.translate(key)}` || chunk === `:${translator.get(key, false, true)}`;
|
||||
@ -83,7 +106,7 @@ const extractModifierValue = (chunk: string, key: string, translator: Translator
|
||||
};
|
||||
|
||||
const buildPronounFromSlashes = (config: Config, path: string, translator: Translator): Pronoun | null => {
|
||||
const chunks = path.split(/(?<!`)\//);
|
||||
const chunks = splitSlashes(path);
|
||||
let plural = false;
|
||||
let pluralHonorific = false;
|
||||
let description = '';
|
||||
|
Loading…
x
Reference in New Issue
Block a user