diff options
| author | Adam <Adam@anope.org> | 2011-02-04 15:30:31 -0500 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2011-02-04 15:30:31 -0500 |
| commit | 08583dc107974252312fb7c87532c9deb68e7f63 (patch) | |
| tree | 0c42ec7422752cabd8352b49be976b4dc100c56c /src | |
| parent | c362a1e077d5ede9eadbe79483f2a755b5883e9a (diff) | |
Moved the language strings which are only used once
out of the core and into the modules that use them.
Diffstat (limited to 'src')
| -rw-r--r-- | src/botserv.cpp | 30 | ||||
| -rw-r--r-- | src/channels.cpp | 4 | ||||
| -rw-r--r-- | src/chanserv.cpp | 82 | ||||
| -rw-r--r-- | src/command.cpp | 32 | ||||
| -rw-r--r-- | src/commands.cpp | 37 | ||||
| -rw-r--r-- | src/hostserv.cpp | 4 | ||||
| -rw-r--r-- | src/language.cpp | 5255 | ||||
| -rw-r--r-- | src/mail.cpp | 12 | ||||
| -rw-r--r-- | src/memoserv.cpp | 58 | ||||
| -rw-r--r-- | src/misc.cpp | 18 | ||||
| -rw-r--r-- | src/modules.cpp | 9 | ||||
| -rw-r--r-- | src/nickserv.cpp | 16 | ||||
| -rw-r--r-- | src/operserv.cpp | 40 | ||||
| -rw-r--r-- | src/protocol.cpp | 10 | ||||
| -rw-r--r-- | src/regchannel.cpp | 4 | ||||
| -rw-r--r-- | src/sessions.cpp | 4 | ||||
| -rw-r--r-- | src/users.cpp | 30 |
17 files changed, 230 insertions, 5415 deletions
diff --git a/src/botserv.cpp b/src/botserv.cpp index d3c7a7450..5f321a125 100644 --- a/src/botserv.cpp +++ b/src/botserv.cpp @@ -125,7 +125,7 @@ void botchanmsgs(User *u, ChannelInfo *ci, const Anope::string &buf) if (ci->botflags.HasFlag(BS_KICK_BOLDS) && realbuf.find(2) != Anope::string::npos) { check_ban(ci, u, TTB_BOLDS); - bot_kick(ci, u, BOT_REASON_BOLD); + bot_kick(ci, u, _("Don't use bolds on this channel!")); return; } @@ -133,7 +133,7 @@ void botchanmsgs(User *u, ChannelInfo *ci, const Anope::string &buf) if (ci->botflags.HasFlag(BS_KICK_COLORS) && realbuf.find(3) != Anope::string::npos) { check_ban(ci, u, TTB_COLORS); - bot_kick(ci, u, BOT_REASON_COLOR); + bot_kick(ci, u, _("Don't use colors on this channel!")); return; } @@ -141,7 +141,7 @@ void botchanmsgs(User *u, ChannelInfo *ci, const Anope::string &buf) if (ci->botflags.HasFlag(BS_KICK_REVERSES) && realbuf.find(22) != Anope::string::npos) { check_ban(ci, u, TTB_REVERSES); - bot_kick(ci, u, BOT_REASON_REVERSE); + bot_kick(ci, u, _("Don't use reverses on this channel!")); return; } @@ -149,7 +149,7 @@ void botchanmsgs(User *u, ChannelInfo *ci, const Anope::string &buf) if (ci->botflags.HasFlag(BS_KICK_ITALICS) && realbuf.find(29) != Anope::string::npos) { check_ban(ci, u, TTB_ITALICS); - bot_kick(ci, u, BOT_REASON_ITALIC); + bot_kick(ci, u, _("Don't use italics on this channel!")); return; } @@ -157,7 +157,7 @@ void botchanmsgs(User *u, ChannelInfo *ci, const Anope::string &buf) if (ci->botflags.HasFlag(BS_KICK_UNDERLINES) && realbuf.find(31) != Anope::string::npos) { check_ban(ci, u, TTB_UNDERLINES); - bot_kick(ci, u, BOT_REASON_UNDERLINE); + bot_kick(ci, u, _("Don't use underlines on this channel!")); return; } @@ -182,7 +182,7 @@ void botchanmsgs(User *u, ChannelInfo *ci, const Anope::string &buf) if (i && l && i >= ci->capsmin && i * 100 / (i + l) >= ci->capspercent) { check_ban(ci, u, TTB_CAPS); - bot_kick(ci, u, BOT_REASON_CAPS); + bot_kick(ci, u, _("Turn caps lock OFF!")); return; } } @@ -255,9 +255,9 @@ void botchanmsgs(User *u, ChannelInfo *ci, const Anope::string &buf) { check_ban(ci, u, TTB_BADWORDS); if (Config->BSGentleBWReason) - bot_kick(ci, u, BOT_REASON_BADWORD_GENTLE); + bot_kick(ci, u, _("Watch your language!")); else - bot_kick(ci, u, BOT_REASON_BADWORD, bw->word.c_str()); + bot_kick(ci, u, _("Don't use the word \"%s\" on this channel!"), bw->word.c_str()); return; } @@ -281,7 +281,7 @@ void botchanmsgs(User *u, ChannelInfo *ci, const Anope::string &buf) if (ud->lines >= ci->floodlines) { check_ban(ci, u, TTB_FLOOD); - bot_kick(ci, u, BOT_REASON_FLOOD); + bot_kick(ci, u, _("Stop flooding!")); return; } } @@ -308,7 +308,7 @@ void botchanmsgs(User *u, ChannelInfo *ci, const Anope::string &buf) if (ud->times >= ci->repeattimes) { check_ban(ci, u, TTB_REPEAT); - bot_kick(ci, u, BOT_REASON_REPEAT); + bot_kick(ci, u, _("Stop repeating yourself!")); return; } } @@ -486,7 +486,7 @@ void check_ban(ChannelInfo *ci, User *u, int ttbtype) /* This makes a bot kick a user. Works somewhat like notice_lang in fact ;) */ -void bot_kick(ChannelInfo *ci, User *u, LanguageString message, ...) +void bot_kick(ChannelInfo *ci, User *u, const char *message, ...) { va_list args; char buf[1024]; @@ -494,7 +494,7 @@ void bot_kick(ChannelInfo *ci, User *u, LanguageString message, ...) if (!ci || !ci->bi || !ci->c || !u) return; - Anope::string fmt = GetString(u, message); + Anope::string fmt = GetString(u->Account(), message); va_start(args, message); if (fmt.empty()) return; @@ -519,7 +519,7 @@ void bot_raw_ban(User *requester, ChannelInfo *ci, User *u, const Anope::string if (ModeManager::FindUserModeByName(UMODE_PROTECTED) && u->IsProtected() && requester != u) { - ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", GetString(requester, ACCESS_DENIED).c_str()); + ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", GetString(requester->Account(), LanguageString::ACCESS_DENIED).c_str()); return; } @@ -530,7 +530,7 @@ void bot_raw_ban(User *requester, ChannelInfo *ci, User *u, const Anope::string if (matches_list(ci->c, u, CMODE_EXCEPT)) { - ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", GetString(requester, BOT_EXCEPT).c_str()); + ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", GetString(requester->Account(), _("User matches channel except.")).c_str()); return; } @@ -561,7 +561,7 @@ void bot_raw_kick(User *requester, ChannelInfo *ci, User *u, const Anope::string if (ModeManager::FindUserModeByName(UMODE_PROTECTED) && u->IsProtected() && requester != u) { - ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", GetString(requester, ACCESS_DENIED).c_str()); + ircdproto->SendPrivmsg(ci->bi, ci->name, "%s", GetString(requester->Account(), LanguageString::ACCESS_DENIED).c_str()); return; } diff --git a/src/channels.cpp b/src/channels.cpp index a4c920227..72b09ae1e 100644 --- a/src/channels.cpp +++ b/src/channels.cpp @@ -133,9 +133,9 @@ void Channel::JoinUser(User *user) if (this->ci && check_access(user, this->ci, CA_MEMO) && this->ci->memos.memos.size() > 0) { if (this->ci->memos.memos.size() == 1) - user->SendMessage(MemoServ, MEMO_X_ONE_NOTICE, this->ci->memos.memos.size(), this->ci->name.c_str()); + user->SendMessage(MemoServ, _("There is \002%d\002 memo on channel %s."), this->ci->memos.memos.size(), this->ci->name.c_str()); else - user->SendMessage(MemoServ, MEMO_X_MANY_NOTICE, this->ci->memos.memos.size(), this->ci->name.c_str()); + user->SendMessage(MemoServ, _("There are \002%d\002 memos on channel %s."), this->ci->memos.memos.size(), this->ci->name.c_str()); } if (!Config->s_BotServ.empty() && this->ci && this->ci->bi) diff --git a/src/chanserv.cpp b/src/chanserv.cpp index 741349a46..64cfeeef5 100644 --- a/src/chanserv.cpp +++ b/src/chanserv.cpp @@ -60,45 +60,45 @@ static int def_levels[][2] = { }; LevelInfo levelinfo[] = { - { CA_AUTOHALFOP, "AUTOHALFOP", CHAN_LEVEL_AUTOHALFOP }, - { CA_AUTOOP, "AUTOOP", CHAN_LEVEL_AUTOOP }, - { CA_AUTOPROTECT, "AUTOPROTECT", CHAN_LEVEL_AUTOPROTECT }, - { CA_AUTOVOICE, "AUTOVOICE", CHAN_LEVEL_AUTOVOICE }, - { CA_NOJOIN, "NOJOIN", CHAN_LEVEL_NOJOIN }, - { CA_SIGNKICK, "SIGNKICK", CHAN_LEVEL_SIGNKICK }, - { CA_ACCESS_LIST, "ACC-LIST", CHAN_LEVEL_ACCESS_LIST }, - { CA_ACCESS_CHANGE, "ACC-CHANGE", CHAN_LEVEL_ACCESS_CHANGE }, - { CA_AKICK, "AKICK", CHAN_LEVEL_AKICK }, - { CA_SET, "SET", CHAN_LEVEL_SET }, - { CA_BAN, "BAN", CHAN_LEVEL_BAN }, - { CA_BANME, "BANME", CHAN_LEVEL_BANME }, - { CA_GETKEY, "GETKEY", CHAN_LEVEL_GETKEY }, - { CA_HALFOP, "HALFOP", CHAN_LEVEL_HALFOP }, - { CA_HALFOPME, "HALFOPME", CHAN_LEVEL_HALFOPME }, - { CA_INFO, "INFO", CHAN_LEVEL_INFO }, - { CA_KICK, "KICK", CHAN_LEVEL_KICK }, - { CA_KICKME, "KICKME", CHAN_LEVEL_KICKME }, - { CA_INVITE, "INVITE", CHAN_LEVEL_INVITE }, - { CA_OPDEOP, "OPDEOP", CHAN_LEVEL_OPDEOP }, - { CA_OPDEOPME, "OPDEOPME", CHAN_LEVEL_OPDEOPME }, - { CA_PROTECT, "PROTECT", CHAN_LEVEL_PROTECT }, - { CA_PROTECTME, "PROTECTME", CHAN_LEVEL_PROTECTME }, - { CA_TOPIC, "TOPIC", CHAN_LEVEL_TOPIC }, - { CA_MODE, "MODE", CHAN_LEVEL_MODE }, - { CA_UNBAN, "UNBAN", CHAN_LEVEL_UNBAN }, - { CA_VOICE, "VOICE", CHAN_LEVEL_VOICE }, - { CA_VOICEME, "VOICEME", CHAN_LEVEL_VOICEME }, - { CA_MEMO, "MEMO", CHAN_LEVEL_MEMO }, - { CA_ASSIGN, "ASSIGN", CHAN_LEVEL_ASSIGN }, - { CA_BADWORDS, "BADWORDS", CHAN_LEVEL_BADWORDS }, - { CA_FANTASIA, "FANTASIA", CHAN_LEVEL_FANTASIA }, - { CA_GREET, "GREET", CHAN_LEVEL_GREET }, - { CA_NOKICK, "NOKICK", CHAN_LEVEL_NOKICK }, - { CA_SAY, "SAY", CHAN_LEVEL_SAY }, - { CA_AUTOOWNER, "AUTOOWNER", CHAN_LEVEL_AUTOOWNER }, - { CA_OWNER, "OWNER", CHAN_LEVEL_OWNER }, - { CA_OWNERME, "OWNERME", CHAN_LEVEL_OWNERME }, - { CA_FOUNDER, "FOUNDER", CHAN_LEVEL_FOUNDER }, + { CA_AUTOHALFOP, "AUTOHALFOP", _("Automatic mode +h") }, + { CA_AUTOOP, "AUTOOP", _("Automatic channel operator status") }, + { CA_AUTOPROTECT, "AUTOPROTECT", _("Automatic mode +a") }, + { CA_AUTOVOICE, "AUTOVOICE", _("Automatic mode +v") }, + { CA_NOJOIN, "NOJOIN", _("Not allowed to join channel") }, + { CA_SIGNKICK, "SIGNKICK", _("No signed kick when SIGNKICK LEVEL is used") }, + { CA_ACCESS_LIST, "ACC-LIST", _("Allowed to view the access list") }, + { CA_ACCESS_CHANGE, "ACC-CHANGE", _("Allowed to modify the access list") }, + { CA_AKICK, "AKICK", _("Allowed to use AKICK command") }, + { CA_SET, "SET", _("Allowed to use SET command (not FOUNDER/PASSWORD)"), }, + { CA_BAN, "BAN", _("Allowed to use BAN command") }, + { CA_BANME, "BANME", _("Allowed to ban him/herself") }, + { CA_GETKEY, "GETKEY", _("Allowed to use GETKEY command") }, + { CA_HALFOP, "HALFOP", _("Allowed to (de)halfop him/herself") }, + { CA_HALFOPME, "HALFOPME", _("Allowed to (de)halfop him/herself") }, + { CA_INFO, "INFO", _("Allowed to use INFO command with ALL option") }, + { CA_KICK, "KICK", _("Allowed to use KICK command") }, + { CA_KICKME, "KICKME", _("Allowed to kick him/herself") }, + { CA_INVITE, "INVITE", _("Allowed to use INVITE command") }, + { CA_OPDEOP, "OPDEOP", _("Allowed to use OP/DEOP commands") }, + { CA_OPDEOPME, "OPDEOPME", _("Allowed to (de)op him/herself") }, + { CA_PROTECT, "PROTECT", _("Allowed to use PROTECT/DEPROTECT commands") }, + { CA_PROTECTME, "PROTECTME", _("Allowed to (de)protect him/herself"), }, + { CA_TOPIC, "TOPIC", _("Allowed to use TOPIC command") }, + { CA_MODE, "MODE", _("Allowed to use MODE command") }, + { CA_UNBAN, "UNBAN", _("Allowed to use UNBAN command") }, + { CA_VOICE, "VOICE", _("Allowed to use VOICE/DEVOICE commands") }, + { CA_VOICEME, "VOICEME", _("Allowed to (de)voice him/herself") }, + { CA_MEMO, "MEMO", _("Allowed to list/read channel memos") }, + { CA_ASSIGN, "ASSIGN", _("Allowed to assign/unassign a bot") }, + { CA_BADWORDS, "BADWORDS", _("Allowed to use BADWORDS command") }, + { CA_FANTASIA, "FANTASIA", _("Allowed to use fantaisist commands") }, + { CA_GREET, "GREET", _("Greet message displayed") }, + { CA_NOKICK, "NOKICK", _("Never kicked by the bot's kickers") }, + { CA_SAY, "SAY", _("Allowed to use SAY and ACT commands") }, + { CA_AUTOOWNER, "AUTOOWNER", _("Automatic mode +q") }, + { CA_OWNER, "OWNER", _("Allowed to use OWNER command") }, + { CA_OWNERME, "OWNERME", _("Allowed to (de)owner him/herself") }, + { CA_FOUNDER, "FOUNDER", _("Allowed to issue commands restricted to channel founders") }, { -1 } }; int levelinfo_maxwidth = 0; @@ -301,7 +301,7 @@ int check_valid_admin(User *user, Channel *chan, int servermode) if (servermode && !check_access(user, chan->ci, CA_AUTOPROTECT)) { - user->SendMessage(ChanServ, CHAN_IS_REGISTERED, Config->s_ChanServ.c_str()); + user->SendMessage(ChanServ, _("This channel has been registered with %s."), Config->s_ChanServ.c_str()); chan->RemoveMode(NULL, CMODE_PROTECT, user->nick); return 0; } @@ -331,7 +331,7 @@ int check_valid_op(User *user, Channel *chan, int servermode) if (servermode && !check_access(user, chan->ci, CA_AUTOOP)) { - user->SendMessage(ChanServ, CHAN_IS_REGISTERED, Config->s_ChanServ.c_str()); + user->SendMessage(ChanServ, _("This channel has been registered with %s."), Config->s_ChanServ.c_str()); if (owner) chan->RemoveMode(NULL, CMODE_OWNER, user->nick); diff --git a/src/command.cpp b/src/command.cpp index 17de467e9..398f4249c 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -28,28 +28,6 @@ CommandSource::~CommandSource() } } -void CommandSource::Reply(LanguageString message, ...) -{ - Anope::string m = GetString(this->u, message); - - m = m.replace_all_cs("%S", this->owner->nick); - - if (m.length() >= 4096) - Log() << "Warning, language string " << message << " is longer than 4096 bytes"; - - va_list args; - char buf[4096]; - va_start(args, message); - vsnprintf(buf, sizeof(buf) - 1, m.c_str(), args); - va_end(args); - - sepstream sep(buf, '\n'); - Anope::string line; - - while (sep.GetToken(line)) - this->Reply(line.empty() ? " " : line.c_str()); -} - void CommandSource::Reply(const char *message, ...) { va_list args; @@ -60,12 +38,20 @@ void CommandSource::Reply(const char *message, ...) va_start(args, message); vsnprintf(buf, BUFSIZE - 1, message, args); - this->reply.push_back(buf); + this->Reply(Anope::string(buf)); va_end(args); } } +void CommandSource::Reply(const Anope::string &message) +{ + sepstream sep(message, '\n'); + Anope::string tok; + while (sep.GetToken(tok)) + this->reply.push_back(tok); +} + Command::Command(const Anope::string &sname, size_t min_params, size_t max_params, const Anope::string &spermission) : Flags<CommandFlag>(CommandFlagStrings), MaxParams(max_params), MinParams(min_params), name(sname), permission(spermission) { this->module = NULL; diff --git a/src/commands.cpp b/src/commands.cpp index 4cfb1c636..e3a52a503 100644 --- a/src/commands.cpp +++ b/src/commands.cpp @@ -52,18 +52,22 @@ void mod_run_cmd(BotInfo *bi, User *u, Command *c, const Anope::string &command, { if (!bi || !u) return; + + PushLanguage("anope", u->Account() ? u->Account()->language : ""); if (!c) { - u->SendMessage(bi, UNKNOWN_COMMAND_HELP, command.c_str(), bi->nick.c_str()); + u->SendMessage(bi, _("Unknown command \002%s\002. \"%R%s HELP\" for help."), command.c_str(), bi->nick.c_str()); + PopLanguage(); return; } // Command requires registered users only if (!c->HasFlag(CFLAG_ALLOW_UNREGISTERED) && !u->IsIdentified()) { - u->SendMessage(bi, NICK_IDENTIFY_REQUIRED, Config->s_NickServ.c_str()); + u->SendMessage(bi, _(LanguageString::NICK_IDENTIFY_REQUIRED), Config->s_NickServ.c_str()); Log(LOG_COMMAND, "denied", bi) << "Access denied for unregistered user " << u->GetMask() << " with command " << command; + PopLanguage(); return; } @@ -98,27 +102,31 @@ void mod_run_cmd(BotInfo *bi, User *u, Command *c, const Anope::string &command, { if (ci->HasFlag(CI_FORBIDDEN) && !c->HasFlag(CFLAG_ALLOW_FORBIDDEN)) { - u->SendMessage(bi, CHAN_X_FORBIDDEN, ci->name.c_str()); + u->SendMessage(bi, _(LanguageString::CHAN_X_FORBIDDEN), ci->name.c_str()); Log(LOG_COMMAND, "denied", bi) << "Access denied for user " << u->GetMask() << " with command " << command << " because of FORBIDDEN channel " << ci->name; + PopLanguage(); return; } else if (ci->HasFlag(CI_SUSPENDED) && !c->HasFlag(CFLAG_ALLOW_SUSPENDED)) { - u->SendMessage(bi, CHAN_X_FORBIDDEN, ci->name.c_str()); + u->SendMessage(bi, _(LanguageString::CHAN_X_FORBIDDEN), ci->name.c_str()); Log(LOG_COMMAND, "denied", bi) << "Access denied for user " << u->GetMask() << " with command " << command << " because of SUSPENDED channel " << ci->name; + PopLanguage(); return; } } else if (!c->HasFlag(CFLAG_ALLOW_UNREGISTEREDCHANNEL)) { - u->SendMessage(bi, CHAN_X_NOT_REGISTERED, params[0].c_str()); + u->SendMessage(bi, _(LanguageString::CHAN_X_NOT_REGISTERED), params[0].c_str()); + PopLanguage(); return; } } /* A user not giving a channel name for a param that should be a channel */ else { - u->SendMessage(bi, CHAN_X_INVALID, params[0].c_str()); + u->SendMessage(bi, LanguageString::CHAN_X_INVALID, params[0].c_str()); + PopLanguage(); return; } } @@ -133,19 +141,24 @@ void mod_run_cmd(BotInfo *bi, User *u, Command *c, const Anope::string &command, if (params.size() < c->MinParams) { c->OnSyntaxError(source, !params.empty() ? params[params.size() - 1] : ""); + PopLanguage(); return; } EventReturn MOD_RESULT; FOREACH_RESULT(I_OnPreCommand, OnPreCommand(source, c, params)); if (MOD_RESULT == EVENT_STOP) + { + PopLanguage(); return; + } // If the command requires a permission, and they aren't registered or don't have the required perm, DENIED if (!c->permission.empty() && !u->Account()->HasCommand(c->permission)) { - u->SendMessage(bi, ACCESS_DENIED); + u->SendMessage(bi, LanguageString::ACCESS_DENIED); Log(LOG_COMMAND, "denied", bi) << "Access denied for user " << u->GetMask() << " with command " << command; + PopLanguage(); return; } @@ -184,23 +197,23 @@ void mod_help_cmd(BotInfo *bi, User *u, ChannelInfo *ci, const Anope::string &cm source.fantasy = ci != NULL; if (!c || (Config->HidePrivilegedCommands && !c->permission.empty() && (!u->Account() || !u->Account()->HasCommand(c->permission))) || !c->OnHelp(source, subcommand)) - u->SendMessage(bi, NO_HELP_AVAILABLE, cmd.c_str()); + source.Reply( _("No help available for \002%s\002."), cmd.c_str()); else { u->SendMessage(bi, " "); /* Inform the user what permission is required to use the command */ if (!c->permission.empty()) - u->SendMessage(bi, COMMAND_REQUIRES_PERM, c->permission.c_str()); + source.Reply(_("Access to this command requires the permission \002%s\002 to be present in your opertype."), c->permission.c_str()); /* User isn't identified and needs to be to use this command */ if (!c->HasFlag(CFLAG_ALLOW_UNREGISTERED) && !u->IsIdentified()) - u->SendMessage(bi, COMMAND_IDENTIFY_REQUIRED); + source.Reply( _("You need to be identified to use this command.")); /* User doesn't have the proper permission to use this command */ else if (!c->permission.empty() && (!u->Account() || !u->Account()->HasCommand(c->permission))) - u->SendMessage(bi, COMMAND_CANNOT_USE); + source.Reply(_("You cannot use this command.")); /* User can use this command */ else - u->SendMessage(bi, COMMAND_CAN_USE); + source.Reply(_("You can use this command.")); } } diff --git a/src/hostserv.cpp b/src/hostserv.cpp index a3edce445..bfd68f17f 100644 --- a/src/hostserv.cpp +++ b/src/hostserv.cpp @@ -169,8 +169,8 @@ void do_on_id(User *u) u->UpdateHost(); if (!na->hostinfo.GetIdent().empty()) - u->SendMessage(HostServ, HOST_IDENT_ACTIVATED, na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str()); + u->SendMessage(HostServ, _("Your vhost of \002%s\002@\002%s\002 is now activated."), na->hostinfo.GetIdent().c_str(), na->hostinfo.GetHost().c_str()); else - u->SendMessage(HostServ, HOST_ACTIVATED, na->hostinfo.GetHost().c_str()); + u->SendMessage(HostServ, _("Your vhost of \002%s\002 is now activated."), na->hostinfo.GetHost().c_str()); } } diff --git a/src/language.cpp b/src/language.cpp index 2823cc117..7256ebbbf 100644 --- a/src/language.cpp +++ b/src/language.cpp @@ -1,11 +1,5 @@ #include "services.h" - -#if GETTEXT_FOUND -# include LIBINTL -# define _(x) gettext(x) -#else -# define _(x) x -#endif +#include <stack> std::vector<Anope::string> languages; @@ -38,50 +32,49 @@ void InitLanguages() #endif } -const Anope::string GetString(const Anope::string &language, LanguageString string) +const Anope::string GetString(NickCore *nc, const char *string) { - return GetString("anope", language, language_strings[string]); + return GetString("anope", nc ? nc->language : "", string); } -const Anope::string GetString(LanguageString string) +const Anope::string GetString(const Anope::string &domain, const Anope::string &lang, const char *string) { - return GetString("anope", "", language_strings[string]); + PushLanguage(domain, lang); + const char *t_string = anope_gettext(string); + PopLanguage(); + return t_string; } -const Anope::string GetString(NickCore *nc, LanguageString string) +#if GETTEXT_FOUND +static std::stack<std::pair<Anope::string, Anope::string > > language_stack; + +void PushLanguage(const Anope::string &domain, Anope::string language) { - return GetString(nc ? nc->language : "", string); + if (language.empty() && !Config->NSDefLanguage.empty()) + language = Config->NSDefLanguage; + + language_stack.push(std::make_pair(domain, language)); } -const Anope::string GetString(User *u, LanguageString string) +void PopLanguage() { - if (!u) - return GetString(string); - NickCore *nc = u->Account(); - NickAlias *na = NULL; - if (!nc) - na = findnick(u->nick); - return GetString(nc ? nc : (na ? na->nc : NULL), string); + language_stack.pop(); } -#if GETTEXT_FOUND /* Used by gettext to make it always dynamically load language strings (so we can drop them in while Anope is running) */ extern "C" int _nl_msg_cat_cntr; -const Anope::string GetString(const char *domain, Anope::string language, const Anope::string &string) -{ - if (language == "en") - language.clear(); - /* Apply def language */ - if (language.empty() && !Config->NSDefLanguage.empty()) - language = Config->NSDefLanguage; - - if (language.empty()) +const char *anope_gettext(const char *string) +{ + std::pair<Anope::string, Anope::string> lang_info; + if (!language_stack.empty()) + lang_info = language_stack.top(); + if (lang_info.first.empty() || lang_info.second.empty()) return string; ++_nl_msg_cat_cntr; #ifdef _WIN32 - SetThreadLocale(MAKELCID(MAKELANGID(WindowsGetLanguage(language.c_str()), SUBLANG_DEFAULT), SORT_DEFAULT)); + SetThreadLocale(MAKELCID(MAKELANGID(WindowsGetLanguage(lang_info.second.c_str()), SUBLANG_DEFAULT), SORT_DEFAULT)); #else /* First, set LANGUAGE env variable. * Some systems (Debian) don't care about this, so we must setlocale LC_ALL aswell. @@ -90,11 +83,11 @@ const Anope::string GetString(const char *domain, Anope::string language, const * use the LANGUAGE env variable. We must reset the locale to en_US (or, anything not * C or POSIX) then. */ - setenv("LANGUAGE", language.c_str(), 1); - if (setlocale(LC_ALL, language.c_str()) == NULL) + setenv("LANGUAGE", lang_info.second.c_str(), 1); + if (setlocale(LC_ALL, lang_info.second.c_str()) == NULL) setlocale(LC_ALL, "en_US"); #endif - const char *ret = dgettext(domain, string.c_str()); + const char *translated_string = dgettext(lang_info.first.c_str(), string); #ifdef _WIN32 SetThreadLocale(MAKELCID(MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), SORT_DEFAULT)); #else @@ -102,5198 +95,38 @@ const Anope::string GetString(const char *domain, Anope::string language, const setlocale(LC_ALL, ""); #endif - Anope::string translated = ret ? ret : ""; + Anope::string translated = translated_string ? translated_string : ""; if (Config->UseStrictPrivMsg) translated = translated.replace_all_cs("%R", "/"); else translated = translated.replace_all_cs("%R", "/msg "); - return translated; + return translated.c_str(); } #else -const Anope::string GetString(const char *domain, Anope::string language, const Anope::string &string) +void PushLanguage(const Anope::string &, Anope::string) { - Anope::string translated = string; +} + +void PopLanguage() +{ +} + +const char *anope_gettext(const char *string) +{ + Anope::string translated = string ? string : ""; if (Config->UseStrictPrivMsg) translated = translated.replace_all_cs("%R", "/"); else translated = translated.replace_all_cs("%R", "/msg "); - return translated; + return translated.c_str(); } #endif -void SyntaxError(CommandSource &source, const Anope::string &command, LanguageString message) +void SyntaxError(CommandSource &source, const Anope::string &command, const Anope::string &message) { - if (command.empty()) - return; - - Anope::string str = GetString(source.u, message); - source.Reply(SYNTAX_ERROR, str.c_str()); - source.Reply(MORE_INFO, source.owner->nick.c_str(), command.c_str()); + source.Reply(_("Syntax: \002%s\002"), message.c_str()); + source.Reply(_(LanguageString::MORE_INFO), source.owner->nick.c_str(), command.c_str()); } -const char *const language_strings[LANG_STRING_COUNT] = { - /* LANGUAGE_NAME */ - _("English"), - /* COMMAND_REQUIRES_PERM */ - _("Access to this command requires the permission %s to be present in your opertype."), - /* COMMAND_IDENTIFY_REQUIRED */ - _("You need to be identified to use this command."), - /* COMMAND_CANNOT_USE */ - _("You cannot use this command."), - /* COMMAND_CAN_USE */ - _("You can use this command."), - /* COMMAND_DEPRECATED */ - _("This command is deprecated, use \"%R%s MODE\" instead."), - /* USER_RECORD_NOT_FOUND */ - _("Internal error - unable to process request."), - /* UNKNOWN_COMMAND */ - _("Unknown command %s."), - /* UNKNOWN_COMMAND_HELP */ - _("Unknown command %s. \"%R%s HELP\" for help."), - /* SYNTAX_ERROR */ - _("Syntax: %s"), - /* MORE_INFO */ - _("%R%s HELP %s for more information."), - /* NO_HELP_AVAILABLE */ - _("No help available for %s."), - /* BAD_USERHOST_MASK */ - _("Mask must be in the form user@host."), - /* BAD_EXPIRY_TIME */ - _("Invalid expiry time."), - /* USERHOST_MASK_TOO_WIDE */ - _("%s coverage is too wide; Please use a more specific mask."), - /* SERVICE_OFFLINE */ - _("%s is currently offline."), - /* READ_ONLY_MODE */ - _("Notice: Services is in read-only mode; changes will not be saved!"), - /* PASSWORD_INCORRECT */ - _("Password incorrect."), - /* INVALID_TARGET */ - _("\"/msg %s\" is no longer supported. Use \"/msg %s@%s\" or \"/%s\" instead."), - /* ACCESS_DENIED */ - _("Access denied."), - /* MORE_OBSCURE_PASSWORD */ - _("Please try again with a more obscure password. Passwords should be at least five characters long, should not be something easily guessed (e.g. your real name or your nick), and cannot contain the space or tab characters."), - /* PASSWORD_TOO_LONG */ - _("Your password is too long. Please try again with a shorter password."), - /* NICK_NOT_REGISTERED */ - _("Your nick isn't registered."), - /* NICK_X_IS_SERVICES */ - _("Nick %s is part of this Network's Services."), - /* NICK_X_NOT_REGISTERED */ - _("Nick %s isn't registered."), - /* NICK_X_IN_USE */ - _("Nick %s is currently in use."), - /* NICK_X_NOT_IN_USE */ - _("Nick %s isn't currently in use."), - /* NICK_X_NOT_ON_CHAN */ - _("%s is not currently on channel %s."), - /* NICK_X_FORBIDDEN */ - _("Nick %s may not be registered or used."), - /* NICK_X_FORBIDDEN_OPER */ - _("Nick %s has been forbidden by %s:\n" - "%s"), - /* NICK_X_ILLEGAL */ - _("Nick %s is an illegal nickname and cannot be used."), - /* NICK_X_TRUNCATED */ - _("Nick %s was truncated to %d characters."), - /* NICK_X_SUSPENDED */ - _("Nick %s is currently suspended."), - /* CHAN_X_NOT_REGISTERED */ - _("Channel %s isn't registered."), - /* CHAN_X_NOT_IN_USE */ - _("Channel %s doesn't exist."), - /* CHAN_X_FORBIDDEN */ - _("Channel %s may not be registered or used."), - /* CHAN_X_FORBIDDEN_OPER */ - _("Channel %s has been forbidden by %s:\n" - "%s"), - /* CHAN_X_SUSPENDED */ - _(" Suspended: [%s] %s"), - /* NICK_IDENTIFY_REQUIRED */ - _("Password authentication required for that command.\n" - "Retry after typing %R%s IDENTIFY password."), - /* MAIL_DISABLED */ - _("Services have been configured to not send mail."), - /* MAIL_INVALID */ - _("E-mail for %s is invalid."), - /* MAIL_X_INVALID */ - _("%s is not a valid e-mail address."), - /* MAIL_LATER */ - _("Cannot send mail now; please retry a little later."), - /* MAIL_DELAYED */ - _("Please wait %d seconds and retry."), - /* NO_REASON */ - _("No reason"), - /* UNKNOWN */ - _("<unknown>"), - /* DURATION_DAY */ - _("1 day"), - /* DURATION_DAYS */ - _("%d days"), - /* DURATION_HOUR */ - _("1 hour"), - /* DURATION_HOURS */ - _("%d hours"), - /* DURATION_MINUTE */ - _("1 minute"), - /* DURATION_MINUTES */ - _("%d minutes"), - /* DURATION_SECOND */ - _("1 second"), - /* DURATION_SECONDS */ - _("%d seconds"), - /* NO_EXPIRE */ - _("does not expire"), - /* EXPIRES_SOON */ - _("expires at next database update"), - /* EXPIRES_M */ - _("expires in %d minutes"), - /* EXPIRES_1M */ - _("expires in %d minute"), - /* EXPIRES_HM */ - _("expires in %d hours, %d minutes"), - /* EXPIRES_H1M */ - _("expires in %d hours, %d minute"), - /* EXPIRES_1HM */ - _("expires in %d hour, %d minutes"), - /* EXPIRES_1H1M */ - _("expires in %d hour, %d minute"), - /* EXPIRES_D */ - _("expires in %d days"), - /* EXPIRES_1D */ - _("expires in %d day"), - /* END_OF_ANY_LIST */ - _("End of %s list."), - /* LIST_INCORRECT_RANGE */ - _("Incorrect range specified. The correct syntax is #from-to."), - /* CS_LIST_INCORRECT_RANGE */ - _("To search for channels starting with #, search for the channel\n" - "name without the #-sign prepended (anope instead of #anope)."), - /* NICK_IS_REGISTERED */ - _("This nick is owned by someone else. Please choose another.\n" - "(If this is your nick, type %R%s IDENTIFY password.)"), - /* NICK_IS_SECURE */ - _("This nickname is registered and protected. If it is your\n" - "nick, type %R%s IDENTIFY password. Otherwise,\n" - "please choose a different nick."), - /* NICK_MAY_NOT_BE_USED */ - _("This nickname may not be used. Please choose another one."), - /* FORCENICKCHANGE_IN_1_MINUTE */ - _("If you do not change within one minute, I will change your nick."), - /* FORCENICKCHANGE_IN_20_SECONDS */ - _("If you do not change within 20 seconds, I will change your nick."), - /* FORCENICKCHANGE_NOW */ - _("This nickname has been registered; you may not use it."), - /* FORCENICKCHANGE_CHANGING */ - _("Your nickname is now being changed to %s"), - /* NICK_REGISTER_SYNTAX */ - _("REGISTER password [email]"), - /* NICK_REGISTER_SYNTAX_EMAIL */ - _("REGISTER password email"), - /* NICK_REGISTRATION_DISABLED */ - _("Sorry, nickname registration is temporarily disabled."), - /* NICK_REGISTRATION_FAILED */ - _("Sorry, registration failed."), - /* NICK_REG_PLEASE_WAIT */ - _("Please wait %d seconds before using the REGISTER command again."), - /* NICK_CANNOT_BE_REGISTERED */ - _("Nickname %s may not be registered."), - /* NICK_ALREADY_REGISTERED */ - _("Nickname %s is already registered!"), - /* NICK_REGISTERED */ - _("Nickname %s registered under your account: %s"), - /* NICK_REGISTERED_NO_MASK */ - _("Nickname %s registered."), - /* NICK_PASSWORD_IS */ - _("Your password is %s - remember this for later use."), - /* NICK_REG_DELAY */ - _("You must have been using this nick for at least %d seconds to register."), - /* NICK_GROUP_SYNTAX */ - _("GROUP target password"), - /* NICK_GROUP_DISABLED */ - _("Sorry, nickname grouping is temporarily disabled."), - /* NICK_GROUP_PLEASE_WAIT */ - _("Please wait %d seconds before using the GROUP command again."), - /* NICK_GROUP_CHANGE_DISABLED */ - _("Your nick is already registered; type \002%R%s DROP\002 first."), - /* NICK_GROUP_SAME */ - _("You are already a member of the group of %s."), - /* NICK_GROUP_TOO_MANY */ - _("There are too many nicks in %s's group; list them and drop some.\n" - "Type %R%s HELP GLIST and %R%s HELP DROP\n" - "for more information."), - /* NICK_GROUP_JOINED */ - _("You are now in the group of %s."), - /* NICK_UNGROUP_ONE_NICK */ - _("Your nick is not grouped to anything, you can't ungroup it."), - /* NICK_UNGROUP_NOT_IN_GROUP */ - _("The nick %s is not in your group."), - /* NICK_UNGROUP_SUCCESSFUL */ - _("Nick %s has been ungrouped from %s."), - /* NICK_IDENTIFY_SYNTAX */ - _("IDENTIFY [account] password"), - /* NICK_IDENTIFY_FAILED */ - _("Sorry, identification failed."), - /* NICK_IDENTIFY_SUCCEEDED */ - _("Password accepted - you are now recognized."), - /* NICK_IDENTIFY_EMAIL_REQUIRED */ - _("You must now supply an e-mail for your nick.\n" - "This e-mail will allow you to retrieve your password in\n" - "case you forget it."), - /* NICK_IDENTIFY_EMAIL_HOWTO */ - _("Type %R%S SET EMAIL e-mail in order to set your e-mail.\n" - "Your privacy is respected; this e-mail won't be given to\n" - "any third-party person."), - /* NICK_ALREADY_IDENTIFIED */ - _("You are already identified."), - /* NICK_UPDATE_SUCCESS */ - _("Status updated (memos, vhost, chmodes, flags)."), |
