mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-03-13 07:23:39 +08:00
language specific punctuation
This commit is contained in:
parent
d36742b481
commit
9fe5d76745
1 changed files with 64 additions and 23 deletions
|
@ -217,9 +217,12 @@ export function setRandomQuote(rq) {
|
|||
randomQuote = rq;
|
||||
}
|
||||
|
||||
let spanishSentenceTracker = "";
|
||||
export function punctuateWord(previousWord, currentWord, index, maxindex) {
|
||||
let word = currentWord;
|
||||
|
||||
let currentLanguage = Config.language.split("_")[0];
|
||||
|
||||
if (Config.funbox === "58008") {
|
||||
if (currentWord.length > 3) {
|
||||
if (Math.random() < 0.75) {
|
||||
|
@ -233,10 +236,22 @@ export function punctuateWord(previousWord, currentWord, index, maxindex) {
|
|||
Misc.getLastChar(previousWord) == "." ||
|
||||
Misc.getLastChar(previousWord) == "?" ||
|
||||
Misc.getLastChar(previousWord) == "!") &&
|
||||
Config.language.split("_")[0] != "code"
|
||||
currentLanguage != "code"
|
||||
) {
|
||||
//always capitalise the first word or if there was a dot unless using a code alphabet
|
||||
|
||||
word = Misc.capitalizeFirstLetter(word);
|
||||
|
||||
if (currentLanguage == "spanish" || currentLanguage == "catalan") {
|
||||
let rand = Math.random();
|
||||
if (rand > 0.9) {
|
||||
word = "¿" + word;
|
||||
spanishSentenceTracker = "?";
|
||||
} else if (rand > 0.8) {
|
||||
word = "¡" + word;
|
||||
spanishSentenceTracker = "!";
|
||||
}
|
||||
}
|
||||
} else if (
|
||||
(Math.random() < 0.1 &&
|
||||
Misc.getLastChar(previousWord) != "." &&
|
||||
|
@ -244,35 +259,50 @@ export function punctuateWord(previousWord, currentWord, index, maxindex) {
|
|||
index != maxindex - 2) ||
|
||||
index == maxindex - 1
|
||||
) {
|
||||
let rand = Math.random();
|
||||
if (rand <= 0.8) {
|
||||
word += ".";
|
||||
} else if (rand > 0.8 && rand < 0.9) {
|
||||
if (Config.language.split("_")[0] == "french") {
|
||||
word = "?";
|
||||
} else {
|
||||
word += "?";
|
||||
if (currentLanguage == "spanish" || currentLanguage == "catalan") {
|
||||
if (spanishSentenceTracker == "?" || spanishSentenceTracker == "!") {
|
||||
word += spanishSentenceTracker;
|
||||
spanishSentenceTracker = "";
|
||||
}
|
||||
} else {
|
||||
if (Config.language.split("_")[0] == "french") {
|
||||
word = "!";
|
||||
let rand = Math.random();
|
||||
if (rand <= 0.8) {
|
||||
word += ".";
|
||||
} else if (rand > 0.8 && rand < 0.9) {
|
||||
if (currentLanguage == "french") {
|
||||
word = "?";
|
||||
} else if (
|
||||
currentLanguage == "arabic" ||
|
||||
currentLanguage == "persian" ||
|
||||
currentLanguage == "urdu"
|
||||
) {
|
||||
word += "؟";
|
||||
} else if (currentLanguage == "greek") {
|
||||
word += ";";
|
||||
} else {
|
||||
word += "?";
|
||||
}
|
||||
} else {
|
||||
word += "!";
|
||||
if (currentLanguage == "french") {
|
||||
word = "!";
|
||||
} else {
|
||||
word += "!";
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (
|
||||
Math.random() < 0.01 &&
|
||||
Misc.getLastChar(previousWord) != "," &&
|
||||
Misc.getLastChar(previousWord) != "." &&
|
||||
Config.language.split("_")[0] !== "russian"
|
||||
currentLanguage !== "russian"
|
||||
) {
|
||||
word = `"${word}"`;
|
||||
} else if (
|
||||
Math.random() < 0.011 &&
|
||||
Misc.getLastChar(previousWord) != "," &&
|
||||
Misc.getLastChar(previousWord) != "." &&
|
||||
Config.language.split("_")[0] !== "russian" &&
|
||||
Config.language.split("_")[0] !== "ukrainian"
|
||||
currentLanguage !== "russian" &&
|
||||
currentLanguage !== "ukrainian"
|
||||
) {
|
||||
word = `'${word}'`;
|
||||
} else if (
|
||||
|
@ -280,7 +310,7 @@ export function punctuateWord(previousWord, currentWord, index, maxindex) {
|
|||
Misc.getLastChar(previousWord) != "," &&
|
||||
Misc.getLastChar(previousWord) != "."
|
||||
) {
|
||||
if (Config.language.split("_")[0] == "code") {
|
||||
if (currentLanguage == "code") {
|
||||
let r = Math.random();
|
||||
if (r < 0.25) {
|
||||
word = `(${word})`;
|
||||
|
@ -295,8 +325,11 @@ export function punctuateWord(previousWord, currentWord, index, maxindex) {
|
|||
word = `(${word})`;
|
||||
}
|
||||
} else if (Math.random() < 0.013) {
|
||||
if (Config.language.split("_")[0] == "french") {
|
||||
if (currentLanguage == "french") {
|
||||
word = ":";
|
||||
}
|
||||
if (currentLanguage == "greek") {
|
||||
word = "·";
|
||||
} else {
|
||||
word += ":";
|
||||
}
|
||||
|
@ -313,17 +346,25 @@ export function punctuateWord(previousWord, currentWord, index, maxindex) {
|
|||
Misc.getLastChar(previousWord) != "." &&
|
||||
Misc.getLastChar(previousWord) != ";"
|
||||
) {
|
||||
if (Config.language.split("_")[0] == "french") {
|
||||
if (currentLanguage == "french") {
|
||||
word = ";";
|
||||
}
|
||||
if (currentLanguage == "greek") {
|
||||
word = "·";
|
||||
} else {
|
||||
word += ";";
|
||||
}
|
||||
} else if (Math.random() < 0.2 && Misc.getLastChar(previousWord) != ",") {
|
||||
word += ",";
|
||||
} else if (
|
||||
Math.random() < 0.25 &&
|
||||
Config.language.split("_")[0] == "code"
|
||||
) {
|
||||
if (
|
||||
currentLanguage == "arabic" ||
|
||||
currentLanguage == "urdu" ||
|
||||
currentLanguage == "persian"
|
||||
) {
|
||||
word += "،";
|
||||
} else {
|
||||
word += ",";
|
||||
}
|
||||
} else if (Math.random() < 0.25 && currentLanguage == "code") {
|
||||
let specials = ["{", "}", "[", "]", "(", ")", ";", "=", "+", "%", "/"];
|
||||
|
||||
word = specials[Math.floor(Math.random() * 10)];
|
||||
|
|
Loading…
Reference in a new issue