From 641482854d626cf661ad5a9f6b4f2fbc42f9cef1 Mon Sep 17 00:00:00 2001 From: Wolfgang Meier Date: Sun, 31 Dec 2023 11:46:13 +0000 Subject: [PATCH] Facet selection with combo box: translate labels via output function in config if configured --- modules/config.xqm | 7 ++++--- modules/facets.xql | 26 ++++++++++++++++---------- modules/lib/api/search.xql | 9 +++++---- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/modules/config.xqm b/modules/config.xqm index b28884c4..c938a069 100644 --- a/modules/config.xqm +++ b/modules/config.xqm @@ -139,9 +139,10 @@ declare variable $config:facets := [ map { "dimension": "language", "heading": "facets.language", - "max": 10, + "source": "api/search/facets/language", + "max": 5, "hierarchical": false(), - "output": function($label) { + "output": function($label, $language) { switch($label) case "de" return "German" case "es" return "Spanish" @@ -157,7 +158,7 @@ declare variable $config:facets := [ "dimension": "feature", "heading": "facets.feature", "source": "api/search/facets/feature", - "max": 15, + "max": 5, "hierarchical": false() }, map { diff --git a/modules/facets.xql b/modules/facets.xql index 79cd5815..5f21d43c 100644 --- a/modules/facets.xql +++ b/modules/facets.xql @@ -38,6 +38,7 @@ declare function facets:sort($facets as map(*)?) { declare function facets:print-table($config as map(*), $nodes as element()+, $values as xs:string*, $params as xs:string*) { let $all := exists($config?max) and facets:get-parameter("all-" || $config?dimension) + let $lang := tokenize(facets:get-parameter("language"), '-')[1] let $count := if ($all) then 50 else $config?max let $facets := if (exists($values)) then @@ -50,11 +51,7 @@ declare function facets:print-table($config as map(*), $nodes as element()+, $va { array:for-each(facets:sort($facets), function($entry) { map:for-each($entry, function($label, $freq) { - let $content := - if (exists($config?output)) then - $config?output($label) - else - $label + let $content := facets:translate($config, $lang, $label) return @@ -88,6 +85,7 @@ declare function facets:print-table($config as map(*), $nodes as element()+, $va declare function facets:display($config as map(*), $nodes as element()+) { let $params := facets:get-parameter("facet-" || $config?dimension) + let $lang := tokenize(facets:get-parameter("language"), '-')[1] let $table := facets:print-table($config, $nodes, (), $params) let $maxcount := 50 @@ -127,11 +125,7 @@ declare function facets:display($config as map(*), $nodes as element()+) {