about summary refs log tree commit diff
path: root/src/game/localization.h
blob: e117c4ffe5d14f91e16fa3eef8b3b8d9c60d9ae0 (plain)
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
#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;
		
		// 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_CurrentVersion;
	
public:
	CLocalizationDatabase();

	bool Load(const char *pFilename, class IConsole *pConsole);

	int Version() { return m_CurrentVersion; }
	
	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();
	
	inline operator const char *()
	{
		if(m_Version != g_Localization.Version())
			Reload();
		return m_pCurrentStr;
	}
};


extern const char *Localize(const char *pStr);
#endif