word: option ?lang selects alternate wordlist includes
[sheet.git] / word.plp
index 2c16a24a71282d5433c3327223ad76f190ad9c6a..493bde927b655aadff77009072ad8df21f8a414e 100644 (file)
--- a/word.plp
+++ b/word.plp
@@ -1,6 +1,7 @@
 <(common.inc.plp)><:
 
-my $wordlist = "data/wordlist.en.inc.pl";
+my $lang = $get{lang} || 'en';
+my $wordlist = "data/wordlist.$lang.inc.pl";
 my $limit = $get{v} // (exists $get{v} ? 4 : 3);
 
 Html({
@@ -93,7 +94,18 @@ sub printimgs {
 
 say '<section class="gallery">';
 if (exists $get{q}) {
-       my @rows = map {@$_} values %{$table}; # flatten categories
+       my @rows;
+       if ($Request) {
+               my @query = $Request;
+               while (@query) {
+                       push @rows, grep { (split /:/)[1] <= $limit } @query;
+                       s/:.*// for @query;
+                       @query = map {$_ ? @{$_} : ()} @{$table}{@query};
+               }
+       }
+       else {
+               @rows = map {ref ? @$_ : $_} values %{$table}; # flatten categories
+       }
        @rows = sort { rand <=> .5 } @rows;
        $table = {};
        printimgs(@rows);