-
Notifications
You must be signed in to change notification settings - Fork 1
/
Language.cpp
102 lines (81 loc) · 1.78 KB
/
Language.cpp
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include "Language.h"
#include "../flhookplugin_sdk/headers/FLHook.h"
#include "Tools.h"
#include "Print.h"
namespace raincious
{
namespace FLHookPlugin
{
namespace Revelation
{
Language* Language::Get()
{
static Language Instance;
return &Instance;
}
Language::Language()
{
}
Language::~Language()
{
}
void Language::import(const char* path)
{
INI_Reader ini;
string key = "";
wstring val = L"";
if (!ini.open(path, false))
{
return;
}
while (ini.read_header())
{
if (ini.is_header("Languages"))
{
while (ini.read_value())
{
if (ini.is_value("String"))
{
if (parse(ini.get_value_string(), key, val))
{
if (languages.find(key.c_str()) != languages.end())
{
Print::Info("Language string \"" + key + "\" already been defined. It will be overwrited.", "");
}
else
{
Print::Debug("Adding language string \"" + key + "\" ...", "");
}
languages[key.c_str()] = val;
}
}
}
}
}
ini.close();
}
const wstring& Language::lang(const string key, const wstring defaultStr)
{
if (languages.find(key) == languages.end())
{
languages[key] = defaultStr;
Print::Debug(string("Language string \"").append(key).append("\" was not defined, using default instead."), "");
}
return languages[key];
}
bool Language::parse(string input, string &key, wstring &val)
{
int cutPos = 0;
if ((cutPos = input.find_first_of(",")) == string::npos)
{
return false;
}
key = input.substr(0, cutPos);
val = stows(input.substr(cutPos + 1, input.length()));
trim(key);
trim(val);
return true;
}
}
}
}