Merge pull request #8 from nosoop/translation-support

Add translation support to SourceTV_PrintToChat
This commit is contained in:
peace-maker 2018-11-30 09:14:06 +01:00 committed by GitHub
commit 0a5cab577a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 43 additions and 2 deletions

View File

@ -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();

View File

@ -46,6 +46,7 @@ public:
const char *Name();
const char *Ip();
const char *Password();
unsigned int GetLanguageId();
bool IsConnected();
IClient *BaseClient();

View File

@ -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;
}

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_