AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved Attaching a translation file to a vote menu (https://forums.alliedmods.net/showthread.php?t=303531)

Psyk0tik 12-11-2017 02:52

Attaching a translation file to a vote menu
 
Hey guys, can anyone help me add a translation file to this? I want the menu title and options to be translatable but I don't know the proper format for attaching a translation file to these lines.

PHP Code:

public Action Command_Warp(int clientint args)
{
    if(!
l4d_ass_enable.BoolValue || !l4d_ass_teleport_enable.BoolValue || !l4d_ass_teleport_vote.BoolValue || l4d_ass_teleport_auto.BoolValue || NumTanks3)
        return;
    if(!
l4d_ass_teleport_tank.BoolValue)
        
CountTanks();
    if(
l4d_ass_teleport_vote.BoolValue)
    {
        
char cmEntry[8];
        
Menu chooseMenu CreateMenu(chooseMenuHandler2);
        
SetVoteResultCallback(chooseMenuchooseMenuResults2);
        
chooseMenu.SetTitle("Teleport speedrunners?");
        
IntToString(0cmEntrysizeof(cmEntry));
        
chooseMenu.AddItem(cmEntry"Yes");
        
IntToString(1cmEntrysizeof(cmEntry));
        
chooseMenu.AddItem(cmEntry"No");
        
SetMenuPagination(chooseMenuMENU_NO_PAGINATION);
        
int totalHumanshumanPlayers[MAXPLAYERS+1];
        for(
int i 1<= MaxClientsi++)
        {
            if(!
IsValidClient(i))
                continue;
            
humanPlayers[totalHumans++] = i;
        }

        
VoteMenu(chooseMenuhumanPlayerstotalHumans30);
    }


I tried this but it didn't work:

PHP Code:

        chooseMenu.SetTitle("%T""TeleportSpeedrunners");
        
chooseMenu.AddItem(cmEntry"%T""YesOption");
        
chooseMenu.AddItem(cmEntry"%T""NoOption"); 


8guawong 12-11-2017 05:05

Re: Attaching a translation file to a vote menu
 
Not tested

PHP Code:

        char buffer[64];
        
Format(buffersizeof(buffer), "%T""TeleportSpeedrunners");
        
chooseMenu.SetTitle(buffer); 
        
Format(buffersizeof(buffer), "%T""YesOption");
        
chooseMenu.AddItem(cmEntry"Yes"buffer);
        
Format(buffersizeof(buffer), "%T""NoOption");
        
chooseMenu.AddItem(cmEntry"No"buffer); 


Psyk0tik 12-11-2017 05:16

Re: Attaching a translation file to a vote menu
 
Quote:

Originally Posted by 8guawong (Post 2565552)
Not tested

PHP Code:

        char buffer[64];
        
Format(buffersizeof(buffer), "%T""TeleportSpeedrunners");
        
chooseMenu.SetTitle(buffer); 
        
Format(buffersizeof(buffer), "%T""YesOption");
        
chooseMenu.AddItem(cmEntry"Yes"buffer);
        
Format(buffersizeof(buffer), "%T""NoOption");
        
chooseMenu.AddItem(cmEntry"No"buffer); 


The compiler says that these lines have an "argument type mismatch (argument 4)"

PHP Code:

        chooseMenu.AddItem(cmEntry"Yes"buffer);
        
chooseMenu.AddItem(cmEntry"No"buffer); 

This is how I implemented your code:

PHP Code:

        char buffer[64], cmEntry[8];
        
Menu chooseMenu CreateMenu(chooseMenuHandler2);
        
SetVoteResultCallback(chooseMenuchooseMenuResults2);
        
Format(buffersizeof(buffer), "%T""TeleportSpeedrunners");
        
chooseMenu.SetTitle(buffer); 
        
Format(buffersizeof(buffer), "%T""YesOption");
        
chooseMenu.AddItem(cmEntry"Yes"buffer);
        
Format(buffersizeof(buffer), "%T""NoOption");
        
chooseMenu.AddItem(cmEntry"No"buffer);  
        
SetMenuPagination(chooseMenuMENU_NO_PAGINATION);
        
int totalHumanshumanPlayers[MAXPLAYERS+1]; 


8guawong 12-11-2017 05:19

Re: Attaching a translation file to a vote menu
 
not used to new syntax XD
below should work

PHP Code:

        chooseMenu.AddItem("Yes"buffer); 
        
chooseMenu.AddItem("No"buffer); 


Psyk0tik 12-11-2017 05:30

Re: Attaching a translation file to a vote menu
 
Quote:

Originally Posted by 8guawong (Post 2565558)
not used to new syntax XD
below should work

PHP Code:

        chooseMenu.AddItem("Yes"buffer); 
        
chooseMenu.AddItem("No"buffer); 


It compiles now, but in-game it gives errors saying that these are incorrectly formatted:

PHP Code:

        Format(buffersizeof(buffer), "%T""TeleportSpeedrunners");
        
Format(buffersizeof(buffer), "%T""YesOption");
        
Format(buffersizeof(buffer), "%T""NoOption"); 


8guawong 12-11-2017 05:33

Re: Attaching a translation file to a vote menu
 
use %t

Psyk0tik 12-11-2017 05:41

Re: Attaching a translation file to a vote menu
 
Quote:

Originally Posted by 8guawong (Post 2565562)
use %t

I was able to make it work:

PHP Code:

public Action Command_Warp(int clientint args)
{
    if(!
l4d_ass_enable.BoolValue || !l4d_ass_teleport_enable.BoolValue || !l4d_ass_teleport_vote.BoolValue || l4d_ass_teleport_auto.BoolValue || NumTanks3)
        return;
    if(!
l4d_ass_teleport_tank.BoolValue)
        
CountTanks();
    if(
l4d_ass_teleport_vote.BoolValue)
    {
        
char buffer[64];
        
int totalHumanshumanPlayers[MAXPLAYERS+1];
        for(
int i 1<= MaxClientsi++)
        {
            if(!
IsValidClient(i))
                continue;
            
humanPlayers[totalHumans++] = i;
        }

        for(
int i 1<= MaxClientsi++)
        {
            if(
IsValidClient(i))
            {
                
Menu chooseMenu CreateMenu(chooseMenuHandler2);
                
SetVoteResultCallback(chooseMenuchooseMenuResults2);
                
Format(buffersizeof(buffer), "%T""TeleportSpeedrunners"i);
                
chooseMenu.SetTitle(buffer); 
                
Format(buffersizeof(buffer), "%T""YesOption"i);
                
chooseMenu.AddItem("Yes"buffer);
                
Format(buffersizeof(buffer), "%T""NoOption"i);
                
chooseMenu.AddItem("No"buffer); 
                
SetMenuPagination(chooseMenuMENU_NO_PAGINATION);
                
VoteMenu(chooseMenuhumanPlayerstotalHumans30);
            }
        }
    }


Thank you for your help!

Powerlord 12-11-2017 13:55

Re: Attaching a translation file to a vote menu
 
For menu translations, you can just create the menu once, then...
  • use the MenuAction_Display callback to translate the menu title using Format / SetPanelTitle.
  • use the MenuAction_DisplayItem callback to translate menu items using Format / RedrawMenuItem.

WildCard65 12-11-2017 16:44

Re: Attaching a translation file to a vote menu
 
Quote:

Originally Posted by Crasher_3637 (Post 2565563)
I was able to make it work:

PHP Code:

public Action Command_Warp(int clientint args)
{
    if(!
l4d_ass_enable.BoolValue || !l4d_ass_teleport_enable.BoolValue || !l4d_ass_teleport_vote.BoolValue || l4d_ass_teleport_auto.BoolValue || NumTanks3)
        return;
    if(!
l4d_ass_teleport_tank.BoolValue)
        
CountTanks();
    if(
l4d_ass_teleport_vote.BoolValue)
    {
        
char buffer[64];
        
int totalHumanshumanPlayers[MAXPLAYERS+1];
        for(
int i 1<= MaxClientsi++)
        {
            if(!
IsValidClient(i))
                continue;
            
humanPlayers[totalHumans++] = i;
        }

        for(
int i 1<= MaxClientsi++)
        {
            if(
IsValidClient(i))
            {
                
Menu chooseMenu CreateMenu(chooseMenuHandler2);
                
SetVoteResultCallback(chooseMenuchooseMenuResults2);
                
Format(buffersizeof(buffer), "%T""TeleportSpeedrunners"i);
                
chooseMenu.SetTitle(buffer); 
                
Format(buffersizeof(buffer), "%T""YesOption"i);
                
chooseMenu.AddItem("Yes"buffer);
                
Format(buffersizeof(buffer), "%T""NoOption"i);
                
chooseMenu.AddItem("No"buffer); 
                
SetMenuPagination(chooseMenuMENU_NO_PAGINATION);
                
VoteMenu(chooseMenuhumanPlayerstotalHumans30);
            }
        }
    }


Thank you for your help!

Here's what I believe is a cleaner version of your code:

PHP Code:

public Action Command_Warp(int clientint args)
{
    if(!
l4d_ass_enable.BoolValue || !l4d_ass_teleport_enable.BoolValue || !l4d_ass_teleport_vote.BoolValue || l4d_ass_teleport_auto.BoolValue || NumTanks3)
        return;
    if(!
l4d_ass_teleport_tank.BoolValue)
        
CountTanks();
    if(
l4d_ass_teleport_vote.BoolValue)
    {
        
char buffer[64];
        
int totalHumanshumanPlayers[MAXPLAYERS+1];
        for(
int i 1<= MaxClientsi++)
        {
            if(!
IsValidClient(i))
                continue;
            
humanPlayers[totalHumans++] = i;
        }

        for(
int i 1<= MaxClientsi++)
        {
            if(
IsValidClient(i))
            {
                
Menu chooseMenu CreateMenu(chooseMenuHandler2);
                
SetVoteResultCallback(chooseMenuchooseMenuResults2);

                
SetGlobalTransTarget(i); // Set translation target for "%t" translation format specifier.

                
Format(buffersizeof(buffer), "%t""TeleportSpeedrunners");
                
chooseMenu.SetTitle(buffer); 
                
Format(buffersizeof(buffer), "%t""YesOption");
                
chooseMenu.AddItem("Yes"buffer);
                
Format(buffersizeof(buffer), "%t""NoOption");
                
chooseMenu.AddItem("No"buffer); 

                
SetMenuPagination(chooseMenuMENU_NO_PAGINATION);
                
VoteMenu(chooseMenuhumanPlayerstotalHumans30);
            }
        }
        
SetGlobalTransTarget(LANG_SERVER); // If this fails compile, replace it with client #0
    
}




All times are GMT -4. The time now is 17:46.

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