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_
35 #include "common_logic.h"
36 #include <sm_trie_tpl.h>
37 #include <sh_string.h>
38 #include <sh_vector.h>
39 #include "sm_memtable.h"
40 #include "ITextParsers.h"
41 #include <ITranslator.h>
43 /* :TODO: write a templatized version of tries? */
45 using namespace SourceHook;
62 public ITextListener_SMC,
66 CPhraseFile(Translator *pTranslator, const char *file);
70 const char *GetFilename();
71 TransError GetTranslation(const char *szPhrase, unsigned int lang_id, Translation *pTrans);
72 public: //ITextListener_SMC
73 void ReadSMC_ParseStart();
74 SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name);
75 SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value);
76 SMCResult ReadSMC_LeavingSection(const SMCStates *states);
77 void ReadSMC_ParseEnd(bool halted, bool failed);
79 void ParseError(const char *message, ...);
80 void ParseWarning(const char *message, ...);
82 KTrie<int> m_PhraseLookup;
84 Translator *m_pTranslator;
85 PhraseParseState m_ParseState;
87 BaseMemTable *m_pMemory;
88 BaseStringTable *m_pStringTab;
89 unsigned int m_LangCount;
91 String m_LastPhraseString;
96 public ITextListener_SMC,
103 public: // SMGlobalClass
104 ConfigResult OnSourceModConfigChanged(const char *key,
109 void OnSourceModAllInitialized();
110 void OnSourceModLevelChange(const char *mapName);
111 void OnSourceModShutdown();
112 public: // ITextListener_SMC
113 void ReadSMC_ParseStart();
114 SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name);
115 SMCResult ReadSMC_KeyValue(const SMCStates *states, const char *key, const char *value);
116 SMCResult ReadSMC_LeavingSection(const SMCStates *states);
118 void RebuildLanguageDatabase(const char *lang_header_file);
119 unsigned int FindOrAddPhraseFile(const char *phrase_file);
120 BaseStringTable *GetStringTable();
121 unsigned int GetLanguageCount();
122 bool GetLanguageInfo(unsigned int number, const char **code, const char **name);
123 bool GetLanguageByCode(const char *code, unsigned int *index);
124 bool GetLanguageByName(const char *name, unsigned int *index);
125 CPhraseFile *GetFileByIndex(unsigned int index);
126 public: //ITranslator
127 unsigned int GetServerLanguage();
128 unsigned int GetClientLanguage(int client);
129 const char *GetInterfaceName();
130 unsigned int GetInterfaceVersion();
131 IPhraseCollection *CreatePhraseCollection();
132 int SetGlobalTarget(int index);
133 int GetGlobalTarget() const;
137 SourcePawn::IPluginContext *pContext,
138 const cell_t *params,
144 IPhraseCollection *pPhrases,
146 unsigned int numparams,
148 const char **pFailPhrase);
150 bool AddLanguage(const char *langcode, const char *description);
152 CVector<Language *> m_Languages;
153 CVector<CPhraseFile *> m_Files;
154 BaseStringTable *m_pStringTab;
155 KTrie<unsigned int> m_LCodeLookup;
156 bool m_InLanguageSection;
157 String m_CustomError;
158 unsigned int m_ServerLang;
159 char m_InitialLang[4];
162 /* Nice little wrapper to handle error logging and whatnot */
163 bool CoreTranslate(char *buffer,
166 unsigned int numparams,
170 extern IPhraseCollection *g_pCorePhrases;
171 extern unsigned int g_pCorePhraseID;
172 extern Translator g_Translator;
174 #endif //_INCLUDE_SOURCEMOD_TRANSLATOR_H_