mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2026-01-06 15:34:06 +08:00
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:
parent
2c74f752a7
commit
e99c85bdfc
3 changed files with 17 additions and 8 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
1
frontend/src/ts/types/types.d.ts
vendored
1
frontend/src/ts/types/types.d.ts
vendored
|
|
@ -801,6 +801,7 @@ declare namespace MonkeyTypes {
|
|||
|
||||
interface Quote {
|
||||
text: string;
|
||||
britishText?: string;
|
||||
source: string;
|
||||
length: number;
|
||||
id: number;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue