mirror of https://github.com/kiwix/libkiwix.git
Translations for /nojs endpoint
Uses the string from #846 for translations. A couple new translations are also added for <title> tag.
This commit is contained in:
parent
37aadb86fb
commit
cc35fe503f
|
@ -3,6 +3,7 @@
|
||||||
#include "tools/otherTools.h"
|
#include "tools/otherTools.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
#include "tools/regexTools.h"
|
#include "tools/regexTools.h"
|
||||||
|
#include "server/i18n.h"
|
||||||
|
|
||||||
namespace kiwix
|
namespace kiwix
|
||||||
{
|
{
|
||||||
|
@ -88,15 +89,28 @@ std::string HTMLDumper::dumpPlainHTML(kiwix::Filter filter) const
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto getTranslation = i18n::GetTranslatedStringWithMsgId(m_userLang);
|
||||||
|
|
||||||
|
const auto translations = kainjow::mustache::object{
|
||||||
|
getTranslation("search"),
|
||||||
|
getTranslation("download"),
|
||||||
|
getTranslation("count-of-matching-books", {{"COUNT", to_string(filteredBooks.size())}}),
|
||||||
|
getTranslation("book-filtering-all-categories"),
|
||||||
|
getTranslation("book-filtering-all-languages"),
|
||||||
|
getTranslation("powered-by-kiwix-html"),
|
||||||
|
getTranslation("welcome-to-kiwix-server"),
|
||||||
|
getTranslation("preview-book")
|
||||||
|
};
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
RESOURCE::templates::no_js_library_page_html,
|
RESOURCE::templates::no_js_library_page_html,
|
||||||
kainjow::mustache::object{
|
kainjow::mustache::object{
|
||||||
{"root", rootLocation},
|
{"root", rootLocation},
|
||||||
{"books", booksData },
|
{"books", booksData },
|
||||||
{"searchQuery", searchQuery},
|
{"searchQuery", searchQuery},
|
||||||
{"resultsCount", to_string(filteredBooks.size())},
|
|
||||||
{"languages", languages},
|
{"languages", languages},
|
||||||
{"categories", categories}
|
{"categories", categories},
|
||||||
|
{"translations", translations}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,6 +69,28 @@ private:
|
||||||
const std::string m_lang;
|
const std::string m_lang;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class GetTranslatedStringWithMsgId
|
||||||
|
{
|
||||||
|
typedef kainjow::mustache::basic_data<std::string> MustacheString;
|
||||||
|
typedef std::pair<std::string, MustacheString> MsgIdAndTranslation;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit GetTranslatedStringWithMsgId(const std::string& lang) : m_lang(lang) {}
|
||||||
|
|
||||||
|
MsgIdAndTranslation operator()(const std::string& key) const
|
||||||
|
{
|
||||||
|
return {key, getTranslatedString(m_lang, key)};
|
||||||
|
}
|
||||||
|
|
||||||
|
MsgIdAndTranslation operator()(const std::string& key, const Parameters& params) const
|
||||||
|
{
|
||||||
|
return {key, expandParameterizedString(m_lang, key, params)};
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
const std::string m_lang;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace i18n
|
} // namespace i18n
|
||||||
|
|
||||||
struct ParameterizedMessage
|
struct ParameterizedMessage
|
||||||
|
|
|
@ -759,16 +759,25 @@ std::unique_ptr<Response> InternalServer::handle_viewer_settings(const RequestCo
|
||||||
return ContentResponse::build(*this, RESOURCE::templates::viewer_settings_js, data, "application/javascript; charset=utf-8");
|
return ContentResponse::build(*this, RESOURCE::templates::viewer_settings_js, data, "application/javascript; charset=utf-8");
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string InternalServer::getNoJSDownloadPageHTML(const std::string& bookId) const
|
std::string InternalServer::getNoJSDownloadPageHTML(const std::string& bookId, const std::string& userLang) const
|
||||||
{
|
{
|
||||||
const auto book = mp_library->getBookById(bookId);
|
const auto book = mp_library->getBookById(bookId);
|
||||||
auto bookUrl = kiwix::stripSuffix(book.getUrl(), ".meta4");
|
auto bookUrl = kiwix::stripSuffix(book.getUrl(), ".meta4");
|
||||||
|
auto getTranslation = i18n::GetTranslatedStringWithMsgId(userLang);
|
||||||
|
const auto translations = kainjow::mustache::object{
|
||||||
|
getTranslation("download-links-heading", {{"BOOK_TITLE", book.getTitle()}}),
|
||||||
|
getTranslation("download-links-title"),
|
||||||
|
getTranslation("direct-download-link-text"),
|
||||||
|
getTranslation("hash-download-link-text"),
|
||||||
|
getTranslation("magnet-link-text"),
|
||||||
|
getTranslation("torrent-download-link-text")
|
||||||
|
};
|
||||||
|
|
||||||
return render_template(
|
return render_template(
|
||||||
RESOURCE::templates::no_js_download_html,
|
RESOURCE::templates::no_js_download_html,
|
||||||
kainjow::mustache::object{
|
kainjow::mustache::object{
|
||||||
{"url", bookUrl},
|
{"url", bookUrl},
|
||||||
{"bookTitle", book.getTitle()}
|
{"translations", translations}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -780,6 +789,8 @@ std::unique_ptr<Response> InternalServer::handle_no_js(const RequestContext& req
|
||||||
HTMLDumper htmlDumper(mp_library, mp_nameMapper);
|
HTMLDumper htmlDumper(mp_library, mp_nameMapper);
|
||||||
htmlDumper.setRootLocation(m_root);
|
htmlDumper.setRootLocation(m_root);
|
||||||
htmlDumper.setLibraryId(getLibraryId());
|
htmlDumper.setLibraryId(getLibraryId());
|
||||||
|
auto userLang = request.get_user_language();
|
||||||
|
htmlDumper.setUserLanguage(userLang);
|
||||||
std::string content;
|
std::string content;
|
||||||
|
|
||||||
if (urlParts.size() == 1) {
|
if (urlParts.size() == 1) {
|
||||||
|
@ -798,7 +809,7 @@ std::unique_ptr<Response> InternalServer::handle_no_js(const RequestContext& req
|
||||||
} else if ((urlParts.size() == 3) && (urlParts[1] == "download")) {
|
} else if ((urlParts.size() == 3) && (urlParts[1] == "download")) {
|
||||||
try {
|
try {
|
||||||
const auto bookId = mp_nameMapper->getIdForName(urlParts[2]);
|
const auto bookId = mp_nameMapper->getIdForName(urlParts[2]);
|
||||||
content = getNoJSDownloadPageHTML(bookId);
|
content = getNoJSDownloadPageHTML(bookId, userLang);
|
||||||
} catch (const std::out_of_range&) {
|
} catch (const std::out_of_range&) {
|
||||||
return HTTP404Response(*this, request)
|
return HTTP404Response(*this, request)
|
||||||
+ urlNotFoundMsg;
|
+ urlNotFoundMsg;
|
||||||
|
|
|
@ -156,7 +156,7 @@ class InternalServer {
|
||||||
|
|
||||||
std::string getLibraryId() const;
|
std::string getLibraryId() const;
|
||||||
|
|
||||||
std::string getNoJSDownloadPageHTML(const std::string& bookId) const;
|
std::string getNoJSDownloadPageHTML(const std::string& bookId, const std::string& userLang) const;
|
||||||
|
|
||||||
private: // types
|
private: // types
|
||||||
class LockableSuggestionSearcher;
|
class LockableSuggestionSearcher;
|
||||||
|
|
|
@ -47,4 +47,8 @@
|
||||||
, "filter-by-tag": "Filter by tag \"{{TAG}}\""
|
, "filter-by-tag": "Filter by tag \"{{TAG}}\""
|
||||||
, "stop-filtering-by-tag": "Stop filtering by tag \"{{TAG}}\""
|
, "stop-filtering-by-tag": "Stop filtering by tag \"{{TAG}}\""
|
||||||
, "library-opds-feed-parameterised": "Library OPDS Feed - entries matching {{#LANG}}\nLanguage: {{LANG}} {{/LANG}}{{#CATEGORY}}\nCategory: {{CATEGORY}} {{/CATEGORY}}{{#TAG}}\nTag: {{TAG}} {{/TAG}}{{#Q}}\nQuery: {{Q}} {{/Q}}"
|
, "library-opds-feed-parameterised": "Library OPDS Feed - entries matching {{#LANG}}\nLanguage: {{LANG}} {{/LANG}}{{#CATEGORY}}\nCategory: {{CATEGORY}} {{/CATEGORY}}{{#TAG}}\nTag: {{TAG}} {{/TAG}}{{#Q}}\nQuery: {{Q}} {{/Q}}"
|
||||||
|
, "welcome-to-kiwix-server": "Welcome to Kiwix Server"
|
||||||
|
, "download-links-heading": "Download links for <b><i>{{BOOK_TITLE}}</i></b>"
|
||||||
|
, "download-links-title": "Download book"
|
||||||
|
, "preview-book": "Preview"
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,5 +48,9 @@
|
||||||
"filter-by-tag": "Hint for a link that would load results filtered by a single tag",
|
"filter-by-tag": "Hint for a link that would load results filtered by a single tag",
|
||||||
"stop-filtering-by-tag": "Tooltip for the button that cancels filtering by tag",
|
"stop-filtering-by-tag": "Tooltip for the button that cancels filtering by tag",
|
||||||
"library-opds-feed-all-entries": "Hint for the library OPDS feed for all entries",
|
"library-opds-feed-all-entries": "Hint for the library OPDS feed for all entries",
|
||||||
"library-opds-feed-parameterised": "Hint for the library OPDS feed for filtered entries"
|
"library-opds-feed-parameterised": "Hint for the library OPDS feed for filtered entries",
|
||||||
|
"welcome-to-kiwix-server": "Title shown in browser's title bar/page tab",
|
||||||
|
"download-links-heading": "Heading for no-js download page",
|
||||||
|
"download-links-title": "Title for no-js download page",
|
||||||
|
"preview-book": "Tooltip of book-tile leading to the book"
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,4 +36,8 @@
|
||||||
, "filter-by-tag": "Filter [I18N] by [TESTING] tag \"{{TAG}}\""
|
, "filter-by-tag": "Filter [I18N] by [TESTING] tag \"{{TAG}}\""
|
||||||
, "stop-filtering-by-tag": "[I18N] Stop filtering [TESTING] by tag \"{{TAG}}\""
|
, "stop-filtering-by-tag": "[I18N] Stop filtering [TESTING] by tag \"{{TAG}}\""
|
||||||
, "library-opds-feed-parameterised": "[I18N] Library OPDS Feed - [TESTING] entries matching {{#LANG}}\nLanguage: {{LANG}} {{/LANG}}{{#CATEGORY}}\nCategory: {{CATEGORY}} {{/CATEGORY}}{{#TAG}}\nTag: {{TAG}} {{/TAG}}{{#Q}}\nQuery: {{Q}} {{/Q}}"
|
, "library-opds-feed-parameterised": "[I18N] Library OPDS Feed - [TESTING] entries matching {{#LANG}}\nLanguage: {{LANG}} {{/LANG}}{{#CATEGORY}}\nCategory: {{CATEGORY}} {{/CATEGORY}}{{#TAG}}\nTag: {{TAG}} {{/TAG}}{{#Q}}\nQuery: {{Q}} {{/Q}}"
|
||||||
|
, "welcome-to-kiwix-server": "[I18N] Welcome to Kiwix Server [TESTING]"
|
||||||
|
, "download-links-heading": "[I18N] Download links for <b><i>{{BOOK_TITLE}}</i></b> [TESTING]"
|
||||||
|
, "download-links-title": "[I18N TESTING]Download book"
|
||||||
|
, "preview-book": "[I18N] Preview [TESTING]"
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,30 +4,30 @@
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Download book</title>
|
<title>{{translations.download-links-title}}</title>
|
||||||
</head>
|
</head>
|
||||||
<style>
|
<style>
|
||||||
.downloadLinksTitle {
|
.downloadLinksTitle {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
font-size: 32px;
|
font-size: 32px;
|
||||||
margin-bottom: 6px;
|
margin-bottom: 8px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
<body>
|
<body>
|
||||||
<div class="downloadLinksTitle">
|
<div class="downloadLinksTitle">
|
||||||
Download links for <b><i>{{bookTitle}}</i></b>
|
{{{translations.download-links-heading}}}
|
||||||
</div>
|
</div>
|
||||||
<a href="{{url}}" download>
|
<a href="{{url}}" download>
|
||||||
<div>Direct</div>
|
<div>{{translations.direct-download-link-text}}</div>
|
||||||
</a>
|
</a>
|
||||||
<a href="{{url}}.sha256" download>
|
<a href="{{url}}.sha256" download>
|
||||||
<div>Sha256 hash</div>
|
<div>{{translations.hash-download-link-text}}</div>
|
||||||
</a>
|
</a>
|
||||||
<a href="{{url}}.magnet" target="_blank">
|
<a href="{{url}}.magnet" target="_blank">
|
||||||
<div>Magnet link</div>
|
<div>{{translations.magnet-link-text}}</div>
|
||||||
</a>
|
</a>
|
||||||
<a href="{{url}}.torrent" download>
|
<a href="{{url}}.torrent" download>
|
||||||
<div>Torrent file</div>
|
<div>{{translations.torrent-download-link-text}}</div>
|
||||||
</a>
|
</a>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
|
@ -4,7 +4,7 @@
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
||||||
<link type="root" href="{{root}}">
|
<link type="root" href="{{root}}">
|
||||||
<title>Welcome to Kiwix Server</title>
|
<title>{{translations.welcome-to-kiwix-server}}</title>
|
||||||
<link
|
<link
|
||||||
type="text/css"
|
type="text/css"
|
||||||
href="{{root}}/skin/index.css?KIWIXCACHEID"
|
href="{{root}}/skin/index.css?KIWIXCACHEID"
|
||||||
|
@ -69,7 +69,7 @@
|
||||||
<div class="kiwixNav__filters">
|
<div class="kiwixNav__filters">
|
||||||
<div class="kiwixNav__select">
|
<div class="kiwixNav__select">
|
||||||
<select name="lang" id="languageFilter" class='kiwixNav__kiwixFilter filter' form="kiwixSearchForm">
|
<select name="lang" id="languageFilter" class='kiwixNav__kiwixFilter filter' form="kiwixSearchForm">
|
||||||
<option value="" selected>All languages</option>
|
<option value="" selected>{{translations.book-filtering-all-languages}}</option>
|
||||||
{{#languages}}
|
{{#languages}}
|
||||||
<option value="{{lang_code}}"{{#selected}} selected {{/selected}}>{{lang_self_name}}</option>
|
<option value="{{lang_code}}"{{#selected}} selected {{/selected}}>{{lang_self_name}}</option>
|
||||||
{{/languages}}
|
{{/languages}}
|
||||||
|
@ -77,7 +77,7 @@
|
||||||
</div>
|
</div>
|
||||||
<div class="kiwixNav__select">
|
<div class="kiwixNav__select">
|
||||||
<select name="category" id="categoryFilter" class='kiwixNav__kiwixFilter filter' form="kiwixSearchForm">
|
<select name="category" id="categoryFilter" class='kiwixNav__kiwixFilter filter' form="kiwixSearchForm">
|
||||||
<option value="">All categories</option>
|
<option value="">{{translations.book-filtering-all-categories}}</option>
|
||||||
{{#categories}}
|
{{#categories}}
|
||||||
<option value="{{name}}"{{#selected}} selected {{/selected}}>{{hf_name}}</option>
|
<option value="{{name}}"{{#selected}} selected {{/selected}}>{{hf_name}}</option>
|
||||||
{{/categories}}
|
{{/categories}}
|
||||||
|
@ -85,13 +85,13 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<form id='kiwixSearchForm' class='kiwixNav__SearchForm' action="{{root}}/nojs">
|
<form id='kiwixSearchForm' class='kiwixNav__SearchForm' action="{{root}}/nojs">
|
||||||
<input type="text" name="q" placeholder="Search" id="searchFilter" class='kiwixSearch filter' value="{{searchQuery}}">
|
<input type="text" name="q" placeholder="{{translations.search}}" id="searchFilter" class='kiwixSearch filter' value="{{searchQuery}}">
|
||||||
<input type="submit" class="kiwixButton kiwixButtonHover" value="Search"/>
|
<input type="submit" class="kiwixButton kiwixButtonHover" value="{{translations.search}}"/>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="kiwixHomeBody">
|
<div class="kiwixHomeBody">
|
||||||
<div class="book__list">
|
<div class="book__list">
|
||||||
<h3 class="kiwixHomeBody__results">{{resultsCount}} results</h3>
|
<h3 class="kiwixHomeBody__results">{{translations.count-of-matching-books}}</h3>
|
||||||
{{#books}}
|
{{#books}}
|
||||||
<div class="book__wrapper">
|
<div class="book__wrapper">
|
||||||
<div class="book__link__wrapper">
|
<div class="book__link__wrapper">
|
||||||
|
@ -99,10 +99,10 @@
|
||||||
<div class="book__header">
|
<div class="book__header">
|
||||||
<div id="book__title"><a href="{{root}}/content/{{id}}">{{title}}</a></div>
|
<div id="book__title"><a href="{{root}}/content/{{id}}">{{title}}</a></div>
|
||||||
{{#downloadAvailable}}
|
{{#downloadAvailable}}
|
||||||
<div class="book__download"><span><a href="{{root}}/nojs/download/{{id}}">Download</a></span></div>
|
<div class="book__download"><span><a href="{{root}}/nojs/download/{{id}}">{{translations.download}}</a></span></div>
|
||||||
{{/downloadAvailable}}
|
{{/downloadAvailable}}
|
||||||
</div>
|
</div>
|
||||||
<a class="book__link" href="{{root}}/content/{{id}}" title="Preview" aria-label="Preview">
|
<a class="book__link" href="{{root}}/content/{{id}}" title="{{translations.preview-book}}" aria-label="{{translations.preview-book}}">
|
||||||
<div class="book__description" title="{{description}}">{{description}}</div>
|
<div class="book__description" title="{{description}}">{{description}}</div>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
@ -117,5 +117,6 @@
|
||||||
{{/books}}
|
{{/books}}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="kiwixfooter" class="kiwixfooter">{{{translations.powered-by-kiwix-html}}}</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Reference in New Issue