ddnet/src/game/localization.h

62 lines
1.5 KiB
C
Raw Normal View History

2010-11-20 10:37:14 +00:00
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
2010-05-29 07:25:38 +00:00
#ifndef GAME_LOCALIZATION_H
#define GAME_LOCALIZATION_H
#include <base/tl/string.h>
#include <base/tl/sorted_array.h>
class CLocalizationDatabase
{
class CString
{
public:
unsigned m_Hash;
2010-05-29 07:25:38 +00:00
// TODO: do this as an const char * and put everything on a incremental heap
string m_Replacement;
bool operator <(const CString &Other) const { return m_Hash < Other.m_Hash; }
bool operator <=(const CString &Other) const { return m_Hash <= Other.m_Hash; }
bool operator ==(const CString &Other) const { return m_Hash == Other.m_Hash; }
};
sorted_array<CString> m_Strings;
int m_VersionCounter;
2010-05-29 07:25:38 +00:00
int m_CurrentVersion;
2010-05-29 07:25:38 +00:00
public:
CLocalizationDatabase();
2010-10-06 21:07:35 +00:00
bool Load(const char *pFilename, class IStorage *pStorage, class IConsole *pConsole);
2010-05-29 07:25:38 +00:00
int Version() { return m_CurrentVersion; }
2010-05-29 07:25:38 +00:00
void AddString(const char *pOrgStr, const char *pNewStr);
const char *FindString(unsigned Hash);
};
extern CLocalizationDatabase g_Localization;
class CLocConstString
{
const char *m_pDefaultStr;
const char *m_pCurrentStr;
unsigned m_Hash;
int m_Version;
public:
CLocConstString(const char *pStr);
void Reload();
2010-05-29 07:25:38 +00:00
inline operator const char *()
{
if(m_Version != g_Localization.Version())
Reload();
return m_pCurrentStr;
}
};
extern const char *Localize(const char *pStr)
GNUC_ATTRIBUTE((format_arg(1)));
2010-05-29 07:25:38 +00:00
#endif