beginning multi language quote support

This commit is contained in:
Miodec 2021-01-13 04:19:46 +00:00
parent 87d6366e19
commit 2035e8478a
2 changed files with 29 additions and 15 deletions

View file

@ -441,28 +441,41 @@ async function initWords() {
config.language = "english";
}
if (config.mode === "quote" && quotes === null) {
if (config.mode === "quote" && (quotes === null || quotes.language !== config.language.replace(/_\d*k$/g,''))) {
if(config.language.split('_')[0] !== "code"){
setLanguage(config.language.replace(/_\d*k$/g,'').split('_')[0],true);
}
showBackgroundLoader();
$.ajax({
url: "quotes/english.json",
url: `quotes/${config.language.split("_")[0]}.json`,
async: false,
success: function (data) {
hideBackgroundLoader();
quotes = data;
quotes.groups.forEach((qg, i) => {
let lower = qg[0];
let upper = qg[1];
quotes.groups[i] = quotes.quotes.filter((q) => {
if (q.length >= lower && q.length <= upper) {
q.group = i;
return true;
} else {
return false;
}
try{
quotes = data;
quotes.groups.forEach((qg, i) => {
let lower = qg[0];
let upper = qg[1];
quotes.groups[i] = quotes.quotes.filter((q) => {
if (q.length >= lower && q.length <= upper) {
q.group = i;
return true;
} else {
return false;
}
});
});
});
quotes.quotes = [];
quotes.quotes = [];
}catch(e){
console.error(e);
Misc.showNotification(`No ${config.language.replace(/_\d*k$/g,'')} quotes found`,3000);
return;
}
},
error: (e) => {
Misc.showNotification(`Error while loading ${config.language.replace(/_\d*k$/g,'')} quotes: ${e}`, 5000);
return;
}
});
}

View file

@ -1,4 +1,5 @@
{
"language": "english",
"groups": [
[0, 100],
[101, 300],