3 * =============================================================================
5 * Copyright (C) 2004-2008 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"
41 #include <ITranslator.h>
43 #define MAX_TRANSLATE_PARAMS 32
44 #define CORELANG_ENGLISH 0
46 /* :TODO: write a templatized version of tries? */
48 using namespace SourceHook;
65 public ITextListener_SMC,
69 CPhraseFile(Translator *pTranslator, const char *file);
73 const char *GetFilename();
74 TransError GetTranslation(const char *szPhrase, unsigned int lang_id, Translation *pTrans);
75 public: //ITextListener_SMC
76 void ReadSMC_ParseStart();
77 SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name);
78 SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value);
79 SMCResult ReadSMC_LeavingSection(const SMCStates *states);
80 void ReadSMC_ParseEnd(bool halted, bool failed);
82 void ParseError(const char *message, ...);
83 void ParseWarning(const char *message, ...);
85 Trie *m_pPhraseLookup;
87 Translator *m_pTranslator;
88 PhraseParseState m_ParseState;
90 BaseMemTable *m_pMemory;
91 BaseStringTable *m_pStringTab;
92 unsigned int m_LangCount;
94 String m_LastPhraseString;
99 public ITextListener_SMC,
100 public SMGlobalClass,
106 public: // SMGlobalClass
107 ConfigResult OnSourceModConfigChanged(const char *key,
112 void OnSourceModAllInitialized();
113 void OnSourceModLevelChange(const char *mapName);
114 void OnSourceModShutdown();
115 public: // ITextListener_SMC
116 void ReadSMC_ParseStart();
117 SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name);
118 SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value);
119 SMCResult ReadSMC_LeavingSection(const SMCStates *states);
121 void RebuildLanguageDatabase(const char *lang_header_file);
122 unsigned int FindOrAddPhraseFile(const char *phrase_file);
123 BaseStringTable *GetStringTable();
124 unsigned int GetLanguageCount();
125 bool GetLanguageInfo(unsigned int number, const char **code, const char **name);
126 bool GetLanguageByCode(const char *code, unsigned int *index);
127 bool GetLanguageByName(const char *name, unsigned int *index);
128 CPhraseFile *GetFileByIndex(unsigned int index);
129 public: //ITranslator
130 unsigned int GetServerLanguage();
131 unsigned int GetClientLanguage(int client);
132 const char *GetInterfaceName();
133 unsigned int GetInterfaceVersion();
134 IPhraseCollection *CreatePhraseCollection();
135 int SetGlobalTarget(int index);
136 int GetGlobalTarget() const;
140 SourcePawn::IPluginContext *pContext,
141 const cell_t *params,
147 IPhraseCollection *pPhrases,
149 unsigned int numparams,
151 const char **pFailPhrase);
153 bool AddLanguage(const char *langcode, const char *description);
155 CVector<Language *> m_Languages;
156 CVector<CPhraseFile *> m_Files;
157 BaseStringTable *m_pStringTab;
158 Trie *m_pLCodeLookup;
159 bool m_InLanguageSection;
160 String m_CustomError;
161 unsigned int m_ServerLang;
162 char m_InitialLang[4];
165 /* Nice little wrapper to handle error logging and whatnot */
166 bool CoreTranslate(char *buffer,
169 unsigned int numparams,
173 extern IPhraseCollection *g_pCorePhrases;
174 extern unsigned int g_pCorePhraseID;
175 extern Translator g_Translator;
177 #endif //_INCLUDE_SOURCEMOD_TRANSLATOR_H_