Demo of error page translation

This commit demonstrates front-end-side translation of an error page
for a URL like /viewer#INVALIDBOOK/whatever (where INVALIDBOOK should
be a book name NOT present in the library).

Known issues:

- This change breaks a couple of subtests in the
  ServerTest.Http404HtmlError unit test.

- Changing the UI language while an error page is displayed in the
  viewer doesn't retranslate it.
This commit is contained in:
Veloman Yunkan
2024-01-06 18:57:03 +04:00
committed by Matthieu Gautier
parent bceba4da06
commit 103a4516db
6 changed files with 71 additions and 12 deletions

View File

@ -1133,7 +1133,7 @@ std::unique_ptr<Response> InternalServer::handle_content(const RequestContext& r
if (archive == nullptr) {
const std::string searchURL = m_root + "/search?pattern=" + kiwix::urlEncode(pattern);
return UrlNotFoundResponse(request)
return UrlNotFoundResponse(request, true)
+ suggestSearchMsg(searchURL, kiwix::urlDecode(pattern));
}

View File

@ -334,16 +334,20 @@ HTTPErrorResponse::HTTPErrorResponse(const RequestContext& request,
});
}
HTTP404Response::HTTP404Response(const RequestContext& request)
HTTP404Response::HTTP404Response(const RequestContext& request,
bool includeKiwixResponseData)
: HTTPErrorResponse(request,
MHD_HTTP_NOT_FOUND,
"404-page-title",
"404-page-heading")
"404-page-heading",
std::string(),
includeKiwixResponseData)
{
}
UrlNotFoundResponse::UrlNotFoundResponse(const RequestContext& request)
: HTTP404Response(request)
UrlNotFoundResponse::UrlNotFoundResponse(const RequestContext& request,
bool includeKiwixResponseData)
: HTTP404Response(request, includeKiwixResponseData)
{
const std::string requestUrl = urlDecode(m_request.get_full_url(), false);
*this += ParameterizedMessage("url-not-found", {{"url", requestUrl}});

View File

@ -160,12 +160,14 @@ struct HTTPErrorResponse : ContentResponseBlueprint
struct HTTP404Response : HTTPErrorResponse
{
explicit HTTP404Response(const RequestContext& request);
explicit HTTP404Response(const RequestContext& request,
bool includeKiwixResponseData = false);
};
struct UrlNotFoundResponse : HTTP404Response
{
explicit UrlNotFoundResponse(const RequestContext& request);
explicit UrlNotFoundResponse(const RequestContext& request,
bool includeKiwixResponseData = false);
};
struct HTTP400Response : HTTPErrorResponse