View Single Post
Zirconium
Member
Join Date: Jul 2011
Old 09-06-2011 , 09:15   Re: [TF2]ScrollingRules
Reply With Quote #8

I'll try it with KV file like this, hope it 'll work (a scrollingrulesdata.phrases.txt file from translations dir will be loaded and used to translate and also as KV file)

PHP Code:
...
LoadTranslations("myplugin.phrases");
...
    
BuildPath(Path_SMsPathsizeof(sPath), "translations/%s"sFile);
    if (
FileExists(sPath)) {
        
FileToKeyValues(g_hRulessPath);
        
// Moves to the FIRST SubKey level before reading
        
KvGotoFirstSubKey(g_hRules);
        
// Loop for reading all rules
...
        do
        {
            
// Get the Section's Name to use it for getting translations 
            
KvGetSectionName(kvsSectionNamesizeof(sSectionName));
            
// Send the rule text to client's message queue using translations
            
if (StrContains(sSectionName"Rule"true) != -) {
                new 
String:sMsg[255];
                
// Formating the message string with translation file
                
Format(sMsgsizeof(sMsg), "%t" sSectionNameclient);
                
AddMsgToQueue(clientsMsg);
            } 
        } while (
KvGotoNextKey(kv));
        
...

stock bool:AddMsgToQueue(iClient, const String:szMessage[], any:...) {
    if (!
IsClientInGame(iClient)) {
        return 
false;
    }
    new 
String:szFormattedMsg[64];
    
VFormat(szFormattedMsgsizeof(szFormattedMsg), szMessage3);
    
PushArrayCell(g_hUserIdQueueGetClientUserId(iClient));
    
PushArrayString(g_hMsgQueueszFormattedMsg);
    
    if (
g_hMsgTimer == INVALID_HANDLE) {
        
g_hMsgTimer CreateTimer(GetConVarFloat(g_hDelay) * 1.0Timer_SendMsg_TIMER_REPEAT);
    }
    return 
true;
}
...
public 
Action:Timer_SendMsg(Handle:timer) {
    if (!
GetArraySize(g_hMsgQueue)) {
        
g_hMsgTimer INVALID_HANDLE;
        return 
Plugin_Stop;
    }
    new 
String:szMessage[64];
    
GetArrayString(g_hMsgQueue0szMessagesizeof(szMessage));
    new 
iClient GetClientOfUserId(GetArrayCell(g_hUserIdQueue0));
    if (
IsPlaying(iClient)) {
        
#if defined USECOLORS
            
CPrintToChat(iClientszMessage);
        
#else
            
PrintToChat(iClientszMessage);
        
#endif        
    
}
    
RemoveFromArray(g_hMsgQueue0);
    
RemoveFromArray(g_hUserIdQueue0);
    return 
Plugin_Handled;
}  

... 
This is working not too bad, my only problem now is i can't get the first rule section printed because it seems it's not detected correctly.
I hope i'll reach to solve this last point, if someone has an idea ?

Ok problem is solved, was an encoding problem with my phrases.txt file, switched to UTF8 without BOM, put the files in different translations subdir for each corresponding language and now all is working

Last edited by Zirconium; 09-05-2013 at 02:27.
Zirconium is offline