mirror of https://github.com/kiwix/libkiwix.git
Search results page header as translatable text
However it is NOT actually translated by the backend yet
This commit is contained in:
parent
c4fa42f20b
commit
8f5714be07
|
@ -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
|
} // unnamed namespace
|
||||||
|
|
||||||
/* Constructor */
|
/* Constructor */
|
||||||
|
@ -196,7 +215,6 @@ std::string SearchRenderer::renderTemplate(const std::string& tmpl_str, const Na
|
||||||
kainjow::mustache::data results;
|
kainjow::mustache::data results;
|
||||||
results.set("items", items);
|
results.set("items", items);
|
||||||
results.set("count", kiwix::beautifyInteger(estimatedResultCount));
|
results.set("count", kiwix::beautifyInteger(estimatedResultCount));
|
||||||
results.set("hasResults", estimatedResultCount != 0);
|
|
||||||
results.set("start", kiwix::beautifyInteger(resultStart));
|
results.set("start", kiwix::beautifyInteger(resultStart));
|
||||||
results.set("end", kiwix::beautifyInteger(std::min(resultStart+pageLength-1, estimatedResultCount)));
|
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
|
searchBookQuery
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const auto pageHeaderMsg = searchResultsPageHeaderMsg(searchPattern, results);
|
||||||
const kainjow::mustache::object allData{
|
const kainjow::mustache::object allData{
|
||||||
{"PAGE_TITLE", searchResultsPageTitleMsg(searchPattern).getText(userlang)},
|
{"PAGE_TITLE", searchResultsPageTitleMsg(searchPattern).getText(userlang)},
|
||||||
|
{"PAGE_HEADER", pageHeaderMsg.getText(userlang)},
|
||||||
{"searchProtocolPrefix", searchProtocolPrefix},
|
{"searchProtocolPrefix", searchProtocolPrefix},
|
||||||
{"results", results},
|
{"results", results},
|
||||||
{"pagination", pagination},
|
{"pagination", pagination},
|
||||||
|
|
|
@ -26,6 +26,8 @@
|
||||||
, "fulltext-search-unavailable" : "Fulltext search unavailable"
|
, "fulltext-search-unavailable" : "Fulltext search unavailable"
|
||||||
, "no-search-results": "The fulltext search engine is not available for this content."
|
, "no-search-results": "The fulltext search engine is not available for this content."
|
||||||
, "search-results-page-title": "Search: {{SEARCH_PATTERN}}"
|
, "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"
|
, "library-button-text": "Go to welcome page"
|
||||||
, "home-button-text": "Go to the main page of '{{BOOK_TITLE}}'"
|
, "home-button-text": "Go to the main page of '{{BOOK_TITLE}}'"
|
||||||
, "random-page-button-text": "Go to a randomly selected page"
|
, "random-page-button-text": "Go to a randomly selected page"
|
||||||
|
|
|
@ -30,6 +30,8 @@
|
||||||
"fulltext-search-unavailable": "Title of the error page returned when search is attempted in a book without fulltext search database",
|
"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",
|
"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-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",
|
"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",
|
"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",
|
"random-page-button-text": "Tooltip of the button opening a randomly selected page",
|
||||||
|
|
|
@ -106,19 +106,7 @@
|
||||||
</head>
|
</head>
|
||||||
<body bgcolor="white">
|
<body bgcolor="white">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
{{#results.hasResults}}
|
{{{PAGE_HEADER}}}
|
||||||
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}}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="results">
|
<div class="results">
|
||||||
|
|
|
@ -738,18 +738,10 @@ struct TestData
|
||||||
std::string expectedHtmlHeader() const
|
std::string expectedHtmlHeader() const
|
||||||
{
|
{
|
||||||
if ( totalResultCount == 0 ) {
|
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
|
std::string header = R"(Results <b>FIRSTRESULT-LASTRESULT</b> of <b>RESULTCOUNT</b> for <b>"PATTERN"</b>)";
|
||||||
<b>
|
|
||||||
FIRSTRESULT-LASTRESULT
|
|
||||||
</b> of <b>
|
|
||||||
RESULTCOUNT
|
|
||||||
</b> for <b>
|
|
||||||
"PATTERN"
|
|
||||||
</b>
|
|
||||||
)";
|
|
||||||
|
|
||||||
const size_t lastResultIndex = std::min(totalResultCount, firstResultIndex + results.size() - 1);
|
const size_t lastResultIndex = std::min(totalResultCount, firstResultIndex + results.size() - 1);
|
||||||
header = replace(header, "FIRSTRESULT", std::to_string(firstResultIndex));
|
header = replace(header, "FIRSTRESULT", std::to_string(firstResultIndex));
|
||||||
|
|
Loading…
Reference in New Issue