Executable memory is now provided by MM:S's allocator, this should reduce virtual memory usage.
3 * =============================================================================
5 * Copyright (C) 2004-2007 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #ifndef _INCLUDE_SOURCEMOD_TRANSLATOR_H_
33 #define _INCLUDE_SOURCEMOD_TRANSLATOR_H_
36 #include <sh_string.h>
37 #include <sh_vector.h>
38 #include "sm_globals.h"
39 #include "sm_memtable.h"
40 #include "ITextParsers.h"
42 #define MAX_TRANSLATE_PARAMS 32
43 #define CORELANG_ENGLISH 0
45 /* :TODO: write a templatized version of tries? */
47 using namespace SourceHook;
65 const char *szPhrase; /**< Translated phrase. */
66 unsigned int fmt_count; /**< Number of format parameters. */
67 int *fmt_order; /**< Format phrase order. */
70 #define LANGUAGE_ENGLISH 0
75 Trans_BadLanguage = 1,
77 Trans_BadPhraseLanguage = 3,
78 Trans_BadPhraseFile = 4,
81 class CPhraseFile : public ITextListener_SMC
84 CPhraseFile(Translator *pTranslator, const char *file);
88 const char *GetFilename();
89 TransError GetTranslation(const char *szPhrase, unsigned int lang_id, Translation *pTrans);
90 public: //ITextListener_SMC
91 void ReadSMC_ParseStart();
92 SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name);
93 SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value);
94 SMCResult ReadSMC_LeavingSection(const SMCStates *states);
95 void ReadSMC_ParseEnd(bool halted, bool failed);
97 void ParseError(const char *message, ...);
98 void ParseWarning(const char *message, ...);
100 Trie *m_pPhraseLookup;
102 Translator *m_pTranslator;
103 PhraseParseState m_ParseState;
105 BaseMemTable *m_pMemory;
106 BaseStringTable *m_pStringTab;
107 unsigned int m_LangCount;
109 String m_LastPhraseString;
114 public ITextListener_SMC,
120 public: // SMGlobalClass
121 ConfigResult OnSourceModConfigChanged(const char *key,
126 void OnSourceModAllInitialized();
127 void OnSourceModLevelChange(const char *mapName);
128 public: // ITextListener_SMC
129 void ReadSMC_ParseStart();
130 SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name);
131 SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value);
132 SMCResult ReadSMC_LeavingSection(const SMCStates *states);
134 void RebuildLanguageDatabase(const char *lang_header_file);
135 unsigned int FindOrAddPhraseFile(const char *phrase_file);
136 BaseStringTable *GetStringTable();
137 unsigned int GetLanguageCount();
138 bool GetLanguageInfo(unsigned int number, const char **code, const char **name);
139 bool GetLanguageByCode(const char *code, unsigned int *index);
140 bool GetLanguageByName(const char *name, unsigned int *index);
141 size_t Translate(char *buffer, size_t maxlength, void **params, const Translation *pTrans);
142 CPhraseFile *GetFileByIndex(unsigned int index);
143 TransError CoreTrans(int client,
148 size_t *outlen=NULL);
149 unsigned int GetServerLanguage();
150 unsigned int GetClientLanguage(int client);
152 bool AddLanguage(const char *langcode, const char *description);
154 CVector<Language *> m_Languages;
155 CVector<CPhraseFile *> m_Files;
156 BaseStringTable *m_pStringTab;
157 Trie *m_pLCodeLookup;
158 bool m_InLanguageSection;
159 String m_CustomError;
160 unsigned int m_ServerLang;
161 char m_InitialLang[3];
164 extern CPhraseFile *g_pCorePhrases;
165 extern unsigned int g_pCorePhraseID;
166 extern Translator g_Translator;
168 #endif //_INCLUDE_SOURCEMOD_TRANSLATOR_H_