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
27 /* :TODO: write a templatized version of tries? */
29 using namespace SourceHook;
47 const char *szPhrase; /**< Translated phrase. */
48 unsigned int fmt_count; /**< Number of format parameters. */
49 int *fmt_order; /**< Format phrase order. */
55 Trans_BadLanguage = 1,
57 Trans_BadPhraseLanguage = 3,
58 Trans_BadPhraseFile = 4,
61 class CPhraseFile : public ITextListener_SMC
64 CPhraseFile(Translator *pTranslator, const char *file);
68 const char *GetFilename();
69 TransError GetTranslation(const char *szPhrase, unsigned int lang_id, Translation *pTrans);
70 public: //ITextListener_SMC
71 void ReadSMC_ParseStart();
72 void ReadSMC_ParseEnd(bool halted, bool failed);
73 SMCParseResult ReadSMC_NewSection(const char *name, bool opt_quotes);
74 SMCParseResult ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes);
75 SMCParseResult ReadSMC_LeavingSection();
76 SMCParseResult ReadSMC_RawLine(const char *line, unsigned int curline);
78 void ParseError(const char *message, ...);
79 void ParseWarning(const char *message, ...);
81 Trie *m_pPhraseLookup;
83 Translator *m_pTranslator;
84 PhraseParseState m_ParseState;
86 BaseMemTable *m_pMemory;
87 BaseStringTable *m_pStringTab;
88 unsigned int m_LangCount;
90 String m_LastPhraseString;
91 unsigned int m_CurLine;
96 public ITextListener_SMC,
102 public: // SMGlobalClass
103 CoreConfigErr OnSourceModConfigChanged(const char *option, const char *value);
104 void OnSourceModAllInitialized();
105 public: // ITextListener_SMC
106 void ReadSMC_ParseStart();
107 SMCParseResult ReadSMC_NewSection(const char *name, bool opt_quotes);
108 SMCParseResult ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes);
109 SMCParseResult ReadSMC_LeavingSection();
111 void RebuildLanguageDatabase(const char *lang_header_file);
112 unsigned int FindOrAddPhraseFile(const char *phrase_file);
113 BaseStringTable *GetStringTable();
114 unsigned int GetLanguageCount();
115 bool GetLanguageByCode(const char *code, unsigned int *index);
116 size_t Translate(char *buffer, size_t maxlength, void **params, const Translation *pTrans);
117 CPhraseFile *GetFileByIndex(unsigned int index);
118 TransError CoreTrans(int client,
123 size_t *outlen=NULL);
124 const char *GetServerLanguageCode() const;
126 bool AddLanguage(const char *langcode, const char *description);
128 CVector<Language *> m_Languages;
129 CVector<CPhraseFile *> m_Files;
130 BaseStringTable *m_pStringTab;
131 Trie *m_pLCodeLookup;
132 bool m_InLanguageSection;
133 String m_CustomError;
134 char m_ServerLangCode[3];
137 extern CPhraseFile *g_pCorePhrases;
138 extern Translator g_Translator;
140 #endif //_INCLUDE_SOURCEMOD_TRANSLATOR_H_