impr(british english): replace double quotes with single quotes

closes #7015
This commit is contained in:
Miodec 2025-10-15 12:54:43 +02:00
parent be106b8f1c
commit 015252120f
2 changed files with 30 additions and 0 deletions

View file

@ -38,5 +38,30 @@ describe("british-english", () => {
"armour-flavouring"
);
});
it("should convert double quotes to single quotes", async () => {
await expect(replace('"hello"', "")).resolves.toEqual("'hello'");
await expect(replace('"test"', "")).resolves.toEqual("'test'");
await expect(replace('"Hello World"', "")).resolves.toEqual(
"'Hello World'"
);
});
it("should convert double quotes and replace words", async () => {
await expect(replace('"color"', "")).resolves.toEqual("'colour'");
await expect(replace('"math"', "")).resolves.toEqual("'maths'");
await expect(replace('"Color"', "")).resolves.toEqual("'Colour'");
});
it("should handle multiple double quotes in a word", async () => {
await expect(
replace('He said "hello" and "goodbye"', "")
).resolves.toEqual("He said 'hello' and 'goodbye'");
});
it("should not affect words without double quotes", async () => {
await expect(replace("'hello'", "")).resolves.toEqual("'hello'");
await expect(replace("test", "")).resolves.toEqual("test");
});
});
});

View file

@ -658,6 +658,11 @@ export async function replace(
word: string,
previousWord: string
): Promise<string> {
// Convert American-style double quotes to British-style single quotes
if (word.includes('"')) {
word = word.replace(/"/g, "'");
}
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