-
Notifications
You must be signed in to change notification settings - Fork 0
/
messages.h
67 lines (48 loc) · 1.48 KB
/
messages.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef __MESSAGES_H__
#define __MESSAGES_H__
#include <map>
#include <string>
#include <stdarg.h>
class Resource;
class Formatter;
class Buffer;
/// Localized messages formatter
class Messages
{
private:
typedef struct {
int score;
Formatter *message;
} ScoredStr;
typedef std::map<std::wstring, ScoredStr> StrMap;
StrMap messages;
public:
/// Create empty messages table.
Messages();
~Messages();
public:
/// Load message tables from resources.
void load();
/// Get simple text string
/// \param key message key
std::wstring getMessage(const std::wstring &key) const;
/// Shorter alias for getMessage
/// \param key message key
std::wstring operator [](const std::wstring &key) const {
return getMessage(key);
};
/// Format message
/// \param key message key
std::wstring format(const wchar_t *key, ...) const;
/// Shorter alias for format
/// \param key message key
std::wstring operator ()(const wchar_t *key, ...) const;
/// Load messages from resource
/// \param res resource
void loadFromResource(Resource *res, Buffer *buffer);
private:
void loadBundle(int score, unsigned char *data, size_t size);
std::wstring format(const wchar_t *key, va_list ap) const;
};
extern Messages msg;
#endif