diff --git a/include/commands.h b/include/commands.h index f35847c3c..eba578bd3 100644 --- a/include/commands.h +++ b/include/commands.h @@ -90,6 +90,11 @@ public: void Reply(int count, const char *singular, const char *plural, ...) ATTR_FORMAT(4, 5); void Reply(const Anope::string &message); + const char *Translate(const char *message); + const char *Translate(const Anope::string &message); + const char *Translate(int count, const char *single, const char *plural); + const char *Translate(int count, const Anope::string &single, const Anope::string &plural); + bool HasCommand(const Anope::string &cmd); bool HasPriv(const Anope::string &cmd); bool IsServicesOper(); diff --git a/modules/botserv/bs_info.cpp b/modules/botserv/bs_info.cpp index 7bfa283bf..0bd67fc49 100644 --- a/modules/botserv/bs_info.cpp +++ b/modules/botserv/bs_info.cpp @@ -58,7 +58,7 @@ public: info[_("Real name")] = bi->realname; info[_("Created")] = Anope::strftime(bi->created, source.GetAccount()); info[_("Options")] = bi->oper_only ? _("Private") : _("None"); - info[_("Used on")] = Anope::Format(Language::Translate(source.nc, bi->GetChannelCount(), N_("%u channel", "%u channels")), bi->GetChannelCount()); + info[_("Used on")] = Anope::Format(source.Translate(bi->GetChannelCount(), N_("%u channel", "%u channels")), bi->GetChannelCount()); FOREACH_MOD(OnBotInfo, (source, bi, ci, info)); info.SendTo(source); @@ -83,8 +83,8 @@ public: source.Reply(CHAN_INFO_HEADER, ci->name.c_str()); info[_("Bot nick")] = ci->bi ? ci->bi->nick : _("not assigned yet"); - Anope::string enabled = Language::Translate(source.nc, _("Enabled")); - Anope::string disabled = Language::Translate(source.nc, _("Disabled")); + Anope::string enabled = source.Translate(_("Enabled")); + Anope::string disabled = source.Translate(_("Disabled")); FOREACH_MOD(OnBotInfo, (source, bi, ci, info)); info.SendTo(source); @@ -120,7 +120,7 @@ public: Anope::string GetDesc(CommandSource &source) const override { - return Anope::Format(Language::Translate(source.GetAccount(), _("Allows you to see %s information about a channel or a bot")), source.service->nick.c_str()); + return Anope::Format(source.Translate(_("Allows you to see %s information about a channel or a bot")), source.service->nick.c_str()); } }; diff --git a/modules/botserv/bs_kick.cpp b/modules/botserv/bs_kick.cpp index db894cbca..5e52d25ae 100644 --- a/modules/botserv/bs_kick.cpp +++ b/modules/botserv/bs_kick.cpp @@ -1151,8 +1151,8 @@ public: if (!ci) return; - Anope::string enabled = Language::Translate(source.nc, _("Enabled")); - Anope::string disabled = Language::Translate(source.nc, _("Disabled")); + Anope::string enabled = source.Translate(_("Enabled")); + Anope::string disabled = source.Translate(_("Disabled")); auto *kd = kickerdata.Get(ci); if (kd && kd->badwords) diff --git a/modules/chanserv/cs_access.cpp b/modules/chanserv/cs_access.cpp index 3e087adf8..fa5de6072 100644 --- a/modules/chanserv/cs_access.cpp +++ b/modules/chanserv/cs_access.cpp @@ -26,10 +26,10 @@ static inline void reset_levels(ChannelInfo *ci) static Anope::string LevelToString(CommandSource &source, int16_t level) { if (level == ACCESS_INVALID) - return Language::Translate(source.GetAccount(), _("(disabled)")); + return source.Translate(_("(disabled)")); if (level == ACCESS_FOUNDER) - return Language::Translate(source.GetAccount(), _("(founder only)")); + return source.Translate(_("(founder only)")); return Anope::ToString(level); } @@ -893,7 +893,7 @@ public: ListFormatter::ListEntry entry; entry["Name"] = p.name; entry["Default"] = LevelToString(source, defaultLevels[p.name]); - entry["Description"] = Language::Translate(source.nc, p.desc.c_str()); + entry["Description"] = source.Translate(p.desc.c_str()); list.AddEntry(entry); } diff --git a/modules/chanserv/cs_flags.cpp b/modules/chanserv/cs_flags.cpp index 10099d7d3..bfea8667f 100644 --- a/modules/chanserv/cs_flags.cpp +++ b/modules/chanserv/cs_flags.cpp @@ -599,7 +599,7 @@ public: Privilege *p = PrivilegeManager::FindPrivilege(priv); if (p == NULL) continue; - source.Reply(" %c - %s", flag, Language::Translate(source.nc, p->desc.c_str())); + source.Reply(" %c - %s", flag, source.Translate(p->desc.c_str())); } return true; diff --git a/modules/chanserv/cs_list.cpp b/modules/chanserv/cs_list.cpp index 07a5e1334..f8d89b5db 100644 --- a/modules/chanserv/cs_list.cpp +++ b/modules/chanserv/cs_list.cpp @@ -122,7 +122,7 @@ public: ListFormatter::ListEntry entry; entry["Name"] = (isnoexpire ? "!" : "") + ci->name; if (ci->HasExt("CS_SUSPENDED")) - entry["Description"] = Language::Translate(source.GetAccount(), _("[Suspended]")); + entry["Description"] = source.Translate(_("[Suspended]")); else entry["Description"] = ci->desc; list.AddEntry(entry); diff --git a/modules/chanserv/cs_mode.cpp b/modules/chanserv/cs_mode.cpp index 574d68317..c84a9d672 100644 --- a/modules/chanserv/cs_mode.cpp +++ b/modules/chanserv/cs_mode.cpp @@ -945,9 +945,9 @@ public: if (!m.second.empty()) { if (m.first) - return Anope::Format(Language::Translate(source.GetAccount(), _("Gives you or the specified nick %s status on a channel")), m.second.c_str()); + return Anope::Format(source.Translate(_("Gives you or the specified nick %s status on a channel")), m.second.c_str()); else - return Anope::Format(Language::Translate(source.GetAccount(), _("Removes %s status from you or the specified nick on a channel")), m.second.c_str()); + return Anope::Format(source.Translate(_("Removes %s status from you or the specified nick on a channel")), m.second.c_str()); } else return ""; diff --git a/modules/chanserv/cs_seen.cpp b/modules/chanserv/cs_seen.cpp index ed53218a4..11e3b08a5 100644 --- a/modules/chanserv/cs_seen.cpp +++ b/modules/chanserv/cs_seen.cpp @@ -281,7 +281,7 @@ public: if (u2) onlinestatus = "."; else - onlinestatus = Anope::Format(Language::Translate(source.nc, _(" but %s mysteriously dematerialized.")), target.c_str()); + onlinestatus = Anope::Format(source.Translate(_(" but %s mysteriously dematerialized.")), target.c_str()); Anope::string timebuf = Anope::Duration(Anope::CurTime - info->last, source.nc); Anope::string timebuf2 = Anope::strftime(info->last, source.nc, true); @@ -295,9 +295,9 @@ public: { u2 = User::Find(info->nick2, true); if (u2) - onlinestatus = Anope::Format(Language::Translate(source.nc, _(". %s is still online.")), u2->nick.c_str()); + onlinestatus = Anope::Format(source.Translate(_(". %s is still online.")), u2->nick.c_str()); else - onlinestatus = Anope::Format(Language::Translate(source.nc, _(", but %s mysteriously dematerialized.")), info->nick2.c_str()); + onlinestatus = Anope::Format(source.Translate(_(", but %s mysteriously dematerialized.")), info->nick2.c_str()); source.Reply(_("%s (%s) was last seen changing nick to %s %s ago%s"), target.c_str(), info->vhost.c_str(), info->nick2.c_str(), timebuf.c_str(), onlinestatus.c_str()); diff --git a/modules/chanserv/cs_set_misc.cpp b/modules/chanserv/cs_set_misc.cpp index 0624ffcbf..7b87322b7 100644 --- a/modules/chanserv/cs_set_misc.cpp +++ b/modules/chanserv/cs_set_misc.cpp @@ -222,7 +222,7 @@ public: { this->SendSyntax(source); source.Reply(" "); - source.Reply("%s", Language::Translate(source.nc, it->second.description.c_str())); + source.Reply("%s", source.Translate(it->second.description.c_str())); return true; } return false; @@ -237,8 +237,8 @@ public: this->ClearSyntax(); this->SetSyntax(Anope::Format( - Language::Translate(source.nc, _("\037channel\037 [\037%s\037]")), - Language::Translate(source.nc, value) + source.Translate(_("\037channel\037 [\037%s\037]")), + source.Translate(value) )); Command::SendSyntax(source); diff --git a/modules/chanserv/cs_xop.cpp b/modules/chanserv/cs_xop.cpp index cd90bf180..ced25485f 100644 --- a/modules/chanserv/cs_xop.cpp +++ b/modules/chanserv/cs_xop.cpp @@ -543,7 +543,7 @@ public: Anope::string GetDesc(CommandSource &source) const override { - return Anope::Format(Language::Translate(source.GetAccount(), _("Modify the list of %s users")), source.command.nobreak().c_str()); + return Anope::Format(source.Translate(_("Modify the list of %s users")), source.command.nobreak().c_str()); } void Execute(CommandSource &source, const std::vector ¶ms) override diff --git a/modules/hostserv/hs_offer.cpp b/modules/hostserv/hs_offer.cpp index 223278e03..6761a174d 100644 --- a/modules/hostserv/hs_offer.cpp +++ b/modules/hostserv/hs_offer.cpp @@ -669,7 +669,7 @@ public: { if (!show_all) return; - mask = Anope::Format(Language::Translate(source.GetAccount(), _("%s [Invalid]")), mask.c_str()); + mask = Anope::Format(source.Translate(_("%s [Invalid]")), mask.c_str()); } ListFormatter::ListEntry entry; @@ -835,7 +835,7 @@ private: { if (!show_all) continue; - mask = Anope::Format(Language::Translate(source.GetAccount(), _("%s [Invalid]")), mask.c_str()); + mask = Anope::Format(source.Translate(_("%s [Invalid]")), mask.c_str()); } ListFormatter::ListEntry entry; diff --git a/modules/hostserv/hs_request.cpp b/modules/hostserv/hs_request.cpp index 09ef6227d..877763aba 100644 --- a/modules/hostserv/hs_request.cpp +++ b/modules/hostserv/hs_request.cpp @@ -401,7 +401,7 @@ public: else message = _("Your requested vhost has been rejected."); - MemoServ::service->Send(source.service->nick, nick, Language::Translate(source.GetAccount(), message.c_str()), true); + MemoServ::service->Send(source.service->nick, nick, source.Translate(message.c_str()), true); } source.Reply(_("VHost for %s has been rejected."), nick.c_str()); diff --git a/modules/nickserv/ns_alist.cpp b/modules/nickserv/ns_alist.cpp index bc334e8bb..6a456db64 100644 --- a/modules/nickserv/ns_alist.cpp +++ b/modules/nickserv/ns_alist.cpp @@ -63,11 +63,11 @@ public: Anope::string privstr; if (ci->GetFounder() == nc) { - privstr = Language::Translate(source.GetAccount(), _("Founder")); + privstr = source.Translate(_("Founder")); } else if (ci->GetSuccessor() == nc) { - privstr += Language::Translate(source.GetAccount(), _("Successor")); + privstr += source.Translate(_("Successor")); } AccessGroup access = ci->AccessFor(nc, false); diff --git a/modules/nickserv/ns_info.cpp b/modules/nickserv/ns_info.cpp index b68331c65..d065934c1 100644 --- a/modules/nickserv/ns_info.cpp +++ b/modules/nickserv/ns_info.cpp @@ -91,7 +91,7 @@ public: InfoFormatter info(source.nc); - info[_("Account")] = Anope::Format(Language::Translate(source.nc, _("%s (ID: %zu)")), na->nc->display.c_str(), na->nc->GetId()); + info[_("Account")] = Anope::Format(source.Translate(_("%s (ID: %zu)")), na->nc->display.c_str(), na->nc->GetId()); info[_("Account registered")] = Anope::strftime(na->nc->registered, source.GetAccount()); info[_("Nick registered")] = Anope::strftime(na->registered, source.GetAccount()); diff --git a/modules/nickserv/ns_list.cpp b/modules/nickserv/ns_list.cpp index 246c1ff62..0d298306a 100644 --- a/modules/nickserv/ns_list.cpp +++ b/modules/nickserv/ns_list.cpp @@ -110,9 +110,9 @@ public: auto &status = entry["Status"]; if (na->nc->HasExt("NS_SUSPENDED")) - status = Language::Translate(source.GetAccount(), _("Suspended")); + status = source.Translate(_("Suspended")); else if (na->nc->HasExt("UNCONFIRMED")) - status = Language::Translate(source.GetAccount(), _("Unconfirmed")); + status = source.Translate(_("Unconfirmed")); list.AddEntry(entry); } ++count; diff --git a/modules/nickserv/ns_set_misc.cpp b/modules/nickserv/ns_set_misc.cpp index 45144b4ba..35bb83d0e 100644 --- a/modules/nickserv/ns_set_misc.cpp +++ b/modules/nickserv/ns_set_misc.cpp @@ -253,7 +253,7 @@ public: this->SendSyntax(source); source.Reply(" "); - source.Reply("%s", Language::Translate(source.nc, desc.c_str())); + source.Reply("%s", source.Translate(desc.c_str())); return true; } @@ -265,7 +265,7 @@ public: value = it->second.syntax.c_str(); this->ClearSyntax(); - this->SetSyntax(Anope::Format("[\037%s\037]", Language::Translate(source.nc, value))); + this->SetSyntax(Anope::Format("[\037%s\037]", source.Translate(value))); Command::SendSyntax(source); } @@ -294,8 +294,8 @@ public: this->ClearSyntax(); this->SetSyntax(Anope::Format( - Language::Translate(source.nc, _("\037nickname\037 [\037%s\037]")), - Language::Translate(source.nc, value) + source.Translate(_("\037nickname\037 [\037%s\037]")), + source.Translate(value) )); Command::SendSyntax(source); diff --git a/modules/operserv/os_dns.cpp b/modules/operserv/os_dns.cpp index cf9cc6ad6..f3e8ff042 100644 --- a/modules/operserv/os_dns.cpp +++ b/modules/operserv/os_dns.cpp @@ -253,7 +253,7 @@ class CommandOSDNS final ListFormatter::ListEntry entry; entry["Server"] = s->GetName(); - entry["Limit"] = s->GetLimit() ? Anope::ToString(s->GetLimit()) : Language::Translate(source.GetAccount(), _("None")); + entry["Limit"] = s->GetLimit() ? Anope::ToString(s->GetLimit()) : source.Translate(_("None")); Anope::string ip_str; for (const auto &ip : s->GetIPs()) @@ -264,14 +264,14 @@ class CommandOSDNS final entry["IP"] = ip_str; if (s->Active()) - entry["State"] = Language::Translate(source.GetAccount(), _("Pooled/Active")); + entry["State"] = source.Translate(_("Pooled/Active")); else if (s->Pooled()) - entry["State"] = Language::Translate(source.GetAccount(), _("Pooled/Not Active")); + entry["State"] = source.Translate(_("Pooled/Not Active")); else - entry["State"] = Language::Translate(source.GetAccount(), _("Unpooled")); + entry["State"] = source.Translate(_("Unpooled")); if (!srv) - entry["State"] += Anope::string(" ") + Language::Translate(source.GetAccount(), _("(Split)")); + entry["State"] += Anope::string(" ") + source.Translate(_("(Split)")); lf.AddEntry(entry); } diff --git a/modules/operserv/os_login.cpp b/modules/operserv/os_login.cpp index 9376c3964..fb1142eed 100644 --- a/modules/operserv/os_login.cpp +++ b/modules/operserv/os_login.cpp @@ -77,7 +77,7 @@ public: Anope::string GetDesc(CommandSource &source) const override { - return Anope::Format(Language::Translate(source.GetAccount(), _("Login to %s")), source.service->nick.c_str()); + return Anope::Format(source.Translate(_("Login to %s")), source.service->nick.c_str()); } }; @@ -123,7 +123,7 @@ public: Anope::string GetDesc(CommandSource &source) const override { - return Anope::Format(Language::Translate(source.GetAccount(), _("Logout from %s")), source.service->nick.c_str()); + return Anope::Format(source.Translate(_("Logout from %s")), source.service->nick.c_str()); } }; diff --git a/modules/operserv/os_sxline.cpp b/modules/operserv/os_sxline.cpp index e1d50a04b..2cfed9eeb 100644 --- a/modules/operserv/os_sxline.cpp +++ b/modules/operserv/os_sxline.cpp @@ -247,7 +247,7 @@ public: Anope::string GetDesc(CommandSource &source) const override { - return Anope::Format(Language::Translate(source.GetAccount(), _("Manipulate the %s list")), source.command.nobreak().c_str()); + return Anope::Format(source.Translate(_("Manipulate the %s list")), source.command.nobreak().c_str()); } void Execute(CommandSource &source, const std::vector ¶ms) override diff --git a/src/command.cpp b/src/command.cpp index 51127c85e..79e6a70e8 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -112,7 +112,7 @@ bool CommandSource::IsOper() void CommandSource::Reply(const char *message, ...) { - const char *translated_message = Language::Translate(this->nc, message); + const char *translated_message = Translate(message); Anope::string buf; ANOPE_FORMAT(message, translated_message, buf); @@ -121,7 +121,7 @@ void CommandSource::Reply(const char *message, ...) void CommandSource::Reply(int count, const char *single, const char *plural, ...) { - const char *translated_message = Language::Translate(this->nc, count, single, plural); + const char *translated_message = Translate(count, single, plural); Anope::string buf; ANOPE_FORMAT(plural, translated_message, buf); @@ -130,10 +130,30 @@ void CommandSource::Reply(int count, const char *single, const char *plural, ... void CommandSource::Reply(const Anope::string &message) { - const char *translated_message = Language::Translate(this->nc, message.c_str()); + const char *translated_message = Translate(message.c_str()); this->reply->SendMessage(*this, translated_message); } +const char *CommandSource::Translate(const char *message) +{ + return Language::Translate(GetAccount(), message); +} + +const char *CommandSource::Translate(const Anope::string &message) +{ + return Language::Translate(GetAccount(), message.c_str()); +} + +const char *CommandSource::Translate(int count, const Anope::string &single, const Anope::string &plural) +{ + return Language::Translate(GetAccount(), count, single.c_str(), plural.c_str()); +} + +const char *CommandSource::Translate(int count, const char *single, const char *plural) +{ + return Language::Translate(GetAccount(), count, single, plural); +} + Command::Command(Module *o, const Anope::string &sname, size_t minparams, size_t maxparams) : Service(o, "Command", sname), max_params(maxparams), min_params(minparams), module(o) { } @@ -160,7 +180,7 @@ void Command::SendSyntax(CommandSource &source) const auto *monospace = !flexible && sourcenc && sourcenc->HasExt("NS_MONOSPACE") ? "\021" : ""; auto first = true; - Anope::string prefix = Language::Translate(source.GetAccount(), _("Syntax")); + Anope::string prefix = source.Translate(_("Syntax")); Anope::string padding(prefix.utf8length(), ' '); for (const auto &[syntax, predicate] : this->syntax) { @@ -171,14 +191,12 @@ void Command::SendSyntax(CommandSource &source) { first = false; source.Reply("%s%s: \002%s %s\002", monospace, prefix.c_str(), - source.command.nobreak().c_str(), - Language::Translate(source.GetAccount(), syntax.c_str())); + source.command.nobreak().c_str(), source.Translate(syntax)); } else { source.Reply("%s%s \002%s %s\002", monospace, padding.c_str(), - source.command.nobreak().c_str(), - Language::Translate(source.GetAccount(), syntax.c_str())); + source.command.nobreak().c_str(), source.Translate(syntax)); } } diff --git a/src/misc.cpp b/src/misc.cpp index 80c09bdad..5335a88b2 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -340,8 +340,8 @@ void ExampleWrapper::SendTo(CommandSource &source) header = false; } - const auto *trans_example = Language::Translate(source.nc, entry.example.c_str()); - const auto *trans_description = Language::Translate(source.nc, entry.description.c_str()); + const auto *trans_example = source.Translate(entry.example); + const auto *trans_description = source.Translate(entry.description); if (flexible) { source.Reply("\002%s%s%s\002: %s", source.command.c_str(), *trans_example ? " " : "", @@ -381,7 +381,7 @@ void HelpWrapper::SendTo(CommandSource &source) for (const auto &[entry_name, entry_desc] : entries) { - const auto *trans_desc = Language::Translate(source.nc, entry_desc.c_str()); + const auto *trans_desc = source.Translate(entry_desc); if (flexible) { source.Reply("\002%s\002: %s", entry_name.c_str(), trans_desc);