Updated some CS:GO gamedata.
3 * =============================================================================
5 * Copyright (C) 2004-2008 AlliedModders LLC. All rights reserved.
6 * =============================================================================
8 * This program is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, version 3.0, as published by the
10 * Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
20 * As a special exception, AlliedModders LLC gives you permission to link the
21 * code of this program (as well as its derivative works) to "Half-Life 2," the
22 * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
23 * by the Valve Corporation. You must obey the GNU General Public License in
24 * all respects for all other code used. Additionally, AlliedModders LLC grants
25 * this exception to all derivative works. AlliedModders LLC defines further
26 * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
27 * or <http://www.sourcemod.net/license.php>.
32 #ifndef _INCLUDE_SOURCEMOD_TRANSLATOR_INTERFACE_H_
33 #define _INCLUDE_SOURCEMOD_TRANSLATOR_INTERFACE_H_
35 #include <IShareSys.h>
37 #define SMINTERFACE_TRANSLATOR_NAME "ITranslator"
38 #define SMINTERFACE_TRANSLATOR_VERSION 3
40 #define MAX_TRANSLATE_PARAMS 32
41 #define CORELANG_ENGLISH 0
45 * @brief Defines interfaces related to translation files.
51 * @brief SourceMod hardcodes the English language (default) to ID 0.
52 * This cannot be changed and languages.cfg should never have it as anything
53 * other than the first index.
55 #define SOURCEMOD_LANGUAGE_ENGLISH 0
58 * @brief For %T formats, specifies that the language should be that of the
59 * server and not a specific client.
61 #define SOURCEMOD_SERVER_LANGUAGE 0
64 * @brief Translation error codes.
68 Trans_Okay = 0, /**< Translation succeeded. */
69 Trans_BadLanguage = 1, /**< Bad language ID. */
70 Trans_BadPhrase = 2, /**< Phrase not found. */
71 Trans_BadPhraseLanguage = 3, /**< Phrase not found in the given language. */
72 Trans_BadPhraseFile = 4, /**< Phrase file was unreadable. */
76 * @brief Contains information about a translation phrase.
80 const char *szPhrase; /**< Translated phrase. */
81 unsigned int fmt_count; /**< Number of format parameters. */
82 int *fmt_order; /**< Array of size fmt_count where each
83 element is the numerical order of
84 parameter insertion, starting from
90 * @brief Represents a phrase file from SourceMod's "translations" folder.
96 * @brief Attempts to find a translation phrase in a phrase file.
98 * @param szPhrase String containing the phrase name.
99 * @param lang_id Language ID.
100 * @param pTrans Buffer to store translation info.
101 * @return Translation error code indicating success
102 * (pTrans is filled) or failure (pTrans
103 * contents is undefined).
105 virtual TransError GetTranslation(
106 const char *szPhrase,
107 unsigned int lang_id,
108 Translation *pTrans) =0;
111 * @brief Returns the file name of this translation file.
115 virtual const char *GetFilename() =0;
119 * Represents a collection of phrase files.
121 class IPhraseCollection
125 * @brief Adds a phrase file to the collection, using a cached one
126 * if already found. The return value is provided for informational
127 * purposes and does not need to be saved. The life time of the
128 * return pointer is equal to the life time of the collection.
130 * This function will internally ignore dupliate additions but still
131 * return a valid pointer.
133 * @param filename File name, without the ".txt" extension, of
134 * the phrase file in the translations folder.
135 * @return An IPhraseFile pointer, even if the file does
138 virtual IPhraseFile *AddPhraseFile(const char *filename) =0;
141 * @brief Returns the number of contained phrase files.
143 * @return Number of contained phrase files.
145 virtual unsigned int GetFileCount() =0;
148 * @brief Returns the pointer to a contained phrase file.
150 * @param file File index, from 0 to GetFileCount()-1.
151 * @return IPhraseFile pointer, or NULL if out of
154 virtual IPhraseFile *GetFile(unsigned int file) =0;
157 * @brief Destroys the phrase collection, freeing all internal
158 * resources and invalidating the object.
160 virtual void Destroy() =0;
163 * @brief Attempts a translation across a given language. All
164 * contained files are searched for an appropriate match; the
165 * first valid match is returned.
167 * @param key String containing the phrase name.
168 * @param langid Language ID to translate to.
169 * @param pTrans Translation buffer.
170 * @return Translation error code; on success,
171 * pTrans is valid. On failure, the
172 * contents of pTrans is undefined.
174 virtual TransError FindTranslation(
177 Translation *pTrans) =0;
180 * @brief Formats a phrase given a parameter stack. The parameter
181 * stack size must exactly match the expected parameter count. If
182 * this count is too small or too large, the format fails.
184 * @param buffer Buffer to store formatted text.
185 * @param maxlength Maximum length of the buffer.
186 * @param format String containing format information.
187 * This is equivalent to SourceMod's Format()
188 * native, and sub-translations are acceptable.
189 * @param params An array of pointers to each parameter.
190 * Integer parameters must have a pointer to the integer.
191 * Float parameters must have a pointer to a float.
192 * String parameters must be a string pointer.
193 * Char parameters must be a pointer to a char.
194 * Translation parameters fill multiple indexes in the
195 * array. For %T translations, the expected stack is:
196 * [phrase string pointer] [int target id pointer] [...]
197 * Where [...] is the required parameters for the translation,
198 * in the order expected by the phrase, not the phrase's
199 * translation. For example, say the format is:
200 * "%d %T" and the phrase's format is {1:s,2:f}, then the
201 * parameter stack should be:
202 * int *, const char *, int *, const char *, float *
203 * The %t modifier is the same except the target id pointer
205 * int *, const char *, const char *, float *
206 * @param numparams Number of parameters in the params array.
207 * @param pOutLength Optional pointer filled with output length on success.
208 * @param pFailPhrase Optional pointer; on failure, is filled with NULL if the
209 * failure was not due to a failed translation phrase.
210 * Otherwise, it is filled with the given phrase name pointer
211 * from the parameter stack. Undefined on success.
212 * @return True on success. False if the parameter stack was not
213 * exactly the right length, or if a translation phrase
214 * could not be found.
216 virtual bool FormatString(
221 unsigned int numparams,
223 const char **pFailPhrase) =0;
227 * @brief Provides functions for translation.
229 class ITranslator : public SMInterface
232 virtual const char *GetInterfaceName() =0;
233 virtual unsigned int GetInterfaceVersion() =0;
236 * @brief Creates a new phrase collection object.
238 * @return A new phrase collection object, which must be
239 * destroyed via IPhraseCollection::Destroy() when
242 virtual IPhraseCollection *CreatePhraseCollection() =0;
245 * @brief Returns the server language.
247 * @return Server language index.
249 virtual unsigned int GetServerLanguage() =0;
252 * @brief Returns a client's language.
254 * @param client Client index.
255 * @return Client language index, or server's if client's is
258 virtual unsigned int GetClientLanguage(int client) =0;
261 * @brief Sets the global client SourceMod will use for assisted
262 * translations (that is, %t).
264 * @param index Client index (0 for server).
265 * @return Old global client value.
267 virtual int SetGlobalTarget(int index) =0;
270 * @brief Returns the global client SourceMod is currently using
271 * for assisted translations (that is, %t).
273 * @return Global client index (0 for server).
275 virtual int GetGlobalTarget() const =0;
278 * @brief Formats a phrase given a parameter stack. The parameter
279 * stack size must exactly match the expected parameter count. If
280 * this count is too small or too large, the format fails.
282 * Note: This is the same as IPhraseCollection::FormatString(), except
283 * that the IPhraseCollection parameter is explicit instead of implicit.
285 * @param buffer Buffer to store formatted text.
286 * @param maxlength Maximum length of the buffer.
287 * @param format String containing format information.
288 * This is equivalent to SourceMod's Format()
289 * native, and sub-translations are acceptable.
290 * @param pPhrases Optional phrase collection pointer to search for
292 * @param params An array of pointers to each parameter.
293 * Integer parameters must have a pointer to the integer.
294 * Float parameters must have a pointer to a float.
295 * String parameters must be a string pointer.
296 * Char parameters must be a pointer to a char.
297 * Translation parameters fill multiple indexes in the
298 * array. For %T translations, the expected stack is:
299 * [phrase string pointer] [int target id pointer] [...]
300 * Where [...] is the required parameters for the translation,
301 * in the order expected by the phrase, not the phrase's
302 * translation. For example, say the format is:
303 * "%d %T" and the phrase's format is {1:s,2:f}, then the
304 * parameter stack should be:
305 * int *, const char *, int *, const char *, float *
306 * The %t modifier is the same except the target id pointer
308 * int *, const char *, const char *, float *
309 * @param numparams Number of parameters in the params array.
310 * @param pOutLength Optional pointer filled with output length on success.
311 * @param pFailPhrase Optional pointer; on failure, is filled with NULL if the
312 * failure was not due to a failed translation phrase.
313 * Otherwise, it is filled with the given phrase name pointer
314 * from the parameter stack. Undefined on success.
315 * @return True on success. False if the parameter stack was not
316 * exactly the right length, or if a translation phrase
317 * could not be found.
319 virtual bool FormatString(
323 IPhraseCollection *pPhrases,
325 unsigned int numparams,
327 const char **pFailPhrase) =0;
330 * @brief Get number of languages.
332 * @return Number of languages.
334 virtual unsigned int GetLanguageCount() =0;
337 * @brief Find a language number by name.
339 * @param name Language name.
340 * @param index Optional pointer to store language index.
341 * @return True if found, false otherwise.
343 virtual bool GetLanguageByName(const char *name, unsigned int *index) =0;
346 * @brief Retrieves info about a given language number.
348 * @param number Language number.
349 * @param code Pointer to store the language code.
350 * @param name Pointer to store language name.
351 * @return True if language number is valid, false otherwise.
353 virtual bool GetLanguageInfo(unsigned int number, const char **code, const char **name) =0;
357 #endif //_INCLUDE_SOURCEMOD_TRANSLATOR_INTERFACE_H_