3 * ===============================================================
4 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
5 * ===============================================================
7 * This file is not open source and may not be copied without explicit
8 * written permission of AlliedModders LLC. This file may not be redistributed
9 * in whole or significant part.
10 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
15 #ifndef _INCLUDE_SOURCEMOD_TRANSLATOR_H_
16 #define _INCLUDE_SOURCEMOD_TRANSLATOR_H_
19 #include <sh_string.h>
20 #include <sh_vector.h>
21 #include "sm_globals.h"
22 #include "sm_memtable.h"
23 #include "ITextParsers.h"
25 #define MAX_TRANSLATE_PARAMS 32
26 #define CORELANG_ENGLISH 0
28 /* :TODO: write a templatized version of tries? */
30 using namespace SourceHook;
48 const char *szPhrase; /**< Translated phrase. */
49 unsigned int fmt_count; /**< Number of format parameters. */
50 int *fmt_order; /**< Format phrase order. */
53 #define LANGUAGE_ENGLISH 0
58 Trans_BadLanguage = 1,
60 Trans_BadPhraseLanguage = 3,
61 Trans_BadPhraseFile = 4,
64 class CPhraseFile : public ITextListener_SMC
67 CPhraseFile(Translator *pTranslator, const char *file);
71 const char *GetFilename();
72 TransError GetTranslation(const char *szPhrase, unsigned int lang_id, Translation *pTrans);
73 public: //ITextListener_SMC
74 void ReadSMC_ParseStart();
75 void ReadSMC_ParseEnd(bool halted, bool failed);
76 SMCParseResult ReadSMC_NewSection(const char *name, bool opt_quotes);
77 SMCParseResult ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes);
78 SMCParseResult ReadSMC_LeavingSection();
79 SMCParseResult ReadSMC_RawLine(const char *line, unsigned int curline);
81 void ParseError(const char *message, ...);
82 void ParseWarning(const char *message, ...);
84 Trie *m_pPhraseLookup;
86 Translator *m_pTranslator;
87 PhraseParseState m_ParseState;
89 BaseMemTable *m_pMemory;
90 BaseStringTable *m_pStringTab;
91 unsigned int m_LangCount;
93 String m_LastPhraseString;
94 unsigned int m_CurLine;
99 public ITextListener_SMC,
105 public: // SMGlobalClass
106 ConfigResult OnSourceModConfigChanged(const char *key,
111 void OnSourceModAllInitialized();
112 void OnSourceModLevelChange(const char *mapName);
113 public: // ITextListener_SMC
114 void ReadSMC_ParseStart();
115 SMCParseResult ReadSMC_NewSection(const char *name, bool opt_quotes);
116 SMCParseResult ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes);
117 SMCParseResult ReadSMC_LeavingSection();
119 void RebuildLanguageDatabase(const char *lang_header_file);
120 unsigned int FindOrAddPhraseFile(const char *phrase_file);
121 BaseStringTable *GetStringTable();
122 unsigned int GetLanguageCount();
123 bool GetLanguageByCode(const char *code, unsigned int *index);
124 size_t Translate(char *buffer, size_t maxlength, void **params, const Translation *pTrans);
125 CPhraseFile *GetFileByIndex(unsigned int index);
126 TransError CoreTrans(int client,
131 size_t *outlen=NULL);
132 unsigned int GetServerLanguage();
134 bool AddLanguage(const char *langcode, const char *description);
136 CVector<Language *> m_Languages;
137 CVector<CPhraseFile *> m_Files;
138 BaseStringTable *m_pStringTab;
139 Trie *m_pLCodeLookup;
140 bool m_InLanguageSection;
141 String m_CustomError;
142 unsigned int m_ServerLang;
143 char m_InitialLang[3];
146 extern CPhraseFile *g_pCorePhrases;
147 extern Translator g_Translator;
149 #endif //_INCLUDE_SOURCEMOD_TRANSLATOR_H_