From 8f5714be07858422a4b9a6a9bb5d30b026293d2e Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Tue, 30 Jan 2024 15:47:12 +0400 Subject: [PATCH] Search results page header as translatable text However it is NOT actually translated by the backend yet --- src/search_renderer.cpp | 23 +++++++++++++++++++++-- static/skin/i18n/en.json | 2 ++ static/skin/i18n/qqq.json | 2 ++ static/templates/search_result.html | 14 +------------- test/server_search.cpp | 12 ++---------- 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/src/search_renderer.cpp b/src/search_renderer.cpp index b42275c73..bcdb4142f 100644 --- a/src/search_renderer.cpp +++ b/src/search_renderer.cpp @@ -47,6 +47,25 @@ ParameterizedMessage searchResultsPageTitleMsg(const std::string& searchPattern) ); } +ParameterizedMessage searchResultsPageHeaderMsg(const std::string& searchPattern, + const kainjow::mustache::data& r) +{ + if ( r.get("count")->string_value() == "0" ) { + return ParameterizedMessage("empty-search-results-page-header", + {{"SEARCH_PATTERN", searchPattern}} + ); + } else { + return ParameterizedMessage("search-results-page-header", + { + {"SEARCH_PATTERN", searchPattern}, + {"START", r.get("start")->string_value()}, + {"END", r.get("end") ->string_value()}, + {"COUNT", r.get("count")->string_value()}, + } + ); + } +} + } // unnamed namespace /* Constructor */ @@ -196,7 +215,6 @@ std::string SearchRenderer::renderTemplate(const std::string& tmpl_str, const Na kainjow::mustache::data results; results.set("items", items); results.set("count", kiwix::beautifyInteger(estimatedResultCount)); - results.set("hasResults", estimatedResultCount != 0); results.set("start", kiwix::beautifyInteger(resultStart)); results.set("end", kiwix::beautifyInteger(std::min(resultStart+pageLength-1, estimatedResultCount))); @@ -213,9 +231,10 @@ std::string SearchRenderer::renderTemplate(const std::string& tmpl_str, const Na searchBookQuery ); - + const auto pageHeaderMsg = searchResultsPageHeaderMsg(searchPattern, results); const kainjow::mustache::object allData{ {"PAGE_TITLE", searchResultsPageTitleMsg(searchPattern).getText(userlang)}, + {"PAGE_HEADER", pageHeaderMsg.getText(userlang)}, {"searchProtocolPrefix", searchProtocolPrefix}, {"results", results}, {"pagination", pagination}, diff --git a/static/skin/i18n/en.json b/static/skin/i18n/en.json index d54c4cd1d..88bfa8608 100644 --- a/static/skin/i18n/en.json +++ b/static/skin/i18n/en.json @@ -26,6 +26,8 @@ , "fulltext-search-unavailable" : "Fulltext search unavailable" , "no-search-results": "The fulltext search engine is not available for this content." , "search-results-page-title": "Search: {{SEARCH_PATTERN}}" + , "search-results-page-header": "Results {{START}}-{{END}} of {{COUNT}} for \"{{{SEARCH_PATTERN}}}\"" + , "empty-search-results-page-header": "No results were found for \"{{{SEARCH_PATTERN}}}\"" , "library-button-text": "Go to welcome page" , "home-button-text": "Go to the main page of '{{BOOK_TITLE}}'" , "random-page-button-text": "Go to a randomly selected page" diff --git a/static/skin/i18n/qqq.json b/static/skin/i18n/qqq.json index cc44ee4b7..923021b8a 100644 --- a/static/skin/i18n/qqq.json +++ b/static/skin/i18n/qqq.json @@ -30,6 +30,8 @@ "fulltext-search-unavailable": "Title of the error page returned when search is attempted in a book without fulltext search database", "no-search-results": "Text of the error page returned when search is attempted in a book without fulltext search database", "search-results-page-title": "Title of the search results page", + "search-results-page-header": "Header of the search results page", + "empty-search-results-page-header": "Header of the empty search results page", "library-button-text": "Tooltip of the button leading to the welcome page", "home-button-text": "Tooltip of the button leading to the main page of a book", "random-page-button-text": "Tooltip of the button opening a randomly selected page", diff --git a/static/templates/search_result.html b/static/templates/search_result.html index 1ef23007e..9aa440e8c 100644 --- a/static/templates/search_result.html +++ b/static/templates/search_result.html @@ -106,19 +106,7 @@
- {{#results.hasResults}} - Results - - {{results.start}}-{{results.end}} - of - {{results.count}} - for - "{{{query.pattern}}}" - - {{/results.hasResults}} - {{^results.hasResults}} - No results were found for "{{{query.pattern}}}" - {{/results.hasResults}} + {{{PAGE_HEADER}}}
diff --git a/test/server_search.cpp b/test/server_search.cpp index 358160edd..30149a373 100644 --- a/test/server_search.cpp +++ b/test/server_search.cpp @@ -738,18 +738,10 @@ struct TestData std::string expectedHtmlHeader() const { if ( totalResultCount == 0 ) { - return "\n No results were found for \"" + getPattern() + "\""; + return "No results were found for \"" + getPattern() + "\""; } - std::string header = R"( Results - - FIRSTRESULT-LASTRESULT - of - RESULTCOUNT - for - "PATTERN" - - )"; + std::string header = R"(Results FIRSTRESULT-LASTRESULT of RESULTCOUNT for "PATTERN")"; const size_t lastResultIndex = std::min(totalResultCount, firstResultIndex + results.size() - 1); header = replace(header, "FIRSTRESULT", std::to_string(firstResultIndex));