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_SM, sPath, sizeof(sPath), "translations/%s", sFile);
if (FileExists(sPath)) {
FileToKeyValues(g_hRules, sPath);
// 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(kv, sSectionName, sizeof(sSectionName));
// Send the rule text to client's message queue using translations
if (StrContains(sSectionName, "Rule", true) != -1 ) {
new String:sMsg[255];
// Formating the message string with translation file
Format(sMsg, sizeof(sMsg), "%t" , sSectionName, client);
AddMsgToQueue(client, sMsg);
}
} while (KvGotoNextKey(kv));
...
stock bool:AddMsgToQueue(iClient, const String:szMessage[], any:...) {
if (!IsClientInGame(iClient)) {
return false;
}
new String:szFormattedMsg[64];
VFormat(szFormattedMsg, sizeof(szFormattedMsg), szMessage, 3);
PushArrayCell(g_hUserIdQueue, GetClientUserId(iClient));
PushArrayString(g_hMsgQueue, szFormattedMsg);
if (g_hMsgTimer == INVALID_HANDLE) {
g_hMsgTimer = CreateTimer(GetConVarFloat(g_hDelay) * 1.0, Timer_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_hMsgQueue, 0, szMessage, sizeof(szMessage));
new iClient = GetClientOfUserId(GetArrayCell(g_hUserIdQueue, 0));
if (IsPlaying(iClient)) {
#if defined USECOLORS
CPrintToChat(iClient, szMessage);
#else
PrintToChat(iClient, szMessage);
#endif
}
RemoveFromArray(g_hMsgQueue, 0);
RemoveFromArray(g_hUserIdQueue, 0);
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