"Go to welcome page" is internationalized

This commit is contained in:
Veloman Yunkan 2022-01-30 20:55:19 +04:00 committed by Matthieu Gautier
parent 901664b097
commit c2bfeb4030
7 changed files with 23 additions and 4 deletions

View File

@ -50,6 +50,20 @@ std::string expandParameterizedString(const std::string& lang,
const std::string& key, const std::string& key,
const Parameters& params); const Parameters& params);
class GetTranslatedString
{
public:
explicit GetTranslatedString(const std::string& lang) : m_lang(lang) {}
std::string operator()(const std::string& key) const
{
return getTranslatedString(m_lang, key);
}
private:
const std::string m_lang;
};
} // namespace i18n } // namespace i18n
struct ParameterizedMessage struct ParameterizedMessage

View File

@ -280,14 +280,16 @@ void print_response_info(int retCode, MHD_Response* response)
} }
void ContentResponse::introduce_taskbar() void ContentResponse::introduce_taskbar(const std::string& lang)
{ {
i18n::GetTranslatedString t(lang);
kainjow::mustache::data data; kainjow::mustache::data data;
data.set("root", m_root); data.set("root", m_root);
data.set("content", m_bookName); data.set("content", m_bookName);
data.set("hascontent", (!m_bookName.empty() && !m_bookTitle.empty())); data.set("hascontent", (!m_bookName.empty() && !m_bookTitle.empty()));
data.set("title", m_bookTitle); data.set("title", m_bookTitle);
data.set("withlibrarybutton", m_withLibraryButton); data.set("withlibrarybutton", m_withLibraryButton);
data.set("LIBRARY_BUTTON_TEXT", t("library-button-text"));
auto head_content = render_template(RESOURCE::templates::head_taskbar_html, data); auto head_content = render_template(RESOURCE::templates::head_taskbar_html, data);
m_content = prependToFirstOccurence( m_content = prependToFirstOccurence(
m_content, m_content,
@ -352,7 +354,7 @@ ContentResponse::create_mhd_response(const RequestContext& request)
inject_root_link(); inject_root_link();
if (m_withTaskbar) { if (m_withTaskbar) {
introduce_taskbar(); introduce_taskbar(request.get_user_language());
} }
if (m_blockExternalLinks) { if (m_blockExternalLinks) {
inject_externallinks_blocker(); inject_externallinks_blocker();

View File

@ -106,7 +106,7 @@ class ContentResponse : public Response {
private: private:
MHD_Response* create_mhd_response(const RequestContext& request); MHD_Response* create_mhd_response(const RequestContext& request);
void introduce_taskbar(); void introduce_taskbar(const std::string& lang);
void inject_externallinks_blocker(); void inject_externallinks_blocker();
void inject_root_link(); void inject_root_link();
bool can_compress(const RequestContext& request) const; bool can_compress(const RequestContext& request) const;

View File

@ -19,4 +19,5 @@
, "500-page-heading" : "Internal Server Error" , "500-page-heading" : "Internal Server Error"
, "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."
, "library-button-text": "Go to welcome page"
} }

View File

@ -9,4 +9,5 @@
, "url-not-found" : "Սխալ հասցե՝ {{url}}" , "url-not-found" : "Սխալ հասցե՝ {{url}}"
, "404-page-title" : "Սխալ հասցե" , "404-page-title" : "Սխալ հասցե"
, "404-page-heading" : "Սխալ հասցե" , "404-page-heading" : "Սխալ հասցե"
, "library-button-text": "Գրադարանի էջ"
} }

View File

@ -20,4 +20,5 @@
, "500-page-heading" : "Heading of the 500 error page" , "500-page-heading" : "Heading of the 500 error page"
, "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"
, "library-button-text": "Tooltip of the button leading to the welcome page"
} }

View File

@ -12,7 +12,7 @@
<label for="kiwix_button_show_toggle"><img src="{{root}}/skin/caret.png" alt=""></label> <label for="kiwix_button_show_toggle"><img src="{{root}}/skin/caret.png" alt=""></label>
<div class="kiwix_button_cont"> <div class="kiwix_button_cont">
{{#withlibrarybutton}} {{#withlibrarybutton}}
<a id="kiwix_serve_taskbar_library_button" title="Go to welcome page" aria-label="Go to welcome page" href="{{root}}/"><button>&#x1f3e0;</button></a> <a id="kiwix_serve_taskbar_library_button" title="{{{LIBRARY_BUTTON_TEXT}}}" aria-label="{{{LIBRARY_BUTTON_TEXT}}}" href="{{root}}/"><button>&#x1f3e0;</button></a>
{{/withlibrarybutton}} {{/withlibrarybutton}}
{{#hascontent}} {{#hascontent}}
<a id="kiwix_serve_taskbar_home_button" title="Go to the main page of '{{title}}'" aria-label="Go to the main page of '{{title}}'" href="{{root}}/{{content}}/"><button>{{title}}</button></a> <a id="kiwix_serve_taskbar_home_button" title="Go to the main page of '{{title}}'" aria-label="Go to the main page of '{{title}}'" href="{{root}}/{{content}}/"><button>{{title}}</button></a>