From 50442220cc52bad55c1003de34f8dada958650d5 Mon Sep 17 00:00:00 2001 From: Mischa POSLAWSKY Date: Thu, 30 Dec 2021 03:31:41 +0100 Subject: [PATCH] word: language includes for general use Reorder translation columns and add (possibly foreign) category references as stable interface for quizzes. Exceptional category index format for .en English moved to extensionless include. --- Makefile | 4 ++-- tools/mkwordlist | 2 +- word.plp | 3 ++- word/multichoice.js | 6 +++--- word/wijzer.js | 8 ++++---- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index aaf9283..7388647 100644 --- a/Makefile +++ b/Makefile @@ -23,7 +23,7 @@ plan.plp: TODO UPDATE: $(download) $(call cmdsave,git log -1 --date=short --pretty="%ad %s") -word: word/put.min.js data/wordlist.en.json data/wordlist.nl.json data/wordlist.ru.json data/wordpairs.json +word: word/put.min.js data/wordlist.inc.pl data/wordlist.en.json data/wordlist.nl.json data/wordlist.ru.json data/wordpairs.json word/put.js: $(download) tools/wget-ifmodified https://github.com/kriszyp/put-selector/raw/master/put.js $@ @@ -81,7 +81,7 @@ data/wordlist.version.txt: force @[ -e $@ ] || date -Is >$@ @perl -ni -I. -MShiar_Sheet::DB -E 'say (Shiar_Sheet::DB->connect->select(word => "max(updated)", \["updated>?", $$_])->list or exit 1)' $@ || true -data/wordlist.en.inc.pl: tools/mkwordlist data/wordlist.version.txt +data/wordlist.inc.pl: tools/mkwordlist data/wordlist.version.txt $(call cmdsave,$<) data/wordlist.%.inc.pl: tools/mkwordlist data/wordlist.version.txt $(call cmdsave,$< $*) diff --git a/tools/mkwordlist b/tools/mkwordlist index 78859b4..2e38a8d 100755 --- a/tools/mkwordlist +++ b/tools/mkwordlist @@ -13,7 +13,7 @@ use Data::Dump 'pp'; my %rows; if (my $lang = shift @ARGV) { my %filter = (lang => $lang); - my $cols = "ref, id, prio, array_to_string(form || alt, '/')"; + my $cols = "ref, array_to_string(form || alt, '/'), prio, id, cat"; %rows = $db->select(_word_ref => $cols, \%filter)->map_arrays; say pp \%rows =~ s/\\x\{([0-9A-F]+)\}/chr hex $1/ger; diff --git a/word.plp b/word.plp index aed42fd..f47c4f4 100644 --- a/word.plp +++ b/word.plp @@ -1,12 +1,13 @@ <(common.inc.plp)><: our $lang = $get{lang} || 'en'; -our $wordlistbase = "data/wordlist.$lang"; +our $wordlistbase = "data/wordlist"; if ($Request and $Request =~ m{\A([^/]+)}) { my $page = "word/$1.plp"; utf8::downgrade($page); # unicode filename breaks contents encoding if (-e $page) { + $wordlistbase .= ".$lang"; Include $page; exit; } diff --git a/word/multichoice.js b/word/multichoice.js index 649d19a..761b966 100644 --- a/word/multichoice.js +++ b/word/multichoice.js @@ -2,15 +2,15 @@ class WordMultiChoice extends WordQuiz { next() { let word = this.words.shift(); let form = put(this.form, - '+img[src=$]+ul', `/data/word/en/${word[0]}.jpg`, + '+img[src=$]+ul', `/data/word/en/${word[2]}.jpg`, ); - let answers = [word[2], this.words[0][2], this.words[1][2], this.words[2][2]] + let answers = [word[0], this.words[0][0], this.words[1][0], this.words[2][0]] .shuffle() answers.forEach(suggest => { let label = suggest.replace(/\/.*/, ''); let option = put(form, 'li', label, {onclick: () => { - if (suggest != word[2]) { + if (suggest != word[0]) { // incorrect put(option, '.wrong'); return; diff --git a/word/wijzer.js b/word/wijzer.js index b4dab8f..b199be4 100644 --- a/word/wijzer.js +++ b/word/wijzer.js @@ -11,8 +11,8 @@ class WordWijzer extends WordQuiz { this.question.innerHTML = ''; put(this.question, - '[data-id=$] img[src=$]', word[0], - `/data/word/en/${word[0]}.jpg` + '[data-id=$] img[src=$]', word[2], + `/data/word/en/${word[2]}.jpg` ); } @@ -33,9 +33,9 @@ class WordWijzer extends WordQuiz { let answers = put(this.form, 'ul'); this.words .forEach(answer => { - let label = answer[2].replace(/\/.*/, ''); // primary form + let label = answer[0].replace(/\/.*/, ''); // primary form put(answers, 'li[data-id=$][onclick=""]', - answer[0], label, {onclick: e => this.verify(e)} + answer[2], label, {onclick: e => this.verify(e)} ) }); this.words.shuffle(); -- 2.30.0