2009-05-06 02:28:09 +02:00
|
|
|
/*
|
|
|
|
* ============================================================================
|
|
|
|
*
|
2009-07-05 08:49:23 +02:00
|
|
|
* Zombie:Reloaded
|
2009-05-06 02:28:09 +02:00
|
|
|
*
|
2009-06-12 05:51:26 +02:00
|
|
|
* File: translation.inc
|
|
|
|
* Type: Core
|
|
|
|
* Description: Translation parsing functions.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Greyscale, Richard Helgeby
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-05-06 02:28:09 +02:00
|
|
|
*
|
|
|
|
* ============================================================================
|
2008-10-04 22:59:11 +02:00
|
|
|
*/
|
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
/**
|
|
|
|
* @section Max length of different message formats.
|
|
|
|
*/
|
|
|
|
#define TRANSLATION_MAX_LENGTH_CHAT 192
|
|
|
|
#define TRANSLATION_MAX_LENGTH_CONSOLE 1024
|
|
|
|
/**
|
|
|
|
* @endsection
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prefix on all messages printed from the plugin.
|
|
|
|
*/
|
|
|
|
#define TRANSLATION_PHRASE_PREFIX "[ZR]"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @section Text color chars.
|
|
|
|
*/
|
|
|
|
#define TRANSLATION_TEXT_COLOR_DEFAULT "\x01"
|
|
|
|
#define TRANSLATION_TEXT_COLOR_LGREEN "\x03"
|
|
|
|
#define TRANSLATION_TEXT_COLOR_GREEN "\x04"
|
|
|
|
/**
|
|
|
|
* @endsection
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* HUD text usermsg
|
|
|
|
*/
|
|
|
|
#define TRANSLATION_USERMSG_HINTTEXT "HintText"
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Load translations file here.
|
|
|
|
*/
|
|
|
|
TranslationInit()
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
// Load translations phrases used by plugin.
|
|
|
|
LoadTranslations("common.phrases.txt");
|
|
|
|
LoadTranslations("zombiereloaded.phrases.txt");
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
/**
|
|
|
|
* Translate a phrase in zombiereloaded.phrases.txt
|
|
|
|
*
|
|
|
|
* @param client The client index
|
|
|
|
* @param translation The translated text.
|
|
|
|
* @param maxlen Maximum length of the translated string.
|
|
|
|
* @param ... Translation formatting parameters.
|
|
|
|
*/
|
|
|
|
stock TranslationTranslatePhrase(client, String:translation[], maxlen, any:...)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
// Set translation target to given target.
|
|
|
|
SetGlobalTransTarget(client);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
// Dump translation into return string.
|
|
|
|
VFormat(translation, maxlen, "%t", 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format the string to the plugin's style.
|
|
|
|
*
|
|
|
|
* @param text Text to format.
|
|
|
|
* @param maxlen Maximum length of the formatted text.
|
|
|
|
*/
|
|
|
|
stock TranslationPluginFormatString(String:text[], maxlen, bool:color = true)
|
|
|
|
{
|
|
|
|
if (color)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
// Format prefix onto the string.
|
|
|
|
Format(text, maxlen, "@green%s @default%s", TRANSLATION_PHRASE_PREFIX, text);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
// Replace color tokens with CS:S color chars.
|
|
|
|
ReplaceString(text, maxlen, "@default", TRANSLATION_TEXT_COLOR_DEFAULT);
|
|
|
|
ReplaceString(text, maxlen, "@lgreen", TRANSLATION_TEXT_COLOR_LGREEN);
|
|
|
|
ReplaceString(text, maxlen, "@green", TRANSLATION_TEXT_COLOR_GREEN);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
return;
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
2009-05-14 09:32:01 +02:00
|
|
|
|
|
|
|
// Format prefix onto the string.
|
|
|
|
Format(text, maxlen, "%s %s", TRANSLATION_PHRASE_PREFIX, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print chat text to client. (with style)
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @param ... Translation formatting parameters.
|
|
|
|
*/
|
|
|
|
stock TranslationPrintToChat(client, any:...)
|
|
|
|
{
|
|
|
|
// Set translation target
|
|
|
|
SetGlobalTransTarget(client);
|
|
|
|
|
|
|
|
// Translate phrase.
|
|
|
|
decl String:translation[TRANSLATION_MAX_LENGTH_CHAT];
|
|
|
|
VFormat(translation, sizeof(translation), "%t", 2);
|
|
|
|
|
|
|
|
// Format string to create plugin style.
|
|
|
|
TranslationPluginFormatString(translation, sizeof(translation));
|
|
|
|
|
|
|
|
// Print translated phrase to client.
|
|
|
|
PrintToChat(client, translation);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format the string to the plugin's style.
|
|
|
|
*
|
|
|
|
* @param server True to also print text to server console, false just to clients.
|
2009-06-24 23:45:40 +02:00
|
|
|
* @param admin True to only print text to admins, false to print to everyone.
|
2009-05-14 09:32:01 +02:00
|
|
|
* @param ... Translation formatting parameters.
|
|
|
|
*/
|
|
|
|
stock TranslationPrintToChatAll(bool:server, bool:admin, any:...)
|
|
|
|
{
|
|
|
|
decl String:translation[TRANSLATION_MAX_LENGTH_CHAT];
|
|
|
|
|
|
|
|
if (server)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
// Set translation target
|
|
|
|
SetGlobalTransTarget(LANG_SERVER);
|
|
|
|
|
|
|
|
// Translate phrase.
|
|
|
|
VFormat(translation, sizeof(translation), "%t", 3);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
// Format string to create plugin style.
|
|
|
|
TranslationPluginFormatString(translation, sizeof(translation), false);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
// Print phrase to server.
|
|
|
|
PrintToServer(translation);
|
|
|
|
}
|
|
|
|
|
|
|
|
// x = client index.
|
|
|
|
for (new x = 1; x <= MaxClients; x++)
|
|
|
|
{
|
|
|
|
// If client isn't in-game, then stop.
|
|
|
|
if (!IsClientInGame(x))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
// If client isn't an admin, and we're only printing to admins, then stop.
|
|
|
|
if (admin && !ZRIsClientAdmin(x))
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
continue;
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
2009-05-14 09:32:01 +02:00
|
|
|
|
2009-05-29 08:43:15 +02:00
|
|
|
// Set translation target to client.
|
|
|
|
SetGlobalTransTarget(x);
|
2009-05-14 09:32:01 +02:00
|
|
|
|
|
|
|
// Translate phrase.
|
|
|
|
VFormat(translation, sizeof(translation), "%t", 3);
|
|
|
|
|
|
|
|
// Format string to create plugin style.
|
|
|
|
TranslationPluginFormatString(translation, sizeof(translation));
|
|
|
|
|
|
|
|
// Print translated phrase to client.
|
|
|
|
PrintToChat(x, translation);
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
/**
|
|
|
|
* Print console text to client. (with style)
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @param ... Translation formatting parameters.
|
|
|
|
*/
|
|
|
|
stock TranslationPrintToConsole(client, any:...)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
// Set translation target
|
2008-10-04 22:59:11 +02:00
|
|
|
SetGlobalTransTarget(client);
|
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
// Translate phrase.
|
2009-06-24 23:45:40 +02:00
|
|
|
decl String:translation[TRANSLATION_MAX_LENGTH_CONSOLE];
|
2009-05-14 09:32:01 +02:00
|
|
|
VFormat(translation, sizeof(translation), "%t", 2);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
// Format string to create plugin style.
|
|
|
|
TranslationPluginFormatString(translation, sizeof(translation), false);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
// Print translated phrase to client.
|
|
|
|
PrintToConsole(client, translation);
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
/**
|
|
|
|
* Format the string to the plugin's style.
|
|
|
|
*
|
|
|
|
* @param server True to also print text to server console, false just to clients.
|
|
|
|
* @param ... Translation formatting parameters.
|
|
|
|
*/
|
|
|
|
stock TranslationPrintToConsoleAll(bool:server, bool:admin, any:...)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-06-24 23:45:40 +02:00
|
|
|
decl String:translation[TRANSLATION_MAX_LENGTH_CONSOLE];
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
if (server)
|
|
|
|
{
|
|
|
|
// Set translation target
|
|
|
|
SetGlobalTransTarget(LANG_SERVER);
|
|
|
|
|
|
|
|
// Translate phrase.
|
|
|
|
VFormat(translation, sizeof(translation), "%t", 3);
|
|
|
|
|
|
|
|
// Format string to create plugin style.
|
|
|
|
TranslationPluginFormatString(translation, sizeof(translation), false);
|
|
|
|
|
|
|
|
// Print phrase to server.
|
|
|
|
PrintToServer(translation);
|
|
|
|
}
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
// x = client index.
|
|
|
|
for (new x = 1; x <= MaxClients; x++)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
// If client isn't in-game, then stop.
|
|
|
|
if (!IsClientInGame(x))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If client isn't an admin, and we're only printing to admins, then stop.
|
|
|
|
if (admin && !ZRIsClientAdmin(x))
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set translation target
|
|
|
|
SetGlobalTransTarget(LANG_SERVER);
|
|
|
|
|
|
|
|
// Translate phrase.
|
|
|
|
VFormat(translation, sizeof(translation), "%t", 3);
|
|
|
|
|
|
|
|
// Format string to create plugin style.
|
|
|
|
TranslationPluginFormatString(translation, sizeof(translation), false);
|
|
|
|
|
|
|
|
// Print translated phrase to client.
|
|
|
|
PrintToConsole(x, translation);
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
/**
|
|
|
|
* Print center text to client. (with style)
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @param ... Translation formatting parameters.
|
|
|
|
*/
|
|
|
|
stock TranslationPrintCenterText(client, any:...)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
// Set translation target
|
|
|
|
SetGlobalTransTarget(client);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
// Translate phrase.
|
|
|
|
decl String:translation[TRANSLATION_MAX_LENGTH_CHAT];
|
|
|
|
VFormat(translation, sizeof(translation), "%t", 2);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
// Print translated phrase to client.
|
|
|
|
PrintCenterText(client, translation);
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
/**
|
|
|
|
* Print HUD text to client. (with style)
|
|
|
|
*
|
|
|
|
* @param client The client index.
|
|
|
|
* @param ... Translation formatting parameters.
|
|
|
|
*/
|
|
|
|
stock TranslationPrintHUDText(client, any:...)
|
2008-10-04 22:59:11 +02:00
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
// Set translation target
|
|
|
|
SetGlobalTransTarget(client);
|
|
|
|
|
|
|
|
// Translate phrase.
|
|
|
|
decl String:translation[TRANSLATION_MAX_LENGTH_CHAT];
|
|
|
|
VFormat(translation, sizeof(translation), "%t", 2);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
// Print translated phrase to client.
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
// If hint text usermsg is invalid, then stop.
|
|
|
|
new Handle:hHintText = StartMessageOne(TRANSLATION_USERMSG_HINTTEXT, client);
|
|
|
|
if (hHintText == INVALID_HANDLE)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
BfWriteByte(hHintText, -1);
|
|
|
|
BfWriteString(hHintText, translation);
|
|
|
|
EndMessage();
|
2008-10-04 22:59:11 +02:00
|
|
|
}
|
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
/**
|
|
|
|
* Print text to server. (with style)
|
|
|
|
*
|
|
|
|
* @param ... Translation formatting parameters.
|
|
|
|
*/
|
|
|
|
stock TranslationPrintToServer(any:...)
|
2009-02-15 22:25:17 +01:00
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
// Set translation target
|
2009-02-15 22:25:17 +01:00
|
|
|
SetGlobalTransTarget(LANG_SERVER);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
// Translate phrase.
|
2009-06-24 23:45:40 +02:00
|
|
|
decl String:translation[TRANSLATION_MAX_LENGTH_CONSOLE];
|
2009-05-14 09:32:01 +02:00
|
|
|
VFormat(translation, sizeof(translation), "%t", 1);
|
|
|
|
|
|
|
|
// Format string to create plugin style.
|
|
|
|
TranslationPluginFormatString(translation, sizeof(translation), false);
|
2008-10-04 22:59:11 +02:00
|
|
|
|
2009-05-14 09:32:01 +02:00
|
|
|
// Print translated phrase to client.
|
|
|
|
PrintToServer(translation);
|
2008-11-18 01:02:23 +01:00
|
|
|
}
|
|
|
|
|
2009-04-15 23:40:45 +02:00
|
|
|
/**
|
2009-05-14 09:32:01 +02:00
|
|
|
* Print chat text to client. (with style)
|
2009-04-20 05:43:20 +02:00
|
|
|
*
|
|
|
|
* @param client The client index.
|
2009-05-14 09:32:01 +02:00
|
|
|
* @param ... Translation formatting parameters.
|
2009-04-15 23:40:45 +02:00
|
|
|
*/
|
2009-05-14 09:32:01 +02:00
|
|
|
stock TranslationReplyToCommand(client, any:...)
|
2009-04-15 23:40:45 +02:00
|
|
|
{
|
2009-05-14 09:32:01 +02:00
|
|
|
// Set translation target
|
|
|
|
SetGlobalTransTarget(client);
|
|
|
|
|
|
|
|
// Translate phrase.
|
2009-06-24 23:45:40 +02:00
|
|
|
decl String:translation[TRANSLATION_MAX_LENGTH_CONSOLE];
|
2009-05-14 09:32:01 +02:00
|
|
|
VFormat(translation, sizeof(translation), "%t", 2);
|
|
|
|
|
2009-05-29 08:43:15 +02:00
|
|
|
if (ZRIsClientValid(client))
|
|
|
|
{
|
|
|
|
// Format string to create plugin style. (color)
|
|
|
|
TranslationPluginFormatString(translation, sizeof(translation));
|
|
|
|
|
|
|
|
// Print translated phrase to client's chat/console.
|
|
|
|
PrintToChat(client, translation);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Format string to create plugin style. (no color)
|
|
|
|
TranslationPluginFormatString(translation, sizeof(translation), false);
|
|
|
|
|
|
|
|
// Print to server.
|
|
|
|
PrintToServer(translation);
|
|
|
|
}
|
2009-06-08 00:13:38 +02:00
|
|
|
}
|