Search results page header as translatable text

However it is NOT actually translated by the backend yet
This commit is contained in:
Veloman Yunkan 2024-01-30 15:47:12 +04:00
parent c4fa42f20b
commit 8f5714be07
5 changed files with 28 additions and 25 deletions

View File

@ -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},

View File

@ -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 <b>{{START}}-{{END}}</b> of <b>{{COUNT}}</b> for <b>\"{{{SEARCH_PATTERN}}}\"</b>"
, "empty-search-results-page-header": "No results were found for <b>\"{{{SEARCH_PATTERN}}}\"</b>"
, "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"

View File

@ -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",

View File

@ -106,19 +106,7 @@
</head>
<body bgcolor="white">
<div class="header">
{{#results.hasResults}}
Results
<b>
{{results.start}}-{{results.end}}
</b> of <b>
{{results.count}}
</b> for <b>
"{{{query.pattern}}}"
</b>
{{/results.hasResults}}
{{^results.hasResults}}
No results were found for <b>"{{{query.pattern}}}"</b>
{{/results.hasResults}}
{{{PAGE_HEADER}}}
</div>
<div class="results">

View File

@ -738,18 +738,10 @@ struct TestData
std::string expectedHtmlHeader() const
{
if ( totalResultCount == 0 ) {
return "\n No results were found for <b>\"" + getPattern() + "\"</b>";
return "No results were found for <b>\"" + getPattern() + "\"</b>";
}
std::string header = R"( Results
<b>
FIRSTRESULT-LASTRESULT
</b> of <b>
RESULTCOUNT
</b> for <b>
"PATTERN"
</b>
)";
std::string header = R"(Results <b>FIRSTRESULT-LASTRESULT</b> of <b>RESULTCOUNT</b> for <b>"PATTERN"</b>)";
const size_t lastResultIndex = std::min(totalResultCount, firstResultIndex + results.size() - 1);
header = replace(header, "FIRSTRESULT", std::to_string(firstResultIndex));