SourceMod SDK  1.7
ITranslator.h
Go to the documentation of this file.
1 
32 #ifndef _INCLUDE_SOURCEMOD_TRANSLATOR_INTERFACE_H_
33 #define _INCLUDE_SOURCEMOD_TRANSLATOR_INTERFACE_H_
34 
35 #include <IShareSys.h>
36 
37 #define SMINTERFACE_TRANSLATOR_NAME "ITranslator"
38 #define SMINTERFACE_TRANSLATOR_VERSION 4
39 
40 #define MAX_TRANSLATE_PARAMS 32
41 #define CORELANG_ENGLISH 0
42 
48 namespace SourceMod
49 {
55  #define SOURCEMOD_LANGUAGE_ENGLISH 0
56 
61  #define SOURCEMOD_SERVER_LANGUAGE 0
62 
66  enum TransError
67  {
68  Trans_Okay = 0,
69  Trans_BadLanguage = 1,
70  Trans_BadPhrase = 2,
71  Trans_BadPhraseLanguage = 3,
72  Trans_BadPhraseFile = 4,
73  };
74 
78  struct Translation
79  {
80  const char *szPhrase;
81  unsigned int fmt_count;
82  int *fmt_order;
87  };
88 
93  {
94  public:
105  virtual TransError GetTranslation(
106  const char *szPhrase,
107  unsigned int lang_id,
108  Translation *pTrans) =0;
109 
115  virtual const char *GetFilename() =0;
116  };
117 
122  {
123  public:
138  virtual IPhraseFile *AddPhraseFile(const char *filename) =0;
139 
145  virtual unsigned int GetFileCount() =0;
146 
154  virtual IPhraseFile *GetFile(unsigned int file) =0;
155 
160  virtual void Destroy() =0;
161 
174  virtual TransError FindTranslation(
175  const char *key,
176  unsigned int langid,
177  Translation *pTrans) =0;
178 
216  virtual bool FormatString(
217  char *buffer,
218  size_t maxlength,
219  const char *format,
220  void **params,
221  unsigned int numparams,
222  size_t *pOutLength,
223  const char **pFailPhrase) =0;
224  };
225 
229  class ITranslator : public SMInterface
230  {
231  public:
232  virtual const char *GetInterfaceName() =0;
233  virtual unsigned int GetInterfaceVersion() =0;
234  public:
243 
249  virtual unsigned int GetServerLanguage() =0;
250 
258  virtual unsigned int GetClientLanguage(int client) =0;
259 
267  virtual int SetGlobalTarget(int index) =0;
268 
275  virtual int GetGlobalTarget() const =0;
276 
319  virtual bool FormatString(
320  char *buffer,
321  size_t maxlength,
322  const char *format,
323  IPhraseCollection *pPhrases,
324  void **params,
325  unsigned int numparams,
326  size_t *pOutLength,
327  const char **pFailPhrase) =0;
328 
334  virtual unsigned int GetLanguageCount() =0;
335 
343  virtual bool GetLanguageByName(const char *name, unsigned int *index) =0;
344 
353  virtual bool GetLanguageInfo(unsigned int number, const char **code, const char **name) =0;
354 
358  virtual void RebuildLanguageDatabase() =0;
359  };
360 }
361 
362 #endif //_INCLUDE_SOURCEMOD_TRANSLATOR_INTERFACE_H_
363 
virtual bool FormatString(char *buffer, size_t maxlength, const char *format, void **params, unsigned int numparams, size_t *pOutLength, const char **pFailPhrase)=0
Formats a phrase given a parameter stack. The parameter stack size must exactly match the expected pa...
virtual IPhraseFile * AddPhraseFile(const char *filename)=0
Adds a phrase file to the collection, using a cached one if already found. The return value is provid...
virtual const char * GetInterfaceName()=0
Must return a string defining the interface's unique name.
const char * szPhrase
Definition: ITranslator.h:80
virtual unsigned int GetInterfaceVersion()=0
Must return an integer defining the interface's version.
virtual int SetGlobalTarget(int index)=0
Sets the global client SourceMod will use for assisted translations (that is, t). ...
virtual unsigned int GetLanguageCount()=0
Get number of languages.
unsigned int fmt_count
Definition: ITranslator.h:81
virtual unsigned int GetServerLanguage()=0
Returns the server language.
virtual unsigned int GetClientLanguage(int client)=0
Returns a client's language.
virtual int GetGlobalTarget() const =0
Returns the global client SourceMod is currently using for assisted translations (that is...
Defines the Share System, responsible for shared resources and dependencies.
Defines the base functionality required by a shared interface.
Definition: IShareSys.h:92
virtual unsigned int GetFileCount()=0
Returns the number of contained phrase files.
virtual const char * GetFilename()=0
Returns the file name of this translation file.
Provides functions for translation.
Definition: ITranslator.h:229
virtual bool GetLanguageByName(const char *name, unsigned int *index)=0
Find a language number by name.
Definition: ITranslator.h:121
virtual bool FormatString(char *buffer, size_t maxlength, const char *format, IPhraseCollection *pPhrases, void **params, unsigned int numparams, size_t *pOutLength, const char **pFailPhrase)=0
Formats a phrase given a parameter stack. The parameter stack size must exactly match the expected pa...
virtual void Destroy()=0
Destroys the phrase collection, freeing all internal resources and invalidating the object...
virtual void RebuildLanguageDatabase()=0
Reparses all loaded translations files.
virtual IPhraseFile * GetFile(unsigned int file)=0
Returns the pointer to a contained phrase file.
Definition: IAdminSystem.h:63
virtual bool GetLanguageInfo(unsigned int number, const char **code, const char **name)=0
Retrieves info about a given language number.
Contains information about a translation phrase.
Definition: ITranslator.h:78
virtual TransError FindTranslation(const char *key, unsigned int langid, Translation *pTrans)=0
Attempts a translation across a given language. All contained files are searched for an appropriate m...
int * fmt_order
Definition: ITranslator.h:82
virtual IPhraseCollection * CreatePhraseCollection()=0
Creates a new phrase collection object.
Represents a phrase file from SourceMod's "translations" folder.
Definition: ITranslator.h:92
virtual TransError GetTranslation(const char *szPhrase, unsigned int lang_id, Translation *pTrans)=0
Attempts to find a translation phrase in a phrase file.