/
Lang.h
60 lines (41 loc) · 1.44 KB
/
Lang.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
// Copyright © 2008-2024 Pioneer Developers. See AUTHORS.txt for details
// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
#ifndef _LANG_H
#define _LANG_H
#include "IterationProxy.h"
#include <SDL_stdinc.h>
#include <map>
#include <string>
#include <string_view>
#include <vector>
namespace Lang {
class Resource {
public:
using StringMap = std::map<std::string, std::string, std::less<>>;
Resource(std::string_view name, std::string_view langCode) :
m_name(name),
m_langCode(langCode),
m_loaded(false) {}
std::string_view GetName() const { return m_name; }
std::string_view GetLangCode() const { return m_langCode; }
bool Load();
Uint32 GetNumStrings() const { return static_cast<Uint32>(m_strings.size()); }
const std::string &Get(std::string_view token) const;
static std::vector<std::string> GetAvailableLanguages(std::string_view resourceName);
IterationProxy<StringMap> GetStrings() { return MakeIterationProxy(m_strings); }
const IterationProxy<const StringMap> GetStrings() const { return MakeIterationProxy(m_strings); }
private:
std::string m_name;
std::string m_langCode;
bool m_loaded;
StringMap m_strings;
};
// declare all strings
#define DECLARE_STRING(x) extern char x[];
#include "LangStrings.inc.h"
#undef DECLARE_STRING
void MakeCore(Resource &res);
const Resource &GetCore();
Resource &GetResource(std::string_view name, std::string_view langCode);
} // namespace Lang
#endif