2 * ===============================================================
3 * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved.
4 * ===============================================================
6 * This file is not open source and may not be copied without explicit
7 * written permission of AlliedModders LLC. This file may not be redistributed
8 * in whole or significant part.
9 * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
14 #ifndef _INCLUDE_SOURCEMOD_TRANSLATOR_H_
15 #define _INCLUDE_SOURCEMOD_TRANSLATOR_H_
18 #include <sh_string.h>
19 #include <sh_vector.h>
20 #include "sm_globals.h"
21 #include "sm_memtable.h"
22 #include "ITextParsers.h"
24 #define MAX_TRANSLATE_PARAMS 32
26 /* :TODO: write a templatized version of tries? */
28 using namespace SourceHook;
46 const char *szPhrase; /**< Translated phrase. */
47 unsigned int fmt_count; /**< Number of format parameters. */
48 int *fmt_order; /**< Format phrase order. */
54 Trans_BadLanguage = 1,
56 Trans_BadPhraseLanguage = 3,
57 Trans_BadPhraseFile = 4,
60 class CPhraseFile : public ITextListener_SMC
63 CPhraseFile(CTranslator *pTranslator, const char *file);
67 const char *GetFilename();
68 TransError GetTranslation(const char *szPhrase, unsigned int lang_id, Translation *pTrans);
69 public: //ITextListener_SMC
70 void ReadSMC_ParseStart();
71 void ReadSMC_ParseEnd(bool halted, bool failed);
72 SMCParseResult ReadSMC_NewSection(const char *name, bool opt_quotes);
73 SMCParseResult ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes);
74 SMCParseResult ReadSMC_LeavingSection();
75 SMCParseResult ReadSMC_RawLine(const char *line, unsigned int curline);
77 void ParseError(const char *message, ...);
78 void ParseWarning(const char *message, ...);
80 Trie *m_pPhraseLookup;
82 CTranslator *m_pTranslator;
83 PhraseParseState m_ParseState;
85 BaseMemTable *m_pMemory;
86 BaseStringTable *m_pStringTab;
87 unsigned int m_LangCount;
89 String m_LastPhraseString;
90 unsigned int m_CurLine;
95 public ITextListener_SMC,
101 public: //SMGlobalClass
102 void OnSourceModAllInitialized();
103 public: //ITextListener_SMC
104 void ReadSMC_ParseStart();
105 SMCParseResult ReadSMC_NewSection(const char *name, bool opt_quotes);
106 SMCParseResult ReadSMC_KeyValue(const char *key, const char *value, bool key_quotes, bool value_quotes);
107 SMCParseResult ReadSMC_LeavingSection();
109 void RebuildLanguageDatabase(const char *lang_header_file);
110 unsigned int FindOrAddPhraseFile(const char *phrase_file);
111 BaseStringTable *GetStringTable();
112 unsigned int GetLanguageCount();
113 bool GetLanguageByCode(const char *code, unsigned int *index);
114 size_t Translate(char *buffer, size_t maxlength, void **params, const Translation *pTrans);
115 CPhraseFile *GetFileByIndex(unsigned int index);
116 TransError CoreTrans(int client,
121 size_t *outlen=NULL);
123 bool AddLanguage(const char *langcode, const char *description);
125 CVector<Language *> m_Languages;
126 CVector<CPhraseFile *> m_Files;
127 BaseStringTable *m_pStringTab;
128 Trie *m_pLCodeLookup;
129 bool m_InLanguageSection;
130 String m_CustomError;
133 extern CPhraseFile *g_pCorePhrases;
134 extern CTranslator g_Translator;
136 #endif //_INCLUDE_SOURCEMOD_TRANSLATOR_H_