mirror of https://github.com/kiwix/libkiwix.git
Enter ParameterizedMessage
This commit is contained in:
parent
202ec81d8b
commit
387f977d6c
|
@ -106,4 +106,9 @@ std::string expandParameterizedString(const std::string& lang,
|
||||||
|
|
||||||
} // namespace i18n
|
} // namespace i18n
|
||||||
|
|
||||||
|
std::string ParameterizedMessage::getText(const std::string& lang) const
|
||||||
|
{
|
||||||
|
return i18n::expandParameterizedString(lang, msgId, params);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace kiwix
|
} // namespace kiwix
|
||||||
|
|
|
@ -52,6 +52,24 @@ std::string expandParameterizedString(const std::string& lang,
|
||||||
|
|
||||||
} // namespace i18n
|
} // namespace i18n
|
||||||
|
|
||||||
|
struct ParameterizedMessage
|
||||||
|
{
|
||||||
|
public: // types
|
||||||
|
typedef kainjow::mustache::object Parameters;
|
||||||
|
|
||||||
|
public: // functions
|
||||||
|
ParameterizedMessage(const std::string& msgId, const Parameters& params)
|
||||||
|
: msgId(msgId)
|
||||||
|
, params(params)
|
||||||
|
{}
|
||||||
|
|
||||||
|
std::string getText(const std::string& lang) const;
|
||||||
|
|
||||||
|
private: // data
|
||||||
|
const std::string msgId;
|
||||||
|
const Parameters params;
|
||||||
|
};
|
||||||
|
|
||||||
} // namespace kiwix
|
} // namespace kiwix
|
||||||
|
|
||||||
#endif // KIWIX_SERVER_I18N
|
#endif // KIWIX_SERVER_I18N
|
||||||
|
|
|
@ -21,7 +21,6 @@
|
||||||
#include "request_context.h"
|
#include "request_context.h"
|
||||||
#include "internalServer.h"
|
#include "internalServer.h"
|
||||||
#include "kiwixlib-resources.h"
|
#include "kiwixlib-resources.h"
|
||||||
#include "i18n.h"
|
|
||||||
|
|
||||||
#include "tools/regexTools.h"
|
#include "tools/regexTools.h"
|
||||||
#include "tools/stringTools.h"
|
#include "tools/stringTools.h"
|
||||||
|
@ -132,12 +131,7 @@ HTTP404HtmlResponse::HTTP404HtmlResponse(const InternalServer& server,
|
||||||
HTTPErrorHtmlResponse& HTTP404HtmlResponse::operator+(UrlNotFoundMsg /*unused*/)
|
HTTPErrorHtmlResponse& HTTP404HtmlResponse::operator+(UrlNotFoundMsg /*unused*/)
|
||||||
{
|
{
|
||||||
const std::string requestUrl = m_request.get_full_url();
|
const std::string requestUrl = m_request.get_full_url();
|
||||||
const auto urlNotFoundMsg = i18n::expandParameterizedString(
|
return *this + ParameterizedMessage("url-not-found", {{"url", requestUrl}});
|
||||||
"en", // FIXME: hardcoded language
|
|
||||||
"url-not-found",
|
|
||||||
{{"url", requestUrl}}
|
|
||||||
);
|
|
||||||
return *this + urlNotFoundMsg;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HTTPErrorHtmlResponse& HTTPErrorHtmlResponse::operator+(const std::string& msg)
|
HTTPErrorHtmlResponse& HTTPErrorHtmlResponse::operator+(const std::string& msg)
|
||||||
|
@ -146,6 +140,12 @@ HTTPErrorHtmlResponse& HTTPErrorHtmlResponse::operator+(const std::string& msg)
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HTTPErrorHtmlResponse& HTTPErrorHtmlResponse::operator+(const ParameterizedMessage& details)
|
||||||
|
{
|
||||||
|
return *this + details.getText(m_request.get_user_language());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
HTTP400HtmlResponse::HTTP400HtmlResponse(const InternalServer& server,
|
HTTP400HtmlResponse::HTTP400HtmlResponse(const InternalServer& server,
|
||||||
const RequestContext& request)
|
const RequestContext& request)
|
||||||
: HTTPErrorHtmlResponse(server,
|
: HTTPErrorHtmlResponse(server,
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
#include "byte_range.h"
|
#include "byte_range.h"
|
||||||
#include "entry.h"
|
#include "entry.h"
|
||||||
#include "etag.h"
|
#include "etag.h"
|
||||||
|
#include "i18n.h"
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#include "microhttpd_wrapper.h"
|
#include "microhttpd_wrapper.h"
|
||||||
|
@ -189,6 +190,7 @@ struct HTTPErrorHtmlResponse : ContentResponseBlueprint
|
||||||
|
|
||||||
using ContentResponseBlueprint::operator+;
|
using ContentResponseBlueprint::operator+;
|
||||||
HTTPErrorHtmlResponse& operator+(const std::string& msg);
|
HTTPErrorHtmlResponse& operator+(const std::string& msg);
|
||||||
|
HTTPErrorHtmlResponse& operator+(const ParameterizedMessage& errorDetails);
|
||||||
};
|
};
|
||||||
|
|
||||||
class UrlNotFoundMsg {};
|
class UrlNotFoundMsg {};
|
||||||
|
|
Loading…
Reference in New Issue