diff --git a/hltvclientwrapper.cpp b/hltvclientwrapper.cpp index ca2dddc..b78e108 100644 --- a/hltvclientwrapper.cpp +++ b/hltvclientwrapper.cpp @@ -27,6 +27,14 @@ const char *HLTVClientWrapper::Password() return m_Password.chars(); } +unsigned int HLTVClientWrapper::GetLanguageId() +{ + // TODO expose natives to override spectator client language and remove native ifdefs + unsigned int langid = translator->GetServerLanguage(); + translator->GetLanguageByName(m_Client->GetUserSetting("cl_language"), &langid); + return langid; +} + bool HLTVClientWrapper::IsConnected() { return m_Client && m_Client->IsConnected(); diff --git a/hltvclientwrapper.h b/hltvclientwrapper.h index 5b2e88f..bb368ab 100644 --- a/hltvclientwrapper.h +++ b/hltvclientwrapper.h @@ -46,6 +46,7 @@ public: const char *Name(); const char *Ip(); const char *Password(); + unsigned int GetLanguageId(); bool IsConnected(); IClient *BaseClient(); diff --git a/natives.cpp b/natives.cpp index 8e3a671..f53e61a 100644 --- a/natives.cpp +++ b/natives.cpp @@ -825,8 +825,24 @@ 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 iHLTVRelay = hltvserver->GetHLTVServer()->GetHLTVSlot() + 1; + IGamePlayer *pHLTVRelay = playerhelpers->GetGamePlayer(iHLTVRelay); + pHLTVRelay->SetLanguageId(pClient->GetLanguageId()); + + int restoreTarget = translator->SetGlobalTarget(iHLTVRelay); +#endif + DetectExceptions eh(pContext); len = smutils->FormatString(buffer, sizeof(buffer), pContext, params, 2); + +#if SOURCE_ENGINE != SE_CSGO + pHLTVRelay->SetLanguageId(translator->GetServerLanguage()); + translator->SetGlobalTarget(restoreTarget); +#endif + if (eh.HasException()) return 0; } @@ -879,8 +895,24 @@ 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 iHLTVRelay = hltvserver->GetHLTVServer()->GetHLTVSlot() + 1; + IGamePlayer *pHLTVRelay = playerhelpers->GetGamePlayer(iHLTVRelay); + pHLTVRelay->SetLanguageId(pClient->GetLanguageId()); + + int restoreTarget = translator->SetGlobalTarget(iHLTVRelay); +#endif + DetectExceptions eh(pContext); len = smutils->FormatString(buffer, sizeof(buffer), pContext, params, 2); + +#if SOURCE_ENGINE != SE_CSGO + pHLTVRelay->SetLanguageId(translator->GetServerLanguage()); + translator->SetGlobalTarget(restoreTarget); +#endif + if (eh.HasException()) return 0; } diff --git a/smsdk_config.h b/smsdk_config.h index 71c5089..780997b 100644 --- a/smsdk_config.h +++ b/smsdk_config.h @@ -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_