diff --git a/core/msvc8/sourcemod_mm.vcproj b/core/msvc8/sourcemod_mm.vcproj index 913534d3d..7fdd69da0 100644 --- a/core/msvc8/sourcemod_mm.vcproj +++ b/core/msvc8/sourcemod_mm.vcproj @@ -1,7 +1,7 @@ + + diff --git a/core/sm_stringutil.cpp b/core/sm_stringutil.cpp index 133a2a876..1dda1ab9f 100644 --- a/core/sm_stringutil.cpp +++ b/core/sm_stringutil.cpp @@ -16,6 +16,8 @@ #include #include "sm_stringutil.h" #include "CLogger.h" +#include "PluginSys.h" +#include "CTranslator.h" #define LADJUST 0x00000004 /* left adjustment */ #define ZEROPAD 0x00000080 /* zero (as opposed to blank) pad */ @@ -28,6 +30,47 @@ return 0; \ } +size_t Translate(char *buffer, size_t maxlen, IPluginContext *pCtx, const char *key, cell_t target, const cell_t *params, int *arg) +{ + unsigned int langid; + CPlugin *pl = (CPlugin *)g_PluginSys.FindPluginByContext(pCtx->GetContext()); + size_t langcount = pl->GetLangFileCount(); + + if (!g_Translator.GetLanguageByCode("en", &langid)) //:TODO: hardcoded this just for testing + { + //:TODO: error out something + } + + CPhraseFile *phrfl; + TransError err = Trans_Okay; + Translation pTrans; + + for (size_t i=0; iGetFileByIndex(i)); + err = phrfl->GetTranslation(key, langid, &pTrans); + } + + if (err != Trans_Okay) + { + //:TODO: we didnt find our translation in any file :o + } + + void *new_params[MAX_TRANSLATE_PARAMS]; + unsigned int max_params = pTrans.fmt_count; + for (size_t i=0; iLocalToPhysAddr(params[*arg], reinterpret_cast(&new_params[i])); + (*arg)++; + if ((*arg) + i > (size_t)params[0]) + { + //:TODO: we are missing arguments zOMG + } + } + + return g_Translator.Translate(buffer, maxlen, new_params, &pTrans); +} + //:TODO: review this code before we choose a license void AddString(char **buf_p, size_t &maxlen, const char *string, int width, int prec) @@ -564,6 +607,16 @@ reswitch: arg++; break; } + case 'T': + { + CHECK_ARGS(0); + char *key; + cell_t target = params[arg++]; + pCtx->LocalToString(params[arg++], &key); + llen -= Translate(buf_p, llen, pCtx, key, target, params, &arg); + buf_p += llen; + break; + } case '%': { if (!llen) diff --git a/core/sm_stringutil.h b/core/sm_stringutil.h index 61fe0fce6..d47b4b7b9 100644 --- a/core/sm_stringutil.h +++ b/core/sm_stringutil.h @@ -20,6 +20,8 @@ using namespace SourcePawn; +#define LANG_SERVER 0 + size_t atcprintf(char *buffer, size_t maxlen, const char *format, IPluginContext *pCtx, const cell_t *params, int *param); const char *stristr(const char *str, const char *substr); unsigned int strncopy(char *dest, const char *src, size_t count); diff --git a/core/smn_lang.cpp b/core/smn_lang.cpp new file mode 100644 index 000000000..f6d3728f1 --- /dev/null +++ b/core/smn_lang.cpp @@ -0,0 +1,29 @@ +/** + * =============================================================== + * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. + * =============================================================== + * + * This file is not open source and may not be copied without explicit + * written permission of AlliedModders LLC. This file may not be redistributed + * in whole or significant part. + * For information, see LICENSE.txt or http://www.sourcemod.net/license.php + * + * Version: $Id$ + */ + +#include "PluginSys.h" +#include "CTranslator.h" + +static cell_t sm_LoadTranslations(IPluginContext *pCtx, const cell_t *params) +{ + char *filename; + unsigned int index; + CPlugin *pl = (CPlugin *)g_PluginSys.FindPluginByContext(pCtx->GetContext()); + + pCtx->LocalToString(params[1], &filename); + + index = g_Translator.FindOrAddPhraseFile(filename); + pl->AddLangFile(index); + + return 1; +} diff --git a/core/smn_textparse.cpp b/core/smn_textparse.cpp index 35e4c79a4..b61f90de4 100644 --- a/core/smn_textparse.cpp +++ b/core/smn_textparse.cpp @@ -268,6 +268,9 @@ static cell_t SMC_ParseFile(IPluginContext *pContext, const cell_t *params) pContext->LocalToPhysAddr(params[3], &c_line); pContext->LocalToPhysAddr(params[4], &c_col); + *c_line = line; + *c_col = col; + return (cell_t)p_err; } diff --git a/core/systems/PluginSys.cpp b/core/systems/PluginSys.cpp index c75fd680f..15284a06b 100644 --- a/core/systems/PluginSys.cpp +++ b/core/systems/PluginSys.cpp @@ -491,6 +491,21 @@ void CPlugin::SetTimeStamp(time_t t) m_LastAccess = t; } +void CPlugin::AddLangFile(unsigned int index) +{ + m_PhraseFiles.push_back(index); +} + +size_t CPlugin::GetLangFileCount() const +{ + return m_PhraseFiles.size(); +} + +unsigned int CPlugin::GetFileByIndex(unsigned int index) const +{ + return m_PhraseFiles.at(index); +} + /******************* * PLUGIN ITERATOR * *******************/ diff --git a/core/systems/PluginSys.h b/core/systems/PluginSys.h index 1cbb05cf7..fe5dc201c 100644 --- a/core/systems/PluginSys.h +++ b/core/systems/PluginSys.h @@ -21,6 +21,7 @@ #include #include #include +#include #include "sm_globals.h" #include "vm/sp_vm_basecontext.h" #include "PluginInfoDatabase.h" @@ -176,6 +177,21 @@ public: * Returns true if a plugin is usable. */ bool IsRunnable() const; + + /** + * Adds a language file index to the plugin's list. + */ + void AddLangFile(unsigned int index); + + /** + * Get language file count for this plugin. + */ + size_t GetLangFileCount() const; + + /** + * Get language file index based on the vector index. + */ + unsigned int GetFileByIndex(unsigned int index) const; public: /** * Returns the modification time during last plugin load. @@ -207,6 +223,7 @@ private: IdentityToken_t *m_ident; Handle_t m_handle; bool m_WasRunning; + CVector m_PhraseFiles; }; class CPluginManager : diff --git a/plugins/include/lang.inc b/plugins/include/lang.inc new file mode 100644 index 000000000..66fff1599 --- /dev/null +++ b/plugins/include/lang.inc @@ -0,0 +1,26 @@ +/** + * =============================================================== + * SourceMod (C)2004-2007 AlliedModders LLC. All rights reserved. + * =============================================================== + * + * This file is part of the SourceMod/SourcePawn SDK. This file may only be used + * or modified under the Terms and Conditions of its License Agreement, which is found + * in LICENSE.txt. The Terms and Conditions for making SourceMod extensions/plugins + * may change at any time. To view the latest information, see: + * http://www.sourcemod.net/license.php + * + * Version: $Id$ + */ + +#if defined _lang_included + #endinput +#endif +#define _lang_included + +/** + * @brief Loads a translation file for the plugin calling this native. + * + * @param path Translation file. + * @noreturn + */ +native LoadTranslations(const String:file[]); \ No newline at end of file