2 * ===============================================================
3 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
4 * ===============================================================
6 * This file is not open source and may not be copied without explicit
7 * written permission of AlliedModders LLC. This file may not be redistributed
8 * in whole or significant part.
9 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
14 #ifndef _INCLUDE_SOURCEMOD_TRANSLATOR_H_
15 #define _INCLUDE_SOURCEMOD_TRANSLATOR_H_
18 #include <sh_string.h>
19 #include <sh_vector.h>
20 #include "sm_globals.h"
21 #include "sm_memtable.h"
22 #include "ITextParsers.h"
24 #define MAX_TRANSLATE_PARAMS 32
26 /* :TODO: write a templatized version of tries? */
28 using namespace SourceHook;
52 class CPhraseFile : public ITextListener_SMC
55 CPhraseFile(CTranslator *pTranslator, const char *file);
59 const char *GetFilename();
60 const char *GetTranslation(const Translation *pTrans, int **fmt_order, unsigned int *fmt_count);
61 public: //ITextListener_SMC
62 void ReadSMC_ParseStart();
63 void ReadSMC_ParseEnd(bool halted, bool failed);
64 SMCParseResult ReadSMC_NewSection(const char *name, bool opt_quotes);
65 SMCParseResult ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes);
66 SMCParseResult ReadSMC_LeavingSection();
67 SMCParseResult ReadSMC_RawLine(const char *line, unsigned int curline);
69 void ParseError(const char *message, ...);
70 void ParseWarning(const char *message, ...);
72 Trie *m_pPhraseLookup;
74 CTranslator *m_pTranslator;
75 PhraseParseState m_ParseState;
77 BaseMemTable *m_pMemory;
78 BaseStringTable *m_pStringTab;
79 unsigned int m_LangCount;
81 String m_LastPhraseString;
82 unsigned int m_CurLine;
86 class CTranslator : public ITextListener_SMC
91 public: //ITextListener_SMC
92 void ReadSMC_ParseStart();
93 SMCParseResult ReadSMC_NewSection(const char *name, bool opt_quotes);
94 SMCParseResult ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes);
95 SMCParseResult ReadSMC_LeavingSection();
97 void RebuildLanguageDatabase(const char *lang_header_file);
98 unsigned int FindOrAddPhraseFile(const char *phrase_file);
99 BaseStringTable *GetStringTable();
100 unsigned int GetLanguageCount();
101 bool GetLanguageByCode(const char *code, unsigned int *index);
102 size_t Translate(char *buffer, size_t maxlength, const Translation *pTrans);
104 CVector<Language *> m_Languages;
105 CVector<CPhraseFile *> m_Files;
106 BaseStringTable *m_pStringTab;
107 Trie *m_pLCodeLookup;
108 bool m_InLanguageSection;
109 String m_CustomError;
112 extern CTranslator g_Translator;
114 #endif //_INCLUDE_SOURCEMOD_TRANSLATOR_H_