Add translation support to SourceTV_PrintToChat

This commit is contained in:
nosoop 2018-11-17 23:09:10 -08:00
parent 067b238bd2
commit 4c38126ac3
2 changed files with 40 additions and 2 deletions

View File

@ -825,8 +825,27 @@ static cell_t Native_PrintToChat(IPluginContext *pContext, const cell_t *params)
char buffer[1024];
size_t len;
{
#if SOURCE_ENGINE != SE_CSGO
// There's no way to set the current translation without a client index, so we'll save / restore the language on the relay.
int iHLTVClient = hltvserver->GetHLTVServer()->GetHLTVSlot() + 1;
IGamePlayer *pHLTVClient = playerhelpers->GetGamePlayer(iHLTVClient);
unsigned int langid = translator->GetServerLanguage();
translator->GetLanguageByName(pClient->BaseClient()->GetUserSetting("cl_language"), &langid);
pHLTVClient->SetLanguageId(langid);
int restoreTarget = translator->SetGlobalTarget(hltvserver->GetHLTVServer()->GetHLTVSlot() + 1);
#endif
DetectExceptions eh(pContext);
len = smutils->FormatString(buffer, sizeof(buffer), pContext, params, 2);
#if SOURCE_ENGINE != SE_CSGO
pHLTVClient->SetLanguageId(translator->GetServerLanguage());
translator->SetGlobalTarget(restoreTarget);
#endif
if (eh.HasException())
return 0;
}
@ -879,8 +898,27 @@ static cell_t Native_PrintToConsole(IPluginContext *pContext, const cell_t *para
char buffer[1024];
size_t len;
{
#if SOURCE_ENGINE != SE_CSGO
// There's no way to set the current translation without a client index, so we'll save / restore the language on the relay.
int iHLTVClient = hltvserver->GetHLTVServer()->GetHLTVSlot() + 1;
IGamePlayer *pHLTVClient = playerhelpers->GetGamePlayer(iHLTVClient);
unsigned int langid = translator->GetServerLanguage();
translator->GetLanguageByName(pClient->BaseClient()->GetUserSetting("cl_language"), &langid);
pHLTVClient->SetLanguageId(langid);
int restoreTarget = translator->SetGlobalTarget(hltvserver->GetHLTVServer()->GetHLTVSlot() + 1);
#endif
DetectExceptions eh(pContext);
len = smutils->FormatString(buffer, sizeof(buffer), pContext, params, 2);
#if SOURCE_ENGINE != SE_CSGO
pHLTVClient->SetLanguageId(translator->GetServerLanguage());
translator->SetGlobalTarget(restoreTarget);
#endif
if (eh.HasException())
return 0;
}

View File

@ -61,7 +61,7 @@
/** Enable interfaces you want to use here by uncommenting lines */
#define SMEXT_ENABLE_FORWARDSYS
//#define SMEXT_ENABLE_HANDLESYS
//#define SMEXT_ENABLE_PLAYERHELPERS
#define SMEXT_ENABLE_PLAYERHELPERS
//#define SMEXT_ENABLE_DBMANAGER
#define SMEXT_ENABLE_GAMECONF
//#define SMEXT_ENABLE_MEMUTILS
@ -75,7 +75,7 @@
//#define SMEXT_ENABLE_ADMINSYS
//#define SMEXT_ENABLE_TEXTPARSERS
//#define SMEXT_ENABLE_USERMSGS
//#define SMEXT_ENABLE_TRANSLATOR
#define SMEXT_ENABLE_TRANSLATOR
//#define SMEXT_ENABLE_ROOTCONSOLEMENU
#endif // _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_