impr(british english): add support for british quote variations

This helps in cases where a simple word replacement is not enough.
Some words (like practice/se) have different spelling depending on if its a verb or noun

part of #4747
This commit is contained in:
Miodec 2023-11-01 13:49:23 +00:00
parent 2c74f752a7
commit e99c85bdfc
3 changed files with 17 additions and 8 deletions

View file

@ -2,8 +2,9 @@ import { randomElementFromArray, shuffle } from "../utils/misc";
import { subscribe } from "../observables/config-event";
import * as DB from "../db";
interface Quote {
interface JsonQuote {
text: string;
britishText?: string;
source: string;
length: number;
id: number;
@ -11,7 +12,7 @@ interface Quote {
interface QuoteData {
language: string;
quotes: Quote[];
quotes: JsonQuote[];
groups: number[][];
}
@ -63,9 +64,10 @@ class QuotesController {
};
// Transform JSON Quote schema to MonkeyTypes Quote schema
data.quotes.forEach((quote: Quote) => {
data.quotes.forEach((quote: JsonQuote) => {
const monkeyTypeQuote: MonkeyTypes.Quote = {
text: quote.text,
britishText: quote.britishText,
source: quote.source,
length: quote.length,
id: quote.id,

View file

@ -311,10 +311,11 @@ async function applyBritishEnglishToWord(
word: string,
previousWord: string
): Promise<string> {
if (Config.britishEnglish && /english/.test(Config.language)) {
word = await BritishEnglish.replace(word, previousWord);
}
return word;
if (!Config.britishEnglish) return word;
if (!/english/.test(Config.language)) return word;
if (Config.mode === "quote" && TestWords.randomQuote.britishText) return word;
return await BritishEnglish.replace(word, previousWord);
}
function applyLazyModeToWord(
@ -591,7 +592,12 @@ async function generateQuoteWords(
rq.text = rq.text.replace(/( *(\r\n|\r|\n) *)/g, "\n ");
rq.text = rq.text.replace(/…/g, "...");
rq.text = rq.text.trim();
rq.textSplit = rq.text.split(" ");
if (rq.britishText && Config.britishEnglish) {
rq.textSplit = rq.britishText.split(" ");
} else {
rq.textSplit = rq.text.split(" ");
}
TestWords.setRandomQuote(rq);

View file

@ -801,6 +801,7 @@ declare namespace MonkeyTypes {
interface Quote {
text: string;
britishText?: string;
source: string;
length: number;
id: number;