Raised This Month: $51 Target: $400
 12% 

PrintToChatAll translation


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
JLmelenchon
Senior Member
Join Date: Mar 2019
Old 12-04-2020 , 11:45   PrintToChatAll translation
Reply With Quote #1

Hello. How can i add a translation to this code ? I know how to do it for PrintToClient but i can't figure it for printrtochatall.

Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <colors>

new bool:g_bIsTankAlive;

public Plugin:myinfo = 
{
	name = "L4D2 Tank Announcer",
	author = "Visor",
	description = "Announce in chat and via a sound when a Tank has spawned",
	version = "1.1.2",
	url = "https://github.com/SirPlease/L4D2-Competitive-Rework"
};

public OnMapStart()
{
	PrecacheSound("ui/pickup_secret01.wav");
}

public OnPluginStart()
{
	HookEvent("tank_spawn", EventHook:TankSpawnEvent, EventHookMode_PostNoCopy);
	HookEvent("round_start", EventHook:RoundStartEvent, EventHookMode_PostNoCopy);
}

public RoundStartEvent()
{
	g_bIsTankAlive = false;
}

public TankSpawnEvent()
{
	if (!g_bIsTankAlive)
	{
		g_bIsTankAlive = true;
		CPrintToChatAll("{red}[{default}!{red}] {olive}Tank {default}has spawned!");
		EmitSoundToAll("ui/pickup_secret01.wav");
	}
}
JLmelenchon is offline
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 12-04-2020 , 14:52   Re: PrintToChatAll translation
Reply With Quote #2

Quote:
Originally Posted by JLmelenchon View Post
Hello. How can i add a translation to this code ? I know how to do it for PrintToClient but i can't figure it for printrtochatall.

PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <colors>

new bool:g_bIsTankAlive;

public 
Plugin:myinfo 
{
    
name "L4D2 Tank Announcer",
    
author "Visor",
    
description "Announce in chat and via a sound when a Tank has spawned",
    
version "1.1.2",
    
url "https://github.com/SirPlease/L4D2-Competitive-Rework"
};

public 
OnMapStart()
{
    
PrecacheSound("ui/pickup_secret01.wav");
}

public 
OnPluginStart()
{
    
HookEvent("tank_spawn"EventHook:TankSpawnEventEventHookMode_PostNoCopy);
    
HookEvent("round_start"EventHook:RoundStartEventEventHookMode_PostNoCopy);
}

public 
RoundStartEvent()
{
    
g_bIsTankAlive false;
}

public 
TankSpawnEvent()
{
    if (!
g_bIsTankAlive)
    {
        
g_bIsTankAlive true;
        
CPrintToChatAll("{red}[{default}!{red}] {olive}Tank {default}has spawned!");
        
EmitSoundToAll("ui/pickup_secret01.wav");
    }

Hey there. Translations are easy to work with! Here is your code, NOT TESTED YET!

Here are the lines I have modified:
PHP Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>
#include <colors>

new bool:g_bIsTankAlive;

public 
Plugin:myinfo 
{
    
name "L4D2 Tank Announcer",
    
author "Visor",
    
description "Announce in chat and via a sound when a Tank has spawned",
    
version "1.1.2",
    
url "https://github.com/SirPlease/L4D2-Competitive-Rework"
};

public 
OnMapStart()
{
    
PrecacheSound("ui/pickup_secret01.wav");
        
//We need to know where our translations are, therefore let's specify a file
    
LoadTranslations("mytranslations.txt");
}

public 
OnPluginStart()
{
    
HookEvent("tank_spawn"EventHook:TankSpawnEventEventHookMode_PostNoCopy);
    
HookEvent("round_start"EventHook:RoundStartEventEventHookMode_PostNoCopy);
}

public 
RoundStartEvent()
{
    
g_bIsTankAlive false;
}

public 
TankSpawnEvent()
{
    if (!
g_bIsTankAlive)
    {
        
g_bIsTankAlive true;
        
CPrintToChatAll("{red}[{default}!{red}] {olive}%T""Translation1");
        
EmitSoundToAll("ui/pickup_secret01.wav");
    }

Now we need to list everything on our translations file. I added some languages, you can add as many as you want!:
Code:
"Phrases"
{
  "Translation1"
  {
    "en"    "Tank {default}has spawned!"
    "pt"	"Um tanque {default}spawnou!"
    "es"	"El tanque {default}ha engendrado"
    "fr"	"Le réservoir {default}a engendré"
    "de"	"Panzer {default}hat gelaicht"
  }
}
Also if you want to read more about this topic and how to use variables in translations, please mind reading this topic created by SourceMod -> https://wiki.alliedmods.net/Translat...g)#File_Format

Also I'd recommend starting using new syntax and a recent compiler version. If you use SPEdit, most likely your includes are outdated. You can update them or just download the latest version of sourcemod for your operating system and drag the .sp file to the compile.exe / compile.sh.

Best Regards,

SpirT.
__________________

Last edited by SpirT; 12-04-2020 at 14:53.
SpirT is offline
JLmelenchon
Senior Member
Join Date: Mar 2019
Old 12-05-2020 , 07:36   Re: PrintToChatAll translation
Reply With Quote #3

Thank you but this is not working, as i said PrintToChatAll translating seems to be broken or not working the same way.
JLmelenchon is offline
Balimbanana
Member
Join Date: Jan 2017
Old 12-05-2020 , 10:34   Re: PrintToChatAll translation
Reply With Quote #4

I think you need to add the LoadTranslations to OnPluginStart, not OnMapStart. Also, I am not entirely sure if CPrintToChatAll has as good functionality for translations, you might have to do a for loop and format a translation phrase per-client and use:
PHP Code:
Format(szFormatTranslationsizeof(szFormatTranslation), "{red}[{default}!{red}] {olive}%T""Translation1"client);
CPrintToChat(clientszFormatTranslation);
OR
CPrintToChat(client"%s"szFormatTranslation); 
There are different effects when you do a direct print of the buffer, and printing the %s of a buffer. It is possible that the color codes won't be parsed if you do it one way. I believe the correct parsing of the color tags is by just the buffer, but you might have to test it.

It is also good to mention that %T requires the client added after the phrase, then parameters, whereas %t will do it for the client, but might not work in this particular situation.
An example from MapChooser for %t:
PHP Code:
PrintToChatAll("[SM] %t""Nextmap Voting Started"); 
Balimbanana is offline
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 12-06-2020 , 10:00   Re: PrintToChatAll translation
Reply With Quote #5

Quote:
Originally Posted by Balimbanana View Post
I think you need to add the LoadTranslations to OnPluginStart, not OnMapStart. Also, I am not entirely sure if CPrintToChatAll has as good functionality for translations, you might have to do a for loop and format a translation phrase per-client and use:
PHP Code:
Format(szFormatTranslationsizeof(szFormatTranslation), "{red}[{default}!{red}] {olive}%T""Translation1"client);
CPrintToChat(clientszFormatTranslation);
OR
CPrintToChat(client"%s"szFormatTranslation); 
There are different effects when you do a direct print of the buffer, and printing the %s of a buffer. It is possible that the color codes won't be parsed if you do it one way. I believe the correct parsing of the color tags is by just the buffer, but you might have to test it.

It is also good to mention that %T requires the client added after the phrase, then parameters, whereas %t will do it for the client, but might not work in this particular situation.
An example from MapChooser for %t:
PHP Code:
PrintToChatAll("[SM] %t""Nextmap Voting Started"); 
My bad, I was tired and when I saw 'On' my brain instantly thought it was OnPluginStart. Even tho, I think our examples work, LoadTranslations just need to be at the plugin start. Also if I am not mistaken, %t must be used when it is a direct "chat connection", which means we can use %t on PrintToChat, PrintToChatAll, etc. When we use Format, it is not a direct "chat connection", therefore we need %T
__________________

Last edited by SpirT; 12-06-2020 at 10:03.
SpirT is offline
MAGNAT2645
Senior Member
Join Date: Nov 2015
Location: AlliedMods.net
Old 12-07-2020 , 02:09   Re: PrintToChatAll translation
Reply With Quote #6

If there is SetGlobalTransTarget (or g_SourceMod.SetGlobalTarget in C++ version) in function, you can use %t otherwise use %T (with this one you also need to specify client to determine translation language)
Code:
PrintToChat( client, "%t", "MY_PHRASE" );
PrintToChatAll( "%t", "MY_PHRASE" );

char szText[64];
FormatEx( szText, sizeof szText, "%T", "MY_PHRASE", client );
// or
SetGlobalTransTarget( client );
FormatEx( szText, sizeof szText, "%t", "MY_PHRASE" );
__________________

Last edited by MAGNAT2645; 12-07-2020 at 02:17. Reason: changed Format function to FormatEx (a little bit of optimization here) + SetGlobalTarget example in C++
MAGNAT2645 is offline
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 12-07-2020 , 04:35   Re: PrintToChatAll translation
Reply With Quote #7

Quote:
Originally Posted by MAGNAT2645 View Post
If there is SetGlobalTransTarget (or g_SourceMod.SetGlobalTarget in C++ version) in function, you can use %t otherwise use %T (with this one you also need to specify client to determine translation language)
Code:
PrintToChat( client, "%t", "MY_PHRASE" );
PrintToChatAll( "%t", "MY_PHRASE" );

char szText[64];
FormatEx( szText, sizeof szText, "%T", "MY_PHRASE", client );
// or
SetGlobalTransTarget( client );
FormatEx( szText, sizeof szText, "%t", "MY_PHRASE" );
Hmmm makes sense. I did look know to SourceMod translations post and you're completely right!
__________________
SpirT is offline
JLmelenchon
Senior Member
Join Date: Mar 2019
Old 12-08-2020 , 08:40   Re: PrintToChatAll translation
Reply With Quote #8

What will look like the code ? Tried different thing and can't make it work.
JLmelenchon is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 15:21.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode