Search result info as translatable text

However it is NOT actually translated by the backend yet
This commit is contained in:
Veloman Yunkan 2024-01-30 16:21:00 +04:00
parent 8f5714be07
commit 33a3277400
4 changed files with 22 additions and 8 deletions

View File

@ -204,10 +204,20 @@ std::string SearchRenderer::renderTemplate(const std::string& tmpl_str, const Na
result.set("absolutePath", absPathPrefix + urlEncode(path)); result.set("absolutePath", absPathPrefix + urlEncode(path));
result.set("snippet", it.getSnippet()); result.set("snippet", it.getSnippet());
if (library) { if (library) {
result.set("bookTitle", library->getBookById(zim_id).getTitle()); const std::string bookTitle = library->getBookById(zim_id).getTitle();
const ParameterizedMessage bookInfoMsg("search-result-book-info",
{{"BOOK_TITLE", bookTitle}}
);
result.set("bookInfo", bookInfoMsg.getText(userlang)); // for HTML
result.set("bookTitle", bookTitle); // for XML
} }
if (it.getWordCount() >= 0) { if (it.getWordCount() >= 0) {
result.set("wordCount", kiwix::beautifyInteger(it.getWordCount())); const auto wordCountStr = kiwix::beautifyInteger(it.getWordCount());
const ParameterizedMessage wordCountMsg("word-count",
{{"COUNT", wordCountStr}}
);
result.set("wordCountInfo", wordCountMsg.getText(userlang)); // for HTML
result.set("wordCount", wordCountStr); // for XML
} }
items.push_back(result); items.push_back(result);

View File

@ -28,6 +28,8 @@
, "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>" , "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>" , "empty-search-results-page-header": "No results were found for <b>\"{{{SEARCH_PATTERN}}}\"</b>"
, "search-result-book-info": "from {{BOOK_TITLE}}"
, "word-count": "{{COUNT}} words"
, "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"

View File

@ -32,6 +32,8 @@
"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", "search-results-page-header": "Header of the search results page",
"empty-search-results-page-header": "Header of the empty search results page", "empty-search-results-page-header": "Header of the empty search results page",
"search-result-book-info": "Reference to the book where the search result belongs (this is displayed AFTER the search result)",
"word-count": "Word count information",
"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",

View File

@ -119,12 +119,12 @@
{{#snippet}} {{#snippet}}
<cite>{{>snippet}}...</cite> <cite>{{>snippet}}...</cite>
{{/snippet}} {{/snippet}}
{{#bookTitle}} {{#bookInfo}}
<div class="book-title">from {{bookTitle}}</div> <div class="book-title">{{bookInfo}}</div>
{{/bookTitle}} {{/bookInfo}}
{{#wordCount}} {{#wordCountInfo}}
<div class="informations">{{wordCount}} words</div> <div class="informations">{{wordCountInfo}}</div>
{{/wordCount}} {{/wordCountInfo}}
</li> </li>
{{/results.items}} {{/results.items}}
</ul> </ul>