Pioneer
Loading...
Searching...
No Matches
Lang.h
Go to the documentation of this file.
1// Copyright © 2008-2024 Pioneer Developers. See AUTHORS.txt for details
2// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3
4#ifndef _LANG_H
5#define _LANG_H
6
7#include "IterationProxy.h"
8#include <SDL_stdinc.h>
9#include <map>
10#include <string>
11#include <string_view>
12#include <vector>
13
14namespace Lang {
15
16 class Resource {
17 public:
18 using StringMap = std::map<std::string, std::string, std::less<>>;
19
20 Resource(std::string_view name, std::string_view langCode) :
21 m_name(name),
22 m_langCode(langCode),
23 m_loaded(false) {}
24
25 std::string_view GetName() const { return m_name; }
26 std::string_view GetLangCode() const { return m_langCode; }
27
28 bool Load();
29
30 Uint32 GetNumStrings() const { return static_cast<Uint32>(m_strings.size()); }
31
32 const std::string &Get(std::string_view token) const;
33
34 static std::vector<std::string> GetAvailableLanguages(std::string_view resourceName);
35
38
39 private:
40 std::string m_name;
41 std::string m_langCode;
42
43 bool m_loaded;
44
45 StringMap m_strings;
46 };
47
48// declare all strings
49#define DECLARE_STRING(x) extern char x[];
50#include "LangStrings.inc.h"
51#undef DECLARE_STRING
52
53 void MakeCore(Resource &res);
54 const Resource &GetCore();
55
56 Resource &GetResource(std::string_view name, std::string_view langCode);
57
58} // namespace Lang
59
60#endif
IterationProxy< Container > MakeIterationProxy(Container &container)
Definition: IterationProxy.h:51
Definition: IterationProxy.h:13
Definition: Lang.h:16
std::string_view GetLangCode() const
Definition: Lang.h:26
const IterationProxy< const StringMap > GetStrings() const
Definition: Lang.h:37
Uint32 GetNumStrings() const
Definition: Lang.h:30
std::map< std::string, std::string, std::less<> > StringMap
Definition: Lang.h:18
bool Load()
Definition: Lang.cpp:36
Resource(std::string_view name, std::string_view langCode)
Definition: Lang.h:20
IterationProxy< StringMap > GetStrings()
Definition: Lang.h:36
static std::vector< std::string > GetAvailableLanguages(std::string_view resourceName)
Definition: Lang.cpp:117
const std::string & Get(std::string_view token) const
Definition: Lang.cpp:108
std::string_view GetName() const
Definition: Lang.h:25
Definition: Lang.cpp:15
Resource & GetResource(std::string_view name, std::string_view langCode)
Definition: Lang.cpp:209
void MakeCore(Resource &res)
Definition: Lang.cpp:174
const Resource & GetCore()
Definition: Lang.cpp:202