1
0
mirror of https://github.com/anope/anope.git synced 2026-06-12 15:44:46 +02:00

Add some helper methods to CommandSource for translation.

This commit is contained in:
Sadie Powell
2026-04-26 18:07:56 +01:00
parent 7eb710a009
commit e2dc77641a
21 changed files with 74 additions and 51 deletions
+5
View File
@@ -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();
+4 -4
View File
@@ -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());
}
};
+2 -2
View File
@@ -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)
+3 -3
View File
@@ -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);
}
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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);
+2 -2
View File
@@ -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 "";
+3 -3
View File
@@ -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());
+3 -3
View File
@@ -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);
+1 -1
View File
@@ -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<Anope::string> &params) override
+2 -2
View File
@@ -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;
+1 -1
View File
@@ -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());
+2 -2
View File
@@ -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);
+1 -1
View File
@@ -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());
+2 -2
View File
@@ -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;
+4 -4
View File
@@ -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);
+5 -5
View File
@@ -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);
}
+2 -2
View File
@@ -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());
}
};
+1 -1
View File
@@ -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<Anope::string> &params) override
+26 -8
View File
@@ -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));
}
}
+3 -3
View File
@@ -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);