core/Translator.h
changeset 2042 4a2faafca477
parent 1952 b7aa2b626807
child 2289 44045ead61cd
     1.1 --- a/core/Translator.h	Fri May 09 08:22:39 2008 +0000
     1.2 +++ b/core/Translator.h	Sat May 10 09:23:55 2008 +0000
     1.3 @@ -38,6 +38,7 @@
     1.4  #include "sm_globals.h"
     1.5  #include "sm_memtable.h"
     1.6  #include "ITextParsers.h"
     1.7 +#include <ITranslator.h>
     1.8  
     1.9  #define MAX_TRANSLATE_PARAMS		32
    1.10  #define CORELANG_ENGLISH			0
    1.11 @@ -60,25 +61,9 @@
    1.12  	int m_FullName;
    1.13  };
    1.14  
    1.15 -struct Translation
    1.16 -{
    1.17 -	const char *szPhrase;		/**< Translated phrase. */
    1.18 -	unsigned int fmt_count;		/**< Number of format parameters. */
    1.19 -	int *fmt_order;				/**< Format phrase order. */
    1.20 -};
    1.21 -
    1.22 -#define LANGUAGE_ENGLISH			0
    1.23 -
    1.24 -enum TransError
    1.25 -{
    1.26 -	Trans_Okay = 0,
    1.27 -	Trans_BadLanguage = 1,
    1.28 -	Trans_BadPhrase = 2,
    1.29 -	Trans_BadPhraseLanguage = 3,
    1.30 -	Trans_BadPhraseFile = 4,
    1.31 -};
    1.32 -
    1.33 -class CPhraseFile : public ITextListener_SMC
    1.34 +class CPhraseFile : 
    1.35 +	public ITextListener_SMC,
    1.36 +	public IPhraseFile
    1.37  {
    1.38  public:
    1.39  	CPhraseFile(Translator *pTranslator, const char *file);
    1.40 @@ -112,7 +97,8 @@
    1.41  
    1.42  class Translator : 
    1.43  	public ITextListener_SMC,
    1.44 -	public SMGlobalClass
    1.45 +	public SMGlobalClass,
    1.46 +	public ITranslator
    1.47  {
    1.48  public:
    1.49  	Translator();
    1.50 @@ -125,6 +111,7 @@
    1.51  		size_t maxlength);
    1.52  	void OnSourceModAllInitialized();
    1.53  	void OnSourceModLevelChange(const char *mapName);
    1.54 +	void OnSourceModShutdown();
    1.55  public: // ITextListener_SMC
    1.56  	void ReadSMC_ParseStart();
    1.57  	SMCResult ReadSMC_NewSection(const SMCStates *states, const char *name);
    1.58 @@ -138,23 +125,30 @@
    1.59  	bool GetLanguageInfo(unsigned int number, const char **code, const char **name);
    1.60  	bool GetLanguageByCode(const char *code, unsigned int *index);
    1.61  	bool GetLanguageByName(const char *name, unsigned int *index);
    1.62 -	size_t Translate(char *buffer, size_t maxlength, void **params, const Translation *pTrans);
    1.63  	CPhraseFile *GetFileByIndex(unsigned int index);
    1.64 -	TransError CoreTransEx(CPhraseFile *pFile,
    1.65 -		int client, 
    1.66 +public: //ITranslator
    1.67 +	unsigned int GetServerLanguage();
    1.68 +	unsigned int GetClientLanguage(int client);
    1.69 +	const char *GetInterfaceName();
    1.70 +	unsigned int GetInterfaceVersion();
    1.71 +	IPhraseCollection *CreatePhraseCollection();
    1.72 +	int SetGlobalTarget(int index);
    1.73 +	int GetGlobalTarget() const;
    1.74 +	size_t FormatString(
    1.75  		char *buffer, 
    1.76  		size_t maxlength, 
    1.77 -		const char *phrase, 
    1.78 -		void **params, 
    1.79 -		size_t *outlen=NULL);
    1.80 -	TransError CoreTrans(int client, 
    1.81 -						 char *buffer, 
    1.82 -						 size_t maxlength, 
    1.83 -						 const char *phrase, 
    1.84 -						 void **params, 
    1.85 -						 size_t *outlen=NULL);
    1.86 -	unsigned int GetServerLanguage();
    1.87 -	unsigned int GetClientLanguage(int client);
    1.88 +		SourcePawn::IPluginContext *pContext,
    1.89 +		const cell_t *params,
    1.90 +		unsigned int param);
    1.91 +	bool FormatString(
    1.92 +		char *buffer,
    1.93 +		size_t maxlength,
    1.94 +		const char *format,
    1.95 +		IPhraseCollection *pPhrases,
    1.96 +		void **params,
    1.97 +		unsigned int numparams,
    1.98 +		size_t *pOutLength,
    1.99 +		const char **pFailPhrase);
   1.100  private:
   1.101  	bool AddLanguage(const char *langcode, const char *description);
   1.102  private:
   1.103 @@ -168,7 +162,15 @@
   1.104  	char m_InitialLang[3];
   1.105  };
   1.106  
   1.107 -extern CPhraseFile *g_pCorePhrases;
   1.108 +/* Nice little wrapper to handle error logging and whatnot */
   1.109 +bool CoreTranslate(char *buffer, 
   1.110 +				   size_t maxlength,
   1.111 +				   const char *format,
   1.112 +				   unsigned int numparams,
   1.113 +				   size_t *pOutLength,
   1.114 +				   ...);
   1.115 +
   1.116 +extern IPhraseCollection *g_pCorePhrases;
   1.117  extern unsigned int g_pCorePhraseID;
   1.118  extern Translator g_Translator;
   1.119