Unmustached i18n::Parameters

This commit is contained in:
Veloman Yunkan 2024-01-09 23:38:44 +04:00
parent 0b542fe66d
commit f298acd45f
2 changed files with 8 additions and 3 deletions

View File

@ -112,8 +112,12 @@ std::string expandParameterizedString(const std::string& lang,
const std::string& key, const std::string& key,
const Parameters& params) const Parameters& params)
{ {
kainjow::mustache::object mustacheParams;
for( const auto& kv : params ) {
mustacheParams[kv.first] = kv.second;
}
const std::string tmpl = getTranslatedString(lang, key); const std::string tmpl = getTranslatedString(lang, key);
return render_template(tmpl, params); return render_template(tmpl, mustacheParams);
} }
} // namespace i18n } // namespace i18n

View File

@ -20,6 +20,7 @@
#ifndef KIWIX_SERVER_I18N #ifndef KIWIX_SERVER_I18N
#define KIWIX_SERVER_I18N #define KIWIX_SERVER_I18N
#include <map>
#include <string> #include <string>
#include <mustache.hpp> #include <mustache.hpp>
@ -44,7 +45,7 @@ std::string getTranslatedString(const std::string& lang, const std::string& key)
namespace i18n namespace i18n
{ {
typedef kainjow::mustache::object Parameters; typedef std::map<std::string, std::string> Parameters;
std::string expandParameterizedString(const std::string& lang, std::string expandParameterizedString(const std::string& lang,
const std::string& key, const std::string& key,
@ -96,7 +97,7 @@ private:
class ParameterizedMessage class ParameterizedMessage
{ {
public: // types public: // types
typedef kainjow::mustache::object Parameters; typedef i18n::Parameters Parameters;
public: // functions public: // functions
ParameterizedMessage(const std::string& msgId, const Parameters& params) ParameterizedMessage(const std::string& msgId, const Parameters& params)