44 lines
1.3 KiB
C
44 lines
1.3 KiB
C
|
//
|
||
|
// Created by bbr on 14.06.22..
|
||
|
//
|
||
|
|
||
|
#ifndef SCHEMEEDITOR_MESSAGE_SOURCE_H
|
||
|
#define SCHEMEEDITOR_MESSAGE_SOURCE_H
|
||
|
|
||
|
|
||
|
#include <map>
|
||
|
#include <string>
|
||
|
#include "comdel/domain/value.h"
|
||
|
|
||
|
class MessageSource {
|
||
|
private:
|
||
|
MessageSource() {
|
||
|
loadDefaults();
|
||
|
}
|
||
|
|
||
|
void add(const std::string& key, std::string message);
|
||
|
std::string populateMessage(std::string message, std::map<std::string, std::string> parametars);
|
||
|
std::string replacePlaceholder(std::string message, std::string key, std::string value);
|
||
|
|
||
|
std::map<std::string, std::string> messages;
|
||
|
|
||
|
public:
|
||
|
static MessageSource *instance();
|
||
|
static std::map<std::string, std::string> map(std::map<std::string, domain::Value> values);
|
||
|
|
||
|
std::string get(const std::string& key);
|
||
|
std::string get(const std::string& key, std::map<std::string, std::string> parametars);
|
||
|
|
||
|
void loadDefaults();
|
||
|
void load(std::map<std::string, std::string> messages);
|
||
|
};
|
||
|
|
||
|
#define MESSAGE_PARAM(key, params) MessageSource::instance()->get(key, params)
|
||
|
#define MESSAGE(key) MessageSource::instance()->get(key)
|
||
|
#define MESSAGE_MAP(value) MessageSource::instance()->map(value)
|
||
|
|
||
|
#define QMESSAGE_PARAM(key, params) QString::fromStdString(MessageSource::instance()->get(key, params))
|
||
|
#define QMESSAGE(key) QString::fromStdString(MessageSource::instance()->get(key))
|
||
|
|
||
|
#endif //SCHEMEEDITOR_MESSAGE_SOURCE_H
|