From 3188b0afe63014bddfc53978a0f3bf48ccd88fed Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Wed, 29 Nov 2023 14:18:06 +0400 Subject: [PATCH] Translated a hard-coded error message --- src/server/response.cpp | 3 +-- static/skin/i18n/en.json | 1 + static/skin/i18n/qqq.json | 1 + static/skin/i18n/test.json | 2 ++ test/server.cpp | 13 +++++++++++++ 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/server/response.cpp b/src/server/response.cpp index bc8c85e51..5399cfc58 100644 --- a/src/server/response.cpp +++ b/src/server/response.cpp @@ -239,8 +239,7 @@ HTTPErrorResponse& HTTP400Response::operator+(InvalidUrlMsg /*unused*/) if (!query.empty()) { requestUrl += "?" + encodeDiples(query); } - kainjow::mustache::mustache msgTmpl(R"(The requested URL "{{{url}}}" is not a valid request.)"); - return *this + msgTmpl.render({"url", requestUrl}); + return *this + ParameterizedMessage("invalid-request", {{"url", requestUrl}}); } HTTP500Response::HTTP500Response(const InternalServer& server, diff --git a/static/skin/i18n/en.json b/static/skin/i18n/en.json index aaea04978..97a71d558 100644 --- a/static/skin/i18n/en.json +++ b/static/skin/i18n/en.json @@ -12,6 +12,7 @@ , "suggest-search" : "Make a full text search for {{PATTERN}}" , "random-article-failure" : "Oops! Failed to pick a random article :(" , "invalid-raw-data-type" : "{{DATATYPE}} is not a valid request for raw content." + , "invalid-request" : "The requested URL \"{{{url}}}\" is not a valid request." , "no-value-for-arg": "No value provided for argument {{ARGUMENT}}" , "no-query" : "No query provided." , "raw-entry-not-found" : "Cannot find {{DATATYPE}} entry {{ENTRY}}" diff --git a/static/skin/i18n/qqq.json b/static/skin/i18n/qqq.json index 18c97a609..d647a75e4 100644 --- a/static/skin/i18n/qqq.json +++ b/static/skin/i18n/qqq.json @@ -15,6 +15,7 @@ "suggest-search": "Suggest a search when the URL points to a non existing article", "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'", + "invalid-request" : "Error text for malformed URLs.", "no-value-for-arg": "Error text when no value has been provided for ARGUMENT in the request's query string", "no-query": "Error text when no query has been provided for fulltext search", "raw-entry-not-found": "Entry requested via the /raw endpoint was not found", diff --git a/static/skin/i18n/test.json b/static/skin/i18n/test.json index 7686471ab..29def8eac 100644 --- a/static/skin/i18n/test.json +++ b/static/skin/i18n/test.json @@ -40,4 +40,6 @@ , "download-links-heading": "[I18N] Download links for {{BOOK_TITLE}} [TESTING]" , "download-links-title": "[I18N TESTING]Download book" , "preview-book": "[I18N] Preview [TESTING]" + , "no-query" : "[I18N TESTING] Kiwix can read your thoughts but it is against GDPR. Please provide your query explicitly." + , "invalid-request" : "[I18N TESTING] Invalid URL: \"{{{url}}}\"" } diff --git a/test/server.cpp b/test/server.cpp index 73ba7b1ff..86171cd4a 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -927,6 +927,19 @@ TEST_F(ServerTest, Http400HtmlError) Too many books requested (4) where limit is 3

)" }, + + // Testing of translation + { /* url */ "/ROOT%23%3F/search?content=zimfile&userlang=test", + expected_page_title=="[I18N TESTING] Invalid request ($400 fine must be paid)" && + expected_body==R"( +

[I18N TESTING] -400 karma for an invalid request

+

+ [I18N TESTING] Invalid URL: "/ROOT%23%3F/search?content=zimfile&userlang=test" +

+

+ [I18N TESTING] Kiwix can read your thoughts but it is against GDPR. Please provide your query explicitly. +

+)" }, }; for ( const auto& t : testData ) {