From: Mischa POSLAWSKY Date: Mon, 15 Nov 2021 16:43:40 +0000 (+0100) Subject: word: common language handling in quiz X-Git-Tag: v1.13~92 X-Git-Url: http://git.shiar.nl/sheet.git/commitdiff_plain/0f3a55ca3cfa02e2446a20dc050d04490b23bb8d word: common language handling in quiz Replace hardcoded nl include by same ?lang result as overview. --- diff --git a/word.plp b/word.plp index 64a093f..41d2bd3 100644 --- a/word.plp +++ b/word.plp @@ -1,5 +1,8 @@ <(common.inc.plp)><: +our $lang = $get{lang} || 'en'; +our $wordlistbase = "data/wordlist.$lang"; + if ($Request and $Request =~ m{\A([^/]+)}) { my $page = "word/$1.plp"; utf8::downgrade($page); # unicode filename breaks contents encoding @@ -9,8 +12,7 @@ if ($Request and $Request =~ m{\A([^/]+)}) { } } -my $lang = $get{lang} || 'en'; -my $wordlist = "data/wordlist.$lang.inc.pl"; +my $wordlist = "$wordlistbase.inc.pl"; my $limit = $get{v} // (exists $get{v} ? 4 : 3); Html({ diff --git a/word/quiz.js b/word/quiz.js index d2a5818..0518fa1 100644 --- a/word/quiz.js +++ b/word/quiz.js @@ -21,9 +21,8 @@ class Quiz { }); } - constructor() { - this.dataurl = '/data/wordlist.nl.json'; - fetch(this.dataurl).then(res => res.json()).then(json => { + constructor(dataurl) { + fetch(dataurl).then(res => res.json()).then(json => { this.form = document.getElementById('quiz'); this.words = Object.values(json) .sort(() => {return .5 - Math.random()}) // shuffle @@ -32,5 +31,3 @@ class Quiz { }); } }; - -new Quiz(); diff --git a/word/quiz.plp b/word/quiz.plp index 7fc375e..dc0e1e0 100644 --- a/word/quiz.plp +++ b/word/quiz.plp @@ -1,5 +1,7 @@ <(../common.inc.plp)><: +our $wordlistbase; + Html({ raw => <<'EOT', @@ -23,4 +25,6 @@ li.good {background: #0F08} EOT }); + say '

quiz

'; +say "";