localize all static strings (IRC and WWOL are not localized due to encoding issue with IRC protocol)

This commit is contained in:
HarpyWar 2014-06-28 21:32:11 +04:00
parent 268520ec8b
commit 69545f25bf
13 changed files with 640 additions and 673 deletions

View file

@ -40,6 +40,7 @@
#include "anongame_infos.h"
#include "team.h"
#include "server.h"
#include "i18n.h"
#include "compat/snprintf.h"
#include "common/setup_after.h"
@ -454,10 +455,10 @@ namespace pvpgn
/* Return text with account lock */
extern char * account_get_locktext(t_account * account, bool with_author)
extern std::string account_get_locktext(t_account * account, bool with_author)
{
char msgtemp[MAX_MESSAGE_LEN], msgtemp2[MAX_MESSAGE_LEN];
snprintf(msgtemp, sizeof(msgtemp), "");
std::string msgtemp;
t_connection * c = account_get_conn(account);
// append author of ban
if (with_author)
@ -465,24 +466,21 @@ namespace pvpgn
if (char const * author = account_get_auth_lockby(account))
if (author && author[0] != '\0')
{
snprintf(msgtemp2, sizeof(msgtemp2), " by %s", author);
std::strcat(msgtemp, msgtemp2);
msgtemp += localize(c, " by {}", author);
}
}
// append remaining time
if (unsigned int locktime = account_get_auth_locktime(account))
snprintf(msgtemp2, sizeof(msgtemp2), " for %.48s", seconds_to_timestr(locktime - now));
msgtemp += localize(c, " for {}", seconds_to_timestr(locktime - now));
else
snprintf(msgtemp2, sizeof(msgtemp2), " permanently");
std::strcat(msgtemp, msgtemp2);
msgtemp += localize(c, " permanently");
// append reason
char const * reason = account_get_auth_lockreason(account);
if (reason && reason[0] != '\0')
{
snprintf(msgtemp2, sizeof(msgtemp2), " with a reason \"%s\"", reason);
std::strcat(msgtemp, msgtemp2);
msgtemp += localize(c, " with a reason \"{}\"", reason);
}
return msgtemp;
}

View file

@ -93,7 +93,7 @@ namespace pvpgn
extern int account_set_auth_mutetime(t_account * account, unsigned int val);
extern int account_set_auth_mutereason(t_account * account, char const * val);
extern int account_set_auth_muteby(t_account * account, char const * val);
extern char * account_get_locktext(t_account * account, bool with_author = true);
extern std::string account_get_locktext(t_account * account, bool with_author = true);
/* profile */
extern char const * account_get_sex(t_account * account); /* the profile attributes are updated directly in bnetd.c */

View file

@ -32,6 +32,7 @@
#include "common/xalloc.h"
#include "message.h"
#include "connection.h"
#include "i18n.h"
#include "common/setup_after.h"
@ -59,7 +60,7 @@ namespace pvpgn
t_output * output;
char temp[MAX_MESSAGE_LEN];
message_send_text(c, message_type_info, c, "Alias list:");
message_send_text(c, message_type_info, c, localize(c, "Alias list:"));
LIST_TRAVERSE_CONST(aliaslist_head, elem1)
{
if (!(alias = (t_alias*)elem_get_data(elem1)))
@ -580,7 +581,7 @@ namespace pvpgn
if (do_alias(c, cmd, text) < 0)
{
message_send_text(c, message_type_info, c, "No such alias. Use // to show the list.");
message_send_text(c, message_type_info, c, localize(c, "No such alias. Use // to show the list."));
return -1;
}
return 0;

View file

@ -41,6 +41,7 @@
#include "account_wrap.h"
#include "prefs.h"
#include "irc.h"
#include "i18n.h"
#include "common/setup_after.h"
#ifdef WITH_LUA
@ -465,7 +466,7 @@ namespace pvpgn
&& (channel->currmembers == 1)
&& (account_is_operator_or_admin(conn_get_account(connection), channel_get_name(channel)) == 0))
{
message_send_text(connection, message_type_info, connection, "you are now tempOP for this channel");
message_send_text(connection, message_type_info, connection, localize(connection, "you are now tempOP for this channel"));
conn_set_tmpOP_channel(connection, (char *)channel_get_name(channel));
channel_update_userflags(connection);
}

File diff suppressed because it is too large Load diff

View file

@ -73,8 +73,9 @@
#include "command_groups.h"
#include "attrlayer.h"
#include "anongame_wol.h"
#include "common/setup_after.h"
#include "icons.h"
#include "i18n.h"
#include "common/setup_after.h"
#ifdef WITH_LUA
#include "luainterface.h"
@ -128,43 +129,9 @@ namespace pvpgn
}
if (filename = prefs_get_motdfile()) {
t_tag gamelang = conn_get_gamelang(c);
char lang_str[sizeof(t_tag)+1];
char * lang_filename;
char * tempmotdfile;
char * def_langtag;
char * extention;
std::string lang_filename = i18n_filename(filename, gamelang);
std::memset(lang_str, 0, sizeof(lang_str));
tag_uint_to_str(lang_str, gamelang);
tempmotdfile = xstrdup(filename);
def_langtag = std::strrchr(tempmotdfile, '-');
if (!def_langtag) {
extention = std::strrchr(tempmotdfile, '.');
}
else {
*def_langtag = '\0';
def_langtag++;
extention = std::strrchr(def_langtag, '.');
}
lang_filename = (char*)xmalloc(std::strlen(tempmotdfile) + 1 + std::strlen(lang_str) + 1 + std::strlen(extention) + 1);
if (extention) {
*extention = '\0';
extention++;
}
if ((gamelang) && (lang_str))
if (extention)
std::sprintf(lang_filename, "%s-%s.%s", tempmotdfile, lang_str, extention);
else
std::sprintf(lang_filename, "%s-%s", tempmotdfile, lang_str);
else {
INFO0("client does not specifed proper gamelang, sending default motd");
std::sprintf(lang_filename, "%s", filename);
}
if (fp = std::fopen(lang_filename, "r")) {
if (fp = std::fopen(lang_filename.c_str(), "r")) {
message_send_file(c, fp);
if (std::fclose(fp) < 0) {
eventlog(eventlog_level_error, __FUNCTION__, "could not close MOTD file \"%s\" after reading (std::fopen: %s)", lang_filename, std::strerror(errno));
@ -182,10 +149,6 @@ namespace pvpgn
eventlog(eventlog_level_error, __FUNCTION__, "could not open MOTD file \"%s\" for reading (std::fopen: %s)", filename, std::strerror(errno));
}
}
if (tempmotdfile)
xfree((void *)tempmotdfile);
if (lang_filename)
xfree((void *)lang_filename);
}
c->protocol.cflags |= conn_flags_welcomed;
}

View file

@ -73,6 +73,7 @@
#include "friends.h"
#include "autoupdate.h"
#include "anongame.h"
#include "i18n.h"
#ifdef WIN32_GUI
#include <win32/winmain.h>
#endif
@ -1691,9 +1692,9 @@ namespace pvpgn
if (supports_locked_reply)
{
bn_int_set(&rpacket->u.server_loginreply1.message, SERVER_LOGINREPLY2_MESSAGE_LOCKED);
char msgtemp[MAX_MESSAGE_LEN];
snprintf(msgtemp, sizeof(msgtemp), "This account has been locked%s", account_get_locktext(account, true));
packet_append_string(rpacket, msgtemp);
std::string msgtemp = localize(c, "This account has been locked");
msgtemp += account_get_locktext(account, true);
packet_append_string(rpacket, msgtemp.c_str());
}
else {
bn_int_set(&rpacket->u.server_loginreply1.message, SERVER_LOGINREPLY2_MESSAGE_BADPASS);
@ -2115,9 +2116,9 @@ namespace pvpgn
else if (account_get_auth_lock(account) == 1) { /* default to false */
eventlog(eventlog_level_info, __FUNCTION__, "[%d] login for \"%s\" refused (this account is locked)", conn_get_socket(c), username);
bn_int_set(&rpacket->u.server_logonproofreply.response, SERVER_LOGONPROOFREPLY_RESPONSE_CUSTOM);
char msgtemp[MAX_MESSAGE_LEN];
snprintf(msgtemp, sizeof(msgtemp), "This account has been locked%s", account_get_locktext(account, true));
packet_append_string(rpacket, msgtemp);
std::string msgtemp = localize(c, "This account has been locked");
msgtemp += account_get_locktext(account, true);
packet_append_string(rpacket, msgtemp.c_str());
}
else {
t_hash serverhash;

View file

@ -32,6 +32,7 @@
#include "command_groups.h"
#include "account_wrap.h"
#include "connection.h"
#include "i18n.h"
#include "common/setup_after.h"
namespace pvpgn
@ -80,7 +81,7 @@ namespace pvpgn
if (hfd == NULL)
{ /* an error ocured opening readonly the help file, helpfile_unload was called, or helpfile_init hasn't been called */
message_send_text(c, message_type_error, c, "Oops ! There is a problem with the help file. Please contact the administrator of the server.");
message_send_text(c, message_type_error, c, localize(c, "Oops ! There is a problem with the help file. Please contact the administrator of the server."));
return 0;
}

View file

@ -44,11 +44,13 @@
#include "connection.h"
#include "icons.h"
#include "account_wrap.h"
#include "common/setup_after.h"
#include "message.h"
#include "helpfile.h"
#include "channel.h"
#include "command.h"
#include "i18n.h"
#include "common/setup_after.h"
namespace pvpgn
{
@ -84,7 +86,7 @@ namespace pvpgn
char msgtemp[MAX_MESSAGE_LEN];
if (!(conn_get_channel(c))) {
message_send_text(c, message_type_error, c, "This command can only be used inside a channel.");
message_send_text(c, message_type_error, c, localize(c, "This command can only be used inside a channel."));
return -1;
}
else {
@ -95,7 +97,7 @@ namespace pvpgn
clienttag = conn_get_clienttag(c);
if (!clienttag || clienttag == CLIENTTAG_BNCHATBOT_UINT)
{
message_send_text(c, message_type_error, c, "This command can only be used from the game.");
message_send_text(c, message_type_error, c, localize(c, "This command can only be used from the game."));
return -1;
}
@ -177,7 +179,7 @@ namespace pvpgn
}
if (!is_found || strlen(iconcode) != 4)
{
message_send_text(c, message_type_error, c, "Bad icon.");
message_send_text(c, message_type_error, c, localize(c, "Bad icon."));
return -1;
}
snprintf(msgtemp, sizeof(msgtemp), "Set new icon is succeed.", account_get_name(account));

View file

@ -41,9 +41,11 @@
#include "server.h"
#include "prefs.h"
#include "connection.h"
#include "common/setup_after.h"
#include "helpfile.h"
#include "command.h"
#include "i18n.h"
#include "common/setup_after.h"
namespace pvpgn
{
@ -393,7 +395,7 @@ namespace pvpgn
extern int ipbanlist_add(t_connection * c, char const * cp, std::time_t endtime)
{
t_ipban_entry * entry;
char tstr[MAX_MESSAGE_LEN];
std::string msgtemp;
if (!(entry = ipban_str_to_ipban_entry(cp)))
{
@ -411,19 +413,19 @@ namespace pvpgn
if (endtime == 0)
{
std::sprintf(tstr, "%s banned permamently by %s.", cp, conn_get_username(c));
eventlog(eventlog_level_info, __FUNCTION__, "%s", tstr);
message_send_admins(c, message_type_info, tstr);
std::sprintf(tstr, "%s banned permamently.", cp);
message_send_text(c, message_type_info, c, tstr);
msgtemp = localize(c, "{} banned permamently by {}.", cp, conn_get_username(c));
eventlog(eventlog_level_info, __FUNCTION__, msgtemp.c_str());
message_send_admins(c, message_type_info, msgtemp.c_str());
msgtemp = localize(c, "{} banned permamently.", cp);
message_send_text(c, message_type_info, c, msgtemp);
}
else
{
std::sprintf(tstr, "%s banned for %.48s by %s.", cp, seconds_to_timestr(entry->endtime - now), conn_get_username(c));
eventlog(eventlog_level_info, __FUNCTION__, "%s", tstr);
message_send_admins(c, message_type_info, tstr);
std::sprintf(tstr, "%s banned for %.48s.", cp, seconds_to_timestr(entry->endtime - now));
message_send_text(c, message_type_info, c, tstr);
msgtemp = localize(c, "{} banned for {} by {}.", cp, seconds_to_timestr(entry->endtime - now), conn_get_username(c));
eventlog(eventlog_level_info, __FUNCTION__, msgtemp.c_str());
message_send_admins(c, message_type_info, msgtemp.c_str());
msgtemp = localize(c, "{} banned for {}.", cp, seconds_to_timestr(entry->endtime - now));
message_send_text(c, message_type_info, c, msgtemp);
}
}
@ -466,7 +468,7 @@ namespace pvpgn
unsigned int bmin;
char minstr[MAX_TIME_STR];
unsigned int i;
char tstr[MAX_MESSAGE_LEN];
std::string msgtemp;
for (i = 0; std::isdigit((int)timestr[i]) && i < sizeof(minstr)-1; i++)
minstr[i] = timestr[i];
@ -476,12 +478,14 @@ namespace pvpgn
{
if (c)
{
if (std::strlen(minstr) < 1)
message_send_text(c, message_type_info, c, "There was an error in std::time.");
else
msgtemp = "There was an error in std::time.";
//if (std::strlen(minstr) < 1)
// message_send_text(c, message_type_info, c, localize(c, msgtemp));
//else
{
std::sprintf(tstr, "There was an error in std::time. Banning only for: %s minutes.", minstr);
message_send_text(c, message_type_info, c, tstr);
msgtemp += " ";
msgtemp += localize(c, "Banning only for: {} minutes.", minstr);
message_send_text(c, message_type_info, c, msgtemp);
}
}
}

View file

@ -39,9 +39,10 @@
#include "message.h"
#include "prefs.h"
#include "connection.h"
#include "common/setup_after.h"
#include "helpfile.h"
#include "command.h"
#include "i18n.h"
#include "common/setup_after.h"
namespace pvpgn
@ -251,7 +252,7 @@ namespace pvpgn
extern int handle_mail_command(t_connection * c, char const * text)
{
if (!prefs_get_mail_support()) {
message_send_text(c, message_type_error, c, "This server has NO mail support.");
message_send_text(c, message_type_error, c, localize(c, "This server has NO mail support."));
return -1;
}
@ -331,22 +332,22 @@ namespace pvpgn
t_account * recv = accountlist_find_account(receiver);
if (!recv) {
message_send_text(c, message_type_error, c, "Receiver UNKNOWN!");
message_send_text(c, message_type_error, c, localize(c, "Receiver UNKNOWN!"));
return;
}
Mailbox mbox(account_get_uid(recv));
if (get_mail_quota(recv) <= mbox.size()) {
message_send_text(c, message_type_error, c, "Receiver has reached his mail quota. Your message will NOT be sent.");
message_send_text(c, message_type_error, c, localize(c, "Receiver has reached his mail quota. Your message will NOT be sent."));
return;
}
try {
mbox.deliver(conn_get_username(c), message);
message_send_text(c, message_type_info, c, "Your mail has been sent successfully.");
message_send_text(c, message_type_info, c, localize(c, "Your mail has been sent successfully."));
}
catch (const Mailbox::DeliverError&) {
message_send_text(c, message_type_error, c, "There was an error completing your request!");
message_send_text(c, message_type_error, c, localize(c, "There was an error completing your request!"));
}
}
@ -368,7 +369,7 @@ namespace pvpgn
if (token.empty()) { /* user wants to see the mail summary */
if (mbox.empty()) {
message_send_text(c, message_type_info, c, "You have no mail.");
message_send_text(c, message_type_info, c, localize(c, "You have no mail."));
return;
}
@ -412,7 +413,7 @@ namespace pvpgn
message_send_text(c, message_type_info, c, mail.message().c_str());
}
catch (const Mailbox::ReadError&) {
message_send_text(c, message_type_error, c, "There was an error completing your request.");
message_send_text(c, message_type_error, c, localize(c, "There was an error completing your request."));
}
}
}
@ -425,7 +426,7 @@ namespace pvpgn
}
if (token.empty()) {
message_send_text(c, message_type_error, c, "Please specify which message to delete. Use the following syntax: /mail delete {<index>|all} .");
message_send_text(c, message_type_error, c, localize(c, "Please specify which message to delete. Use the following syntax: /mail delete {<index>|all} ."));
return;
}
@ -434,16 +435,16 @@ namespace pvpgn
if (token == "all") {
mbox.clear();
message_send_text(c, message_type_info, c, "Successfully deleted messages.");
message_send_text(c, message_type_info, c, localize(c, "Successfully deleted messages."));
}
else {
if (std::find_if(token.begin(), token.end(), NonNumericChar) != token.end()) {
message_send_text(c, message_type_error, c, "Invalid index. Please use /mail delete {<index>|all} where <index> is a number.");
message_send_text(c, message_type_error, c, localize(c, "Invalid index. Please use /mail delete {<index>|all} where <index> is a number."));
return;
}
mbox.erase(std::atoi(token.c_str()));
message_send_text(c, message_type_info, c, "Succesfully deleted message.");
message_send_text(c, message_type_info, c, localize(c, "Succesfully deleted message."));
}
}

View file

@ -987,6 +987,7 @@ namespace pvpgn
return -1;
}
// empty messages are needed to separate text (or example, in bnhelp output)
if (text && text[0] == '\0')
text = " "; /* empty messages crash some clients, just send whitespace */
@ -994,7 +995,6 @@ namespace pvpgn
if (text && (std::strlen(text) > MAX_MESSAGE_LEN)) {
/* PELISH: We are trying to support MAX_IRC_MESSAGE_LEN for IRC and also
MAX_MESSAGE_LEN for bnet */
eventlog(eventlog_level_warn, __FUNCTION__, "line too long, truncation...");
temp = std::string(text, text + MAX_MESSAGE_LEN);
text = temp.c_str();
}
@ -1595,6 +1595,10 @@ namespace pvpgn
return rez;
}
extern int message_send_text(t_connection * dst, t_message_type type, t_connection * src, std::string text)
{
return message_send_text(dst, type, src, text.c_str());
}
extern int message_send_text(t_connection * dst, t_message_type type, t_connection * src, char const * text)
{

View file

@ -120,6 +120,7 @@ namespace pvpgn
#include <cstdio>
#define JUST_NEED_TYPES
#include <string>
#include "connection.h"
#include "common/bnet_protocol.h"
#undef JUST_NEED_TYPES
@ -138,6 +139,7 @@ namespace pvpgn
extern int message_send_admins(t_connection * src, t_message_type type, char const * text);
/* the following are "shortcuts" to avoid calling message_create(), message_send(), message_destroy() */
extern int message_send_text(t_connection * dst, t_message_type type, t_connection * src, std::string text);
extern int message_send_text(t_connection * dst, t_message_type type, t_connection * src, char const * text);
extern int message_send_formatted(t_connection * dst, char const * text);
extern int message_send_file(t_connection * dst, std::FILE * fd);