class CChan;
// !Forward Declarations
-class CAuthBase {
+class CAuthBase : private CCoreTranslationMixin {
public:
CAuthBase(const CString& sUsername, const CString& sPassword,
CZNCSock* pSock)
class CIRCNetworkJoinTimer;
class CMessage;
-class CIRCNetwork {
+class CIRCNetwork : private CCoreTranslationMixin {
public:
static bool IsValidNetwork(const CString& sNetwork);
}
/** A helper class for handling commands in modules. */
-class CModCommand {
+class CModCommand : private CCoreTranslationMixin {
public:
/// Type for the callback function that handles the actual command.
typedef void (CModule::*ModCmdFunc)(const CString& sLine);
std::map<CString, CModCommand> m_mCommands;
};
-class CModules : public std::vector<CModule*> {
+class CModules : public std::vector<CModule*>, private CCoreTranslationMixin {
public:
CModules();
~CModules();
} \
} \
} else { \
- PutStatus("No such module [" + MOD + "]"); \
+ PutStatus(t_f("No such module {1}")(MOD)); \
} \
}
// login. Use sReason because there are other reasons than "wrong
// password" for a login to be rejected (e.g. fail2ban).
if (pUser) {
- pUser->PutStatusNotice("A client from [" + GetRemoteIP() + "] attempted "
- "to login as you, but was rejected [" +
- sReason + "].");
+ pUser->PutStatusNotice(t_f(
+ "A client from {1} attempted to login as you, but was rejected: "
+ "{2}")(GetRemoteIP(), sReason));
}
GLOBALMODULECALL(OnFailedLogin(GetUsername(), GetRemoteIP()), NOTHING);
if (!m_sNetwork.empty()) {
m_pNetwork = m_pUser->FindNetwork(m_sNetwork);
if (!m_pNetwork) {
- PutStatus("Network (" + m_sNetwork + ") doesn't exist.");
+ PutStatus(t_f("Network {1} doesn't exist.")(m_sNetwork));
}
} else if (!m_pUser->GetNetworks().empty()) {
// If a user didn't supply a network, and they have a network called
if (!m_pNetwork) m_pNetwork = *m_pUser->GetNetworks().begin();
if (m_pNetwork && m_pUser->GetNetworks().size() > 1) {
PutStatusNotice(
- "You have several networks configured, but no network was "
- "specified for the connection.");
- PutStatusNotice("Selecting network [" + m_pNetwork->GetName() +
- "]. To see list of all configured networks, use "
- "/znc ListNetworks");
+ t_s("You have several networks configured, but no network was "
+ "specified for the connection."));
PutStatusNotice(
+ t_f("Selecting network {1}. To see list of all configured "
+ "networks, use /znc ListNetworks")(m_pNetwork->GetName()));
+ PutStatusNotice(t_f(
"If you want to choose another network, use /znc JumpNetwork "
- "<network>, or connect to ZNC with username " +
- m_pUser->GetUserName() + "/<network> (instead of just " +
- m_pUser->GetUserName() + ")");
+ "<network>, or connect to ZNC with username {1}/<network> "
+ "(instead of just {1})")(m_pUser->GetUserName()));
}
} else {
PutStatusNotice(
- "You have no networks configured. Use /znc AddNetwork <network> to "
- "add one.");
+ t_s("You have no networks configured. Use /znc AddNetwork "
+ "<network> to add one."));
}
SetNetwork(m_pNetwork, false);
NETWORKMODULECALL(OnClientLogin(), m_pUser, m_pNetwork, this, NOTHING);
}
-void CClient::Timeout() { PutClient("ERROR :Closing link [Timeout]"); }
+void CClient::Timeout() { PutClient("ERROR :" + t_s("Closing link: Timeout")); }
void CClient::Connected() { DEBUG(GetSockName() << " == Connected();"); }
void CClient::ReachedMaxBuffer() {
DEBUG(GetSockName() << " == ReachedMaxBuffer()");
if (IsAttached()) {
- PutClient("ERROR :Closing link [Too long raw line]");
+ PutClient("ERROR :" + t_s("Closing link: Too long raw line"));
}
Close();
}
void CClient::BouncedOff() {
PutStatusNotice(
- "You are being disconnected because another user just authenticated as "
- "you.");
+ t_s("You are being disconnected because another user just "
+ "authenticated as you."));
Close(Csock::CLT_AFTERWRITE);
}
if (!GetIRCSock()) {
// Some lagmeters do a NOTICE to their own nick, ignore those.
if (!sTarget.Equals(m_sNick))
- PutStatus("Your CTCP to [" + Message.GetTarget() +
- "] got lost, "
- "you are not connected to IRC!");
+ PutStatus(t_f(
+ "Your CTCP to {1} got lost, you are not connected to IRC!")(
+ Message.GetTarget()));
continue;
}
if (!GetIRCSock()) {
// Some lagmeters do a NOTICE to their own nick, ignore those.
if (!sTarget.Equals(m_sNick))
- PutStatus("Your notice to [" + Message.GetTarget() +
- "] got lost, "
- "you are not connected to IRC!");
+ PutStatus(
+ t_f("Your notice to {1} got lost, you are not connected to "
+ "IRC!")(Message.GetTarget()));
continue;
}
CChan* pChan = m_pNetwork ? m_pNetwork->FindChan(sChan) : nullptr;
if (pChan && !pChan->IsOn()) {
- PutStatusNotice("Removing channel [" + sChan + "]");
+ PutStatusNotice(t_f("Removing channel {1}")(sChan));
m_pNetwork->DelChan(sChan);
} else {
sChans += (sChans.empty()) ? sChan : CString("," + sChan);
if (!GetIRCSock()) {
// Some lagmeters do a PRIVMSG to their own nick, ignore those.
if (!sTarget.Equals(m_sNick))
- PutStatus("Your message to [" + Message.GetTarget() +
- "] got lost, "
- "you are not connected to IRC!");
+ PutStatus(
+ t_f("Your message to {1} got lost, you are not connected "
+ "to IRC!")(Message.GetTarget()));
continue;
}
if (sTarget.Equals("status")) {
if (sModCommand.empty())
- PutStatus("Hello. How may I help you?");
+ PutStatus(t_s("Hello. How may I help you?"));
else
UserCommand(sModCommand);
} else {
if (sModCommand.empty())
CALLMOD(sTarget, this, m_pUser, m_pNetwork,
- PutModule("Hello. How may I help you?"))
+ PutModule(t_s("Hello. How may I help you?")))
else
CALLMOD(sTarget, this, m_pUser, m_pNetwork,
OnModCommand(sModCommand))
CString sPatterns = Message.GetParams(0);
if (sPatterns.empty()) {
- PutStatusNotice("Usage: /attach <#chans>");
+ PutStatusNotice(t_s("Usage: /attach <#chans>"));
return true;
}
set<CChan*> sChans = MatchChans(sPatterns);
unsigned int uAttachedChans = AttachChans(sChans);
- PutStatusNotice("There were [" + CString(sChans.size()) +
- "] channels matching [" + sPatterns + "]");
- PutStatusNotice("Attached [" + CString(uAttachedChans) + "] channels");
+ PutStatusNotice(t_p("There was {1} channel matching [{2}]",
+ "There were {1} channels matching [{2}]",
+ sChans.size())(sChans.size(), sPatterns));
+ PutStatusNotice(t_p("Attached {1} channel", "Attached {1} channels",
+ uAttachedChans)(uAttachedChans));
return true;
} else if (sCommand.Equals("DETACH")) {
CString sPatterns = Message.GetParams(0);
if (sPatterns.empty()) {
- PutStatusNotice("Usage: /detach <#chans>");
+ PutStatusNotice(t_s("Usage: /detach <#chans>"));
return true;
}
set<CChan*> sChans = MatchChans(sPatterns);
unsigned int uDetached = DetachChans(sChans);
- PutStatusNotice("There were [" + CString(sChans.size()) +
- "] channels matching [" + sPatterns + "]");
- PutStatusNotice("Detached [" + CString(uDetached) + "] channels");
+ PutStatusNotice(t_p("There was {1} channel matching [{2}]",
+ "There were {1} channels matching [{2}]",
+ sChans.size())(sChans.size(), sPatterns));
+ PutStatusNotice(t_p("Detached {1} channel", "Detached {1} channels",
+ uDetached)(uDetached));
return true;
} else if (sCommand.Equals("PROTOCTL")) {
if (pSock) {
PutStatus(
- "Jumping servers because this server is no longer in the list");
+ t_s("Jumping servers because this server is no longer in the "
+ "list"));
pSock->Quit();
}
}
}
if (!bFound) {
sNotice =
- "Loading network module [simple_away] instead";
+ "NOTICE: awaynick was retired, loading network "
+ "module [simple_away] instead; if you still need "
+ "awaynick, install it as an external module";
sModName = "simple_away";
// not a fatal error if simple_away is not available
LoadModule(sModName, sArgs, sNotice, sModRet);
if (m_RawBuffer.IsEmpty()) {
pClient->PutClient(":irc.znc.in 001 " + pClient->GetNick() +
- " :- Welcome to ZNC -");
+ " :" + t_s("Welcome to ZNC"));
} else {
const CString& sClientNick = pClient->GetNick(false);
MCString msParams;
// Tell them why they won't connect
if (!GetIRCConnectEnabled())
pClient->PutStatus(
- "You are currently disconnected from IRC. "
- "Use 'connect' to reconnect.");
+ t_s("You are currently disconnected from IRC. Use 'connect' to "
+ "reconnect."));
if (CDebug::Debug()) {
- pClient->PutStatus("ZNC is presently running in DEBUG mode. Sensitive"
- " data during your current session may be exposed to the host.");
+ pClient->PutStatus(
+ t_s("ZNC is presently running in DEBUG mode. Sensitive data during "
+ "your current session may be exposed to the host."));
}
}
void CIRCNetwork::SetUser(CUser* pUser) {
for (CClient* pClient : m_vClients) {
pClient->PutStatus(
- "This network is being deleted or moved to another user.");
+ t_s("This network is being deleted or moved to another user."));
pClient->SetNetwork(nullptr);
}
if (m_pUser->JoinTries() != 0 &&
pChan->GetJoinTries() >= m_pUser->JoinTries()) {
- PutStatus("The channel " + pChan->GetName() +
- " could not be joined, disabling it.");
+ PutStatus(t_f("The channel {1} could not be joined, disabling it.")(
+ pChan->GetName()));
pChan->Disable();
} else {
pChan->IncJoinTries();
if (pIRCSock) {
pIRCSock->Quit();
- PutStatus("Your current server was removed, jumping...");
+ PutStatus(t_s("Your current server was removed, jumping..."));
}
} else if (!bSawCurrentServer) {
// Our current server comes after the server which we
bool bSSL = pServer->IsSSL();
#ifndef HAVE_LIBSSL
if (bSSL) {
- PutStatus("Cannot connect to [" + pServer->GetString(false) +
- "], ZNC is not compiled with SSL.");
+ PutStatus(
+ t_f("Cannot connect to {1}, because ZNC is not compiled with SSL "
+ "support.")(pServer->GetString(false)));
CZNC::Get().AddNetworkToQueue(this);
return false;
}
&bAbort);
if (bAbort) {
DEBUG("Some module aborted the connection attempt");
- PutStatus("Some module aborted the connection attempt");
+ PutStatus(t_s("Some module aborted the connection attempt"));
delete pIRCSock;
CZNC::Get().AddNetworkToQueue(this);
return false;
bool CIRCSock::OnErrorMessage(CMessage& Message) {
// ERROR :Closing Link: nick[24.24.24.24] (Excess Flood)
CString sError = Message.GetParam(0);
- m_pNetwork->PutStatus("Error from Server [" + sError + "]");
+ m_pNetwork->PutStatus(t_f("Error from server: {1}")(sError));
return true;
}
if (m_bAuthed && sServer == "irc.znc.in") {
// m_bAuthed == true => we already received another 001 => we
// might be in a traffic loop
- m_pNetwork->PutStatus(
- "ZNC seems to be connected to itself, disconnecting...");
+ m_pNetwork->PutStatus(t_s(
+ "ZNC seems to be connected to itself, disconnecting..."));
Quit();
return true;
}
CString sPort = Message.GetParam(2);
CString sInfo = Message.GetParam(3);
m_pNetwork->PutStatus(
- "Server [" + m_pNetwork->GetCurrentServer()->GetString(false) +
- "] redirects us to [" + sHost + ":" + sPort +
- "] with reason [" + sInfo + "]");
+ t_f("Server {1} redirects us to {2}:{3} with reason: {3}")(
+ m_pNetwork->GetCurrentServer()->GetString(false), sHost,
+ sPort, sInfo));
m_pNetwork->PutStatus(
- "Perhaps you want to add it as a new server.");
+ t_s("Perhaps you want to add it as a new server."));
// Don't send server redirects to the client
return true;
}
}
if (pChan) {
pChan->Disable();
- m_pNetwork->PutStatus("Channel [" + pChan->GetName() +
- "] is linked to "
- "another channel and was thus disabled.");
+ m_pNetwork->PutStatus(
+ t_f("Channel {1} is linked to another channel and was thus "
+ "disabled.")(pChan->GetName()));
}
break;
}
// TLS
if (!GetSSL()) {
StartTLS();
- m_pNetwork->PutStatus("Switched to SSL (STARTTLS)");
+ m_pNetwork->PutStatus(t_s("Switched to SSL (STARTTLS)"));
}
return true;
bool bIsVisible = false;
if (Nick.NickEquals(GetNick())) {
- m_pNetwork->PutStatus("You quit [" + Message.GetReason() + "]");
+ m_pNetwork->PutStatus(t_f("You quit: {1}")(Message.GetReason()));
// We don't call module hooks and we don't
// forward this quit to clients (Some clients
// disconnect if they receive such a QUIT)
if (!m_pNetwork->GetUser()->IsBeingDeleted() &&
m_pNetwork->GetIRCConnectEnabled() &&
m_pNetwork->GetServers().size() != 0) {
- m_pNetwork->PutStatus("Disconnected from IRC. Reconnecting...");
+ m_pNetwork->PutStatus(t_s("Disconnected from IRC. Reconnecting..."));
}
m_pNetwork->ClearRawBuffer();
m_pNetwork->ClearMotdBuffer();
DEBUG(GetSockName() << " == SockError(" << iErrno << " " << sError << ")");
if (!m_pNetwork->GetUser()->IsBeingDeleted()) {
if (GetConState() != CST_OK) {
- m_pNetwork->PutStatus("Cannot connect to IRC (" + sError +
- "). Retrying...");
+ m_pNetwork->PutStatus(
+ t_f("Cannot connect to IRC ({1}). Retrying...")(sError));
} else {
- m_pNetwork->PutStatus("Disconnected from IRC (" + sError +
- "). Reconnecting...");
+ m_pNetwork->PutStatus(
+ t_f("Disconnected from IRC ({1}). Reconnecting...")(sError));
}
#ifdef HAVE_LIBSSL
if (iErrno == errnoBadSSLCert) {
CString sSHA256 = GetSSLPeerFingerprint();
m_pNetwork->PutStatus("SHA-256: " + sSHA256);
m_pNetwork->PutStatus(
- "If you trust this certificate, do /znc "
- "AddTrustedServerFingerprint " +
- sSHA256);
+ t_f("If you trust this certificate, do /znc "
+ "AddTrustedServerFingerprint {1}")(sSHA256));
}
}
#endif
void CIRCSock::Timeout() {
DEBUG(GetSockName() << " == Timeout()");
if (!m_pNetwork->GetUser()->IsBeingDeleted()) {
- m_pNetwork->PutStatus("IRC connection timed out. Reconnecting...");
+ m_pNetwork->PutStatus(
+ t_s("IRC connection timed out. Reconnecting..."));
}
m_pNetwork->ClearRawBuffer();
m_pNetwork->ClearMotdBuffer();
void CIRCSock::ConnectionRefused() {
DEBUG(GetSockName() << " == ConnectionRefused()");
if (!m_pNetwork->GetUser()->IsBeingDeleted()) {
- m_pNetwork->PutStatus("Connection Refused. Reconnecting...");
+ m_pNetwork->PutStatus(t_s("Connection Refused. Reconnecting..."));
}
m_pNetwork->ClearRawBuffer();
m_pNetwork->ClearMotdBuffer();
void CIRCSock::ReachedMaxBuffer() {
DEBUG(GetSockName() << " == ReachedMaxBuffer()");
- m_pNetwork->PutStatus("Received a too long line from the IRC server!");
+ m_pNetwork->PutStatus(t_s("Received a too long line from the IRC server!"));
Quit();
}
} else {
char cLetter = 0;
if (sBadNick.empty()) {
- m_pNetwork->PutUser("No free nick available");
+ m_pNetwork->PutUser(t_s("No free nick available"));
Quit();
return;
}
cLetter = sBadNick.back();
if (cLetter == 'z') {
- m_pNetwork->PutUser("No free nick found");
+ m_pNetwork->PutUser(t_s("No free nick found"));
Quit();
return;
}
}
void CModule::AddHelpCommand() {
- AddCommand("Help", &CModule::HandleHelpCommand, "search",
- "Generate this output");
+ AddCommand("Help", t_d("<search>", "modhelpcmd"),
+ t_d("Generate this output", "modhelpcmd"),
+ [=](const CString& sLine) { HandleHelpCommand(sLine); });
}
bool CModule::RemCommand(const CString& sCmd) {
}
}
if (Table.empty()) {
- PutModule("No matches for '" + sFilter + "'");
+ PutModule(t_f("No matches for '{1}'")(sFilter));
} else {
PutModule(Table);
}
// This function is only called if OnModCommand wasn't
// overriden, so no false warnings for modules which don't use
// CModCommand for command handling.
- PutModule("This module doesn't implement any commands.");
+ PutModule(t_s("This module doesn't implement any commands."));
else
- PutModule("Unknown command!");
+ PutModule(t_s("Unknown command!"));
}
void CModule::OnQuit(const CNick& Nick, const CString& sMessage,
sRetMsg = "";
if (FindModule(sModule) != nullptr) {
- sRetMsg = "Module [" + sModule + "] already loaded.";
+ sRetMsg = t_f("Module {1} already loaded.")(sModule);
return false;
}
CModInfo Info;
if (!FindModPath(sModule, sModPath, sDataPath)) {
- sRetMsg = "Unable to find module [" + sModule + "]";
+ sRetMsg = t_f("Unable to find module {1}")(sModule);
return false;
}
Info.SetName(sModule);
if (!Info.SupportsType(eType)) {
dlclose(p);
- sRetMsg = "Module [" + sModule + "] does not support module type [" +
- CModInfo::ModuleTypeToString(eType) + "].";
+ sRetMsg = t_f("Module {1} does not support module type {1}.")(
+ sModule, CModInfo::ModuleTypeToString(eType));
return false;
}
if (!pUser && eType == CModInfo::UserModule) {
dlclose(p);
- sRetMsg = "Module [" + sModule + "] requires a user.";
+ sRetMsg = t_f("Module {1} requires a user.")(sModule);
return false;
}
if (!pNetwork && eType == CModInfo::NetworkModule) {
dlclose(p);
- sRetMsg = "Module [" + sModule + "] requires a network.";
+ sRetMsg = t_f("Module {1} requires a network.")(sModule);
return false;
}
bLoaded = pModule->OnLoad(sArgs, sRetMsg);
} catch (const CModule::EModException&) {
bLoaded = false;
- sRetMsg = "Caught an exception";
+ sRetMsg = t_s("Caught an exception");
}
if (!bLoaded) {
UnloadModule(sModule, sModPath);
if (!sRetMsg.empty())
- sRetMsg = "Module [" + sModule + "] aborted: " + sRetMsg;
+ sRetMsg = t_f("Module {1} aborted: {2}")(sModule, sRetMsg);
else
- sRetMsg = "Module [" + sModule + "] aborted.";
+ sRetMsg = t_f("Module {1} aborted.")(sModule);
return false;
}
sRetMsg = "";
if (!pModule) {
- sRetMsg = "Module [" + sMod + "] not loaded.";
+ sRetMsg = t_f("Module [{1}] not loaded.")(sMod);
return false;
}
}
dlclose(p);
- sRetMsg = "Module [" + sMod + "] unloaded";
+ sRetMsg = t_f("Module {1} unloaded.")(sMod);
return true;
}
- sRetMsg = "Unable to unload module [" + sMod + "]";
+ sRetMsg = t_f("Unable to unload module {1}.")(sMod);
return false;
}
CModule* pModule = FindModule(sMod);
if (!pModule) {
- sRetMsg = "Module [" + sMod + "] not loaded";
+ sRetMsg = t_f("Module [{1}] not loaded.")(sMod);
return false;
}
return false;
}
- sRetMsg = "Reloaded module [" + sMod + "]";
+ sRetMsg = t_f("Reloaded module {1}.")(sMod);
return true;
}
if (bHandled) return bSuccess;
if (!FindModPath(sModule, sModPath, sTmp)) {
- sRetMsg = "Unable to find module [" + sModule + "]";
+ sRetMsg = t_f("Unable to find module {1}.")(sModule);
return false;
}
((sModule[a] < 'a') || (sModule[a] > 'z')) &&
((sModule[a] < 'A') || (sModule[a] > 'Z')) && (sModule[a] != '_')) {
sRetMsg =
- "Module names can only contain letters, numbers and "
- "underscores, [" +
- sModule + "] is invalid.";
+ t_f("Module names can only contain letters, numbers and "
+ "underscores, [{1}] is invalid")(sModule);
return nullptr;
}
}
// dlerror() returns pointer to static buffer, which may be overwritten
// very soon with another dl call also it may just return null.
const char* cDlError = dlerror();
- CString sDlError = cDlError ? cDlError : "Unknown error";
- sRetMsg = "Unable to open module [" + sModule + "] [" + sDlError + "]";
+ CString sDlError = cDlError ? cDlError : t_s("Unknown error");
+ sRetMsg = t_f("Unable to open module {1}: {2}")(sModule, sDlError);
return nullptr;
}
*reinterpret_cast<void**>(&fpZNCModuleEntry) = dlsym(p, "ZNCModuleEntry");
if (!fpZNCModuleEntry) {
dlclose(p);
- sRetMsg = "Could not find ZNCModuleEntry in module [" + sModule + "]";
+ sRetMsg = t_f("Could not find ZNCModuleEntry in module {1}")(sModule);
return nullptr;
}
const CModuleEntry* pModuleEntry = fpZNCModuleEntry();
if (std::strcmp(pModuleEntry->pcVersion, VERSION_STR) ||
std::strcmp(pModuleEntry->pcVersionExtra, VERSION_EXTRA)) {
- sRetMsg = "Version mismatch for module [" + sModule +
- "] (core is " VERSION_STR VERSION_EXTRA
- ", module is built for " +
- CString(pModuleEntry->pcVersion) +
- pModuleEntry->pcVersionExtra + "), recompile this module.";
+ sRetMsg = t_f(
+ "Version mismatch for module {1}: core is {2}, module is built for "
+ "{3}. Recompile this module.")(
+ sModule, VERSION_STR VERSION_EXTRA,
+ CString(pModuleEntry->pcVersion) + pModuleEntry->pcVersionExtra);
dlclose(p);
return nullptr;
}
if (std::strcmp(pModuleEntry->pcCompileOptions,
ZNC_COMPILE_OPTIONS_STRING)) {
- sRetMsg =
- "Module [" + sModule +
- "] is built incompatibly (core is '" ZNC_COMPILE_OPTIONS_STRING
- "', module is '" +
- CString(pModuleEntry->pcCompileOptions) +
- "'), recompile this module.";
+ sRetMsg = t_f(
+ "Module {1} is built incompatibly: core is '{2}', module is '{3}'. "
+ "Recompile this module.")(sModule, ZNC_COMPILE_OPTIONS_STRING,
+ pModuleEntry->pcCompileOptions);
dlclose(p);
return nullptr;
}
: m_sCmd(sCmd), m_pFunc(std::move(func)), m_Args(Args), m_Desc(Desc) {}
void CModCommand::InitHelp(CTable& Table) {
- Table.AddColumn("Command");
- Table.AddColumn("Description");
+ Table.AddColumn(t_s("Command", "modhelpcmd"));
+ Table.AddColumn(t_s("Description", "modhelpcmd"));
}
void CModCommand::AddHelp(CTable& Table) const {
Table.AddRow();
- Table.SetCell("Command", GetCommand() + " " + GetArgs());
- Table.SetCell("Description", GetDescription());
+ Table.SetCell(t_s("Command", "modhelpcmd"), GetCommand() + " " + GetArgs());
+ Table.SetCell(t_s("Description", "modhelpcmd"), GetDescription());
}
CString CModule::t_s(const CString& sEnglish, const CString& sContext) const {