Add translation support to SourceTV_PrintToChat
This commit is contained in:
		
							parent
							
								
									067b238bd2
								
							
						
					
					
						commit
						4c38126ac3
					
				
							
								
								
									
										38
									
								
								natives.cpp
									
									
									
									
									
								
							
							
						
						
									
										38
									
								
								natives.cpp
									
									
									
									
									
								
							@ -825,8 +825,27 @@ static cell_t Native_PrintToChat(IPluginContext *pContext, const cell_t *params)
 | 
				
			|||||||
	char buffer[1024];
 | 
						char buffer[1024];
 | 
				
			||||||
	size_t len;
 | 
						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);
 | 
							DetectExceptions eh(pContext);
 | 
				
			||||||
		len = smutils->FormatString(buffer, sizeof(buffer), pContext, params, 2);
 | 
							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())
 | 
							if (eh.HasException())
 | 
				
			||||||
			return 0;
 | 
								return 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
@ -879,8 +898,27 @@ static cell_t Native_PrintToConsole(IPluginContext *pContext, const cell_t *para
 | 
				
			|||||||
	char buffer[1024];
 | 
						char buffer[1024];
 | 
				
			||||||
	size_t len;
 | 
						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);
 | 
							DetectExceptions eh(pContext);
 | 
				
			||||||
		len = smutils->FormatString(buffer, sizeof(buffer), pContext, params, 2);
 | 
							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())
 | 
							if (eh.HasException())
 | 
				
			||||||
			return 0;
 | 
								return 0;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
				
			|||||||
@ -61,7 +61,7 @@
 | 
				
			|||||||
/** Enable interfaces you want to use here by uncommenting lines */
 | 
					/** Enable interfaces you want to use here by uncommenting lines */
 | 
				
			||||||
#define SMEXT_ENABLE_FORWARDSYS
 | 
					#define SMEXT_ENABLE_FORWARDSYS
 | 
				
			||||||
//#define SMEXT_ENABLE_HANDLESYS
 | 
					//#define SMEXT_ENABLE_HANDLESYS
 | 
				
			||||||
//#define SMEXT_ENABLE_PLAYERHELPERS
 | 
					#define SMEXT_ENABLE_PLAYERHELPERS
 | 
				
			||||||
//#define SMEXT_ENABLE_DBMANAGER
 | 
					//#define SMEXT_ENABLE_DBMANAGER
 | 
				
			||||||
#define SMEXT_ENABLE_GAMECONF
 | 
					#define SMEXT_ENABLE_GAMECONF
 | 
				
			||||||
//#define SMEXT_ENABLE_MEMUTILS
 | 
					//#define SMEXT_ENABLE_MEMUTILS
 | 
				
			||||||
@ -75,7 +75,7 @@
 | 
				
			|||||||
//#define SMEXT_ENABLE_ADMINSYS
 | 
					//#define SMEXT_ENABLE_ADMINSYS
 | 
				
			||||||
//#define SMEXT_ENABLE_TEXTPARSERS
 | 
					//#define SMEXT_ENABLE_TEXTPARSERS
 | 
				
			||||||
//#define SMEXT_ENABLE_USERMSGS
 | 
					//#define SMEXT_ENABLE_USERMSGS
 | 
				
			||||||
//#define SMEXT_ENABLE_TRANSLATOR
 | 
					#define SMEXT_ENABLE_TRANSLATOR
 | 
				
			||||||
//#define SMEXT_ENABLE_ROOTCONSOLEMENU
 | 
					//#define SMEXT_ENABLE_ROOTCONSOLEMENU
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif // _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_
 | 
					#endif // _INCLUDE_SOURCEMOD_EXTENSION_CONFIG_H_
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user