diff --git a/frontend/src/ts/test/british-english.ts b/frontend/src/ts/test/british-english.ts index 86c01b78f..2bc64285f 100644 --- a/frontend/src/ts/test/british-english.ts +++ b/frontend/src/ts/test/british-english.ts @@ -15,20 +15,29 @@ export async function getList(): Promise { export async function replace(word: string): Promise { const list = await getList(); - const replacement = list.find((a) => - word.match(RegExp(`^([\\W]*${a[0]}[\\W]*)$`, "gi")) - ); - return replacement - ? word.replace( - RegExp(`^(?:([\\W]*)(${replacement[0]})([\\W]*))$`, "gi"), - (_, $1, $2, $3) => - $1 + - ($2.charAt(0) === $2.charAt(0).toUpperCase() - ? $2 === $2.toUpperCase() - ? replacement[1].toUpperCase() - : capitalizeFirstLetterOfEachWord(replacement[1]) - : replacement[1]) + - $3 - ) - : word; + + if (word.includes("-")) { + //this handles hyphenated words (for example "cream-colored") to make sure + //we don't have to add every possible combination to the list + return ( + await Promise.all(word.split("-").map(async (w) => replace(w))) + ).join("-"); + } else { + const replacement = list.find((a) => + word.match(RegExp(`^([\\W]*${a[0]}[\\W]*)$`, "gi")) + ); + return replacement + ? word.replace( + RegExp(`^(?:([\\W]*)(${replacement[0]})([\\W]*))$`, "gi"), + (_, $1, $2, $3) => + $1 + + ($2.charAt(0) === $2.charAt(0).toUpperCase() + ? $2 === $2.toUpperCase() + ? replacement[1].toUpperCase() + : capitalizeFirstLetterOfEachWord(replacement[1]) + : replacement[1]) + + $3 + ) + : word; + } }