diff options
| author | Magnus Auvinen <magnus.auvinen@gmail.com> | 2010-05-29 07:25:38 +0000 |
|---|---|---|
| committer | Magnus Auvinen <magnus.auvinen@gmail.com> | 2010-05-29 07:25:38 +0000 |
| commit | 72c06a258940696093f255fb1061beb58e1cdd0b (patch) | |
| tree | 36b9a7712eec2d4f07837eab9c38ef1c5af85319 /src/game/localization.h | |
| parent | e56feb597bc743677633432f77513b02907fd169 (diff) | |
| download | zcatch-72c06a258940696093f255fb1061beb58e1cdd0b.tar.gz zcatch-72c06a258940696093f255fb1061beb58e1cdd0b.zip | |
copied refactor to trunk
Diffstat (limited to 'src/game/localization.h')
| -rw-r--r-- | src/game/localization.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/game/localization.h b/src/game/localization.h new file mode 100644 index 00000000..2e96ef04 --- /dev/null +++ b/src/game/localization.h @@ -0,0 +1,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); + + 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 |