diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index 7ee986935..f6026a79c 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -628,8 +628,8 @@ std::unique_ptr InternalServer::handle_search(const RequestContext& re // Searcher->search will throw a runtime error if there is no valid xapian database to do the search. // (in case of zim file not containing a index) return HTTPErrorHtmlResponse(*this, request, MHD_HTTP_NOT_FOUND, - "Fulltext search unavailable", - "Not Found", + "fulltext-search-unavailable", + "404-page-heading", m_root + "/skin/search_results.css") + noSearchResultsMsg() + TaskbarInfo(searchInfo.bookName, archive.get()); diff --git a/src/server/response.cpp b/src/server/response.cpp index 09a9b4745..ca157b868 100644 --- a/src/server/response.cpp +++ b/src/server/response.cpp @@ -87,6 +87,11 @@ std::unique_ptr Response::build_304(const InternalServer& server, cons const UrlNotFoundMsg urlNotFoundMsg; const InvalidUrlMsg invalidUrlMsg; +std::string ContentResponseBlueprint::getMessage(const std::string& msgId) const +{ + return getTranslatedString(m_request.get_user_language(), msgId); +} + std::unique_ptr ContentResponseBlueprint::generateResponseObject() const { auto r = ContentResponse::build(m_server, m_template, m_data, m_mimeType); @@ -100,8 +105,8 @@ std::unique_ptr ContentResponseBlueprint::generateResponseObjec HTTPErrorHtmlResponse::HTTPErrorHtmlResponse(const InternalServer& server, const RequestContext& request, int httpStatusCode, - const std::string& pageTitleMsg, - const std::string& headingMsg, + const std::string& pageTitleMsgId, + const std::string& headingMsgId, const std::string& cssUrl) : ContentResponseBlueprint(&server, &request, @@ -112,8 +117,8 @@ HTTPErrorHtmlResponse::HTTPErrorHtmlResponse(const InternalServer& server, kainjow::mustache::list emptyList; this->m_data = kainjow::mustache::object{ {"CSS_URL", onlyAsNonEmptyMustacheValue(cssUrl) }, - {"PAGE_TITLE", pageTitleMsg}, - {"PAGE_HEADING", headingMsg}, + {"PAGE_TITLE", getMessage(pageTitleMsgId)}, + {"PAGE_HEADING", getMessage(headingMsgId)}, {"details", emptyList} }; } @@ -123,8 +128,8 @@ HTTP404HtmlResponse::HTTP404HtmlResponse(const InternalServer& server, : HTTPErrorHtmlResponse(server, request, MHD_HTTP_NOT_FOUND, - "Content not found", - "Not Found") + "404-page-title", + "404-page-heading") { } @@ -151,8 +156,8 @@ HTTP400HtmlResponse::HTTP400HtmlResponse(const InternalServer& server, : HTTPErrorHtmlResponse(server, request, MHD_HTTP_BAD_REQUEST, - "Invalid request", - "Invalid request") + "400-page-title", + "400-page-heading") { } @@ -172,8 +177,8 @@ HTTP500HtmlResponse::HTTP500HtmlResponse(const InternalServer& server, : HTTPErrorHtmlResponse(server, request, MHD_HTTP_INTERNAL_SERVER_ERROR, - "Internal Server Error", - "Internal Server Error") + "500-page-title", + "500-page-heading") { // operator+() is a state-modifying operator (akin to operator+=) *this + "An internal server error occured. We are sorry about that :/"; diff --git a/src/server/response.h b/src/server/response.h index d9a0ada88..9351cf6d4 100644 --- a/src/server/response.h +++ b/src/server/response.h @@ -167,6 +167,7 @@ public: // functions ContentResponseBlueprint& operator+(const TaskbarInfo& taskbarInfo); protected: // functions + std::string getMessage(const std::string& msgId) const; virtual std::unique_ptr generateResponseObject() const; public: //data @@ -184,8 +185,8 @@ struct HTTPErrorHtmlResponse : ContentResponseBlueprint HTTPErrorHtmlResponse(const InternalServer& server, const RequestContext& request, int httpStatusCode, - const std::string& pageTitleMsg, - const std::string& headingMsg, + const std::string& pageTitleMsgId, + const std::string& headingMsgId, const std::string& cssUrl = ""); using ContentResponseBlueprint::operator+; diff --git a/static/i18n/en.json b/static/i18n/en.json index 415d7fbd5..a6e62d51f 100644 --- a/static/i18n/en.json +++ b/static/i18n/en.json @@ -11,4 +11,11 @@ , "random-article-failure" : "Oops! Failed to pick a random article :(" , "invalid-raw-data-type" : "{{DATATYPE}} is not a valid request for raw content." , "raw-entry-not-found" : "Cannot find {{DATATYPE}} entry {{ENTRY}}" + , "400-page-title" : "Invalid request" + , "400-page-heading" : "Invalid request" + , "404-page-title" : "Content not found" + , "404-page-heading" : "Not Found" + , "500-page-title" : "Internal Server Error" + , "500-page-heading" : "Internal Server Error" + , "fulltext-search-unavailable" : "Fulltext search unavailable" } diff --git a/static/i18n/hy.json b/static/i18n/hy.json index 9b55d8c38..6120c2f0c 100644 --- a/static/i18n/hy.json +++ b/static/i18n/hy.json @@ -7,4 +7,6 @@ "suggest-full-text-search": "որոնել '{{{SEARCH_TERMS}}}'..." , "no-such-book": "Գիրքը բացակայում է՝ {{BOOK_NAME}}" , "url-not-found" : "Սխալ հասցե՝ {{url}}" + , "404-page-title" : "Սխալ հասցե" + , "404-page-heading" : "Սխալ հասցե" } diff --git a/static/i18n/qqq.json b/static/i18n/qqq.json index 0ade75a60..b548495a9 100644 --- a/static/i18n/qqq.json +++ b/static/i18n/qqq.json @@ -12,4 +12,11 @@ , "random-article-failure" : "Failure of the random article selection procedure" , "invalid-raw-data-type" : "Invalid DATATYPE was used with the /raw endpoint (/raw//DATATYPE/...); allowed values are 'meta' and 'content'" , "raw-entry-not-found" : "Entry requested via the /raw endpoint was not found" + , "400-page-title" : "Title of the 400 error page" + , "400-page-heading" : "Heading of the 400 error page" + , "404-page-title" : "Title of the 404 error page" + , "404-page-heading" : "Heading of the 404 error page" + , "500-page-title" : "Title 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" } diff --git a/test/server.cpp b/test/server.cpp index f89e2236a..65c1376a8 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -572,8 +572,9 @@ TEST_F(ServerTest, 404WithBodyTesting) )" }, { /* url */ "/ROOT/random?content=non-existent-book&userlang=hy", + expected_page_title=="Սխալ հասցե" && expected_body==R"( -

Not Found

+

Սխալ հասցե

Գիրքը բացակայում է՝ non-existent-book

@@ -596,8 +597,9 @@ TEST_F(ServerTest, 404WithBodyTesting) )" }, { /* url */ "/ROOT/catalog/?userlang=hy", + expected_page_title=="Սխալ հասցե" && expected_body==R"( -

Not Found

+

Սխալ հասցե

Սխալ հասցե՝ /ROOT/catalog/

@@ -612,8 +614,9 @@ TEST_F(ServerTest, 404WithBodyTesting) )" }, { /* url */ "/ROOT/catalog/invalid_endpoint?userlang=hy", + expected_page_title=="Սխալ հասցե" && expected_body==R"( -

Not Found

+

Սխալ հասցե

Սխալ հասցե՝ /ROOT/catalog/invalid_endpoint