extensions can now be built for multiple engines, and will autoload from auto.X.Y folders
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 void ReadSMC_ParseEnd(bool halted, bool failed);
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();
96 SMCParseResult ReadSMC_RawLine(const char *line, unsigned int curline);
98 void ParseError(const char *message, ...);
99 void ParseWarning(const char *message, ...);
101 Trie *m_pPhraseLookup;
103 Translator *m_pTranslator;
104 PhraseParseState m_ParseState;
106 BaseMemTable *m_pMemory;
107 BaseStringTable *m_pStringTab;
108 unsigned int m_LangCount;
110 String m_LastPhraseString;
111 unsigned int m_CurLine;
116 public ITextListener_SMC,
122 public: // SMGlobalClass
123 ConfigResult OnSourceModConfigChanged(const char *key,
128 void OnSourceModAllInitialized();
129 void OnSourceModLevelChange(const char *mapName);
130 public: // ITextListener_SMC
131 void ReadSMC_ParseStart();
132 SMCParseResult ReadSMC_NewSection(const char *name, bool opt_quotes);
133 SMCParseResult ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes);
134 SMCParseResult ReadSMC_LeavingSection();
136 void RebuildLanguageDatabase(const char *lang_header_file);
137 unsigned int FindOrAddPhraseFile(const char *phrase_file);
138 BaseStringTable *GetStringTable();
139 unsigned int GetLanguageCount();
140 bool GetLanguageInfo(unsigned int number, const char **code, const char **name);
141 bool GetLanguageByCode(const char *code, unsigned int *index);
142 bool GetLanguageByName(const char *name, unsigned int *index);
143 size_t Translate(char *buffer, size_t maxlength, void **params, const Translation *pTrans);
144 CPhraseFile *GetFileByIndex(unsigned int index);
145 TransError CoreTrans(int client,
150 size_t *outlen=NULL);
151 unsigned int GetServerLanguage();
152 unsigned int GetClientLanguage(int client);
154 bool AddLanguage(const char *langcode, const char *description);
156 CVector<Language *> m_Languages;
157 CVector<CPhraseFile *> m_Files;
158 BaseStringTable *m_pStringTab;
159 Trie *m_pLCodeLookup;
160 bool m_InLanguageSection;
161 String m_CustomError;
162 unsigned int m_ServerLang;
163 char m_InitialLang[3];
166 extern CPhraseFile *g_pCorePhrases;
167 extern Translator g_Translator;
169 #endif //_INCLUDE_SOURCEMOD_TRANSLATOR_H_