DDraceNetwork Docs
localization.h
Go to the documentation of this file.
1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#ifndef GAME_LOCALIZATION_H
4#define GAME_LOCALIZATION_H
5
6#include <base/system.h> // GNUC_ATTRIBUTE
7
9
10#include <string>
11#include <vector>
12
14{
15public:
16 CLanguage() = default;
17 CLanguage(const char *pName, const char *pFileName, int Code, const std::vector<std::string> &vLanguageCodes) :
18 m_Name(pName), m_FileName(pFileName), m_CountryCode(Code), m_vLanguageCodes(vLanguageCodes) {}
19
20 std::string m_Name;
21 std::string m_FileName;
23 std::vector<std::string> m_vLanguageCodes;
24
25 bool operator<(const CLanguage &Other) const { return m_Name < Other.m_Name; }
26};
27
29{
30 class CString
31 {
32 public:
33 unsigned m_Hash;
34 unsigned m_ContextHash;
35 const char *m_pReplacement;
36
38 CString(unsigned Hash, unsigned ContextHash, const char *pReplacement) :
39 m_Hash(Hash), m_ContextHash(ContextHash), m_pReplacement(pReplacement)
40 {
41 }
42
43 bool operator<(const CString &Other) const { return m_Hash < Other.m_Hash || (m_Hash == Other.m_Hash && m_ContextHash < Other.m_ContextHash); }
44 bool operator<=(const CString &Other) const { return m_Hash < Other.m_Hash || (m_Hash == Other.m_Hash && m_ContextHash <= Other.m_ContextHash); }
45 bool operator==(const CString &Other) const { return m_Hash == Other.m_Hash && m_ContextHash == Other.m_ContextHash; }
46 };
47
48 std::vector<CLanguage> m_vLanguages;
49 std::vector<CString> m_vStrings;
51
52public:
53 void LoadIndexfile(class IStorage *pStorage, class IConsole *pConsole);
54 const std::vector<CLanguage> &Languages() const { return m_vLanguages; }
55 void SelectDefaultLanguage(class IConsole *pConsole, char *pFilename, size_t Length) const;
56
57 bool Load(const char *pFilename, class IStorage *pStorage, class IConsole *pConsole);
58
59 void AddString(const char *pOrgStr, const char *pNewStr, const char *pContext);
60 const char *FindString(unsigned Hash, unsigned ContextHash) const;
61};
62
64
65extern const char *Localize(const char *pStr, const char *pContext = "")
66 GNUC_ATTRIBUTE((format_arg(1)));
67#endif
Definition: memheap.h:11
Definition: localization.h:14
bool operator<(const CLanguage &Other) const
Definition: localization.h:25
std::string m_Name
Definition: localization.h:20
std::string m_FileName
Definition: localization.h:21
int m_CountryCode
Definition: localization.h:22
std::vector< std::string > m_vLanguageCodes
Definition: localization.h:23
CLanguage()=default
CLanguage(const char *pName, const char *pFileName, int Code, const std::vector< std::string > &vLanguageCodes)
Definition: localization.h:17
Definition: localization.h:31
CString(unsigned Hash, unsigned ContextHash, const char *pReplacement)
Definition: localization.h:38
CString()
Definition: localization.h:37
const char * m_pReplacement
Definition: localization.h:35
unsigned m_ContextHash
Definition: localization.h:34
bool operator<(const CString &Other) const
Definition: localization.h:43
bool operator<=(const CString &Other) const
Definition: localization.h:44
bool operator==(const CString &Other) const
Definition: localization.h:45
unsigned m_Hash
Definition: localization.h:33
Definition: localization.h:29
const char * FindString(unsigned Hash, unsigned ContextHash) const
Definition: localization.cpp:245
void SelectDefaultLanguage(class IConsole *pConsole, char *pFilename, size_t Length) const
Definition: localization.cpp:107
CHeap m_StringsHeap
Definition: localization.h:50
void LoadIndexfile(class IStorage *pStorage, class IConsole *pConsole)
Definition: localization.cpp:18
void AddString(const char *pOrgStr, const char *pNewStr, const char *pContext)
Definition: localization.cpp:240
const std::vector< CLanguage > & Languages() const
Definition: localization.h:54
std::vector< CString > m_vStrings
Definition: localization.h:49
std::vector< CLanguage > m_vLanguages
Definition: localization.h:48
bool Load(const char *pFilename, class IStorage *pStorage, class IConsole *pConsole)
Definition: localization.cpp:166
Definition: console.h:18
Definition: storage.h:20
const char * Localize(const char *pStr, const char *pContext="") GNUC_ATTRIBUTE((format_arg(1)))
Definition: localization.cpp:12
CLocalizationDatabase g_Localization
Definition: localization.cpp:268
#define GNUC_ATTRIBUTE(x)
Definition: log.h:10