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;
46 const char *szPhrase; /**< Translated phrase. */
47 unsigned int fmt_count; /**< Number of format parameters. */
48 int *fmt_order; /**< Format phrase order. */
54 Trans_BadLanguage = 1,
56 Trans_BadPhraseLanguage = 3
59 class CPhraseFile : public ITextListener_SMC
62 CPhraseFile(CTranslator *pTranslator, const char *file);
66 const char *GetFilename();
67 TransError GetTranslation(const char *szPhrase, unsigned int lang_id, Translation *pTrans);
68 public: //ITextListener_SMC
69 void ReadSMC_ParseStart();
70 void ReadSMC_ParseEnd(bool halted, bool failed);
71 SMCParseResult ReadSMC_NewSection(const char *name, bool opt_quotes);
72 SMCParseResult ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes);
73 SMCParseResult ReadSMC_LeavingSection();
74 SMCParseResult ReadSMC_RawLine(const char *line, unsigned int curline);
76 void ParseError(const char *message, ...);
77 void ParseWarning(const char *message, ...);
79 Trie *m_pPhraseLookup;
81 CTranslator *m_pTranslator;
82 PhraseParseState m_ParseState;
84 BaseMemTable *m_pMemory;
85 BaseStringTable *m_pStringTab;
86 unsigned int m_LangCount;
88 String m_LastPhraseString;
89 unsigned int m_CurLine;
93 class CTranslator : public ITextListener_SMC
98 public: //ITextListener_SMC
99 void ReadSMC_ParseStart();
100 SMCParseResult ReadSMC_NewSection(const char *name, bool opt_quotes);
101 SMCParseResult ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes);
102 SMCParseResult ReadSMC_LeavingSection();
104 void RebuildLanguageDatabase(const char *lang_header_file);
105 unsigned int FindOrAddPhraseFile(const char *phrase_file);
106 BaseStringTable *GetStringTable();
107 unsigned int GetLanguageCount();
108 bool GetLanguageByCode(const char *code, unsigned int *index);
109 size_t Translate(char *buffer, size_t maxlength, void **params, const Translation *pTrans);
110 CPhraseFile *GetFileByIndex(unsigned int index);
112 CVector<Language *> m_Languages;
113 CVector<CPhraseFile *> m_Files;
114 BaseStringTable *m_pStringTab;
115 Trie *m_pLCodeLookup;
116 bool m_InLanguageSection;
117 String m_CustomError;
120 extern CTranslator g_Translator;
122 #endif //_INCLUDE_SOURCEMOD_TRANSLATOR_H_