From 615d4f6b5eb78c170a0eb72f138b8d1f88682b02 Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Sun, 22 Oct 2017 00:24:37 +0100 Subject: [PATCH] Improve cyrusauth UI, make more strings translatable (#1354) --- modules/clientnotify.cpp | 77 ++++++++++++++++++++-------------------- modules/ctcpflood.cpp | 44 +++++++++++------------ modules/cyrusauth.cpp | 69 ++++++++++++++++++----------------- 3 files changed, 94 insertions(+), 96 deletions(-) diff --git a/modules/clientnotify.cpp b/modules/clientnotify.cpp index 7dacc553..aa9d34d9 100644 --- a/modules/clientnotify.cpp +++ b/modules/clientnotify.cpp @@ -44,20 +44,18 @@ class CClientNotifyMod : public CModule { public: MODCONSTRUCTOR(CClientNotifyMod) { AddHelpCommand(); - AddCommand("Method", static_cast( - &CClientNotifyMod::OnMethodCommand), - "", "Sets the notify method"); - AddCommand("NewOnly", static_cast( - &CClientNotifyMod::OnNewOnlyCommand), - "", - "Turns notifications for unseen IP addresses on or off"); - AddCommand("OnDisconnect", static_cast( - &CClientNotifyMod::OnDisconnectCommand), - "", - "Turns notifications for clients disconnecting on or off"); - AddCommand("Show", static_cast( - &CClientNotifyMod::OnShowCommand), - "", "Show the current settings"); + AddCommand("Method", t_d(""), + t_d("Sets the notify method"), + [=](const CString& sLine) { OnMethodCommand(sLine); }); + AddCommand("NewOnly", t_d(""), + t_d("Turns notifications for unseen IP addresses on or off"), + [=](const CString& sLine) { OnNewOnlyCommand(sLine); }); + AddCommand( + "OnDisconnect", t_d(""), + t_d("Turns notifications for clients disconnecting on or off"), + [=](const CString& sLine) { OnDisconnectCommand(sLine); }); + AddCommand("Show", "", t_d("Shows the current settings"), + [=](const CString& sLine) { OnShowCommand(sLine); }); } bool OnLoad(const CString& sArgs, CString& sMessage) override { @@ -80,10 +78,12 @@ class CClientNotifyMod : public CModule { CString sRemoteIP = GetClient()->GetRemoteIP(); if (!m_bNewOnly || m_sClientsSeen.find(sRemoteIP) == m_sClientsSeen.end()) { - SendNotification( - "Another client authenticated as your user. " - "Use the 'ListClients' command to see all " + - CString(GetUser()->GetAllClients().size()) + " clients."); + SendNotification(t_p("", + "Another client authenticated as your user. " + "Use the 'ListClients' command to see all {1} " + "clients.", + GetUser()->GetAllClients().size())( + GetUser()->GetAllClients().size())); // the set<> will automatically disregard duplicates: m_sClientsSeen.insert(sRemoteIP); @@ -92,58 +92,59 @@ class CClientNotifyMod : public CModule { void OnClientDisconnect() override { if (m_bOnDisconnect) { - SendNotification( - "A client disconnected from your user. " - "Use the 'ListClients' command to see the " + - CString(GetUser()->GetAllClients().size()) + - " remaining client(s)."); + SendNotification(t_p("", + "A client disconnected from your user. Use " + "the 'ListClients' command to see the {1} " + "remaining clients.", + GetUser()->GetAllClients().size())( + GetUser()->GetAllClients().size())); } } void OnMethodCommand(const CString& sCommand) { - const CString& sArg = sCommand.Token(1, true).AsLower(); + const CString sArg = sCommand.Token(1, true).AsLower(); if (sArg != "notice" && sArg != "message" && sArg != "off") { - PutModule("Usage: Method "); + PutModule(t_s("Usage: Method ")); return; } m_sMethod = sArg; SaveSettings(); - PutModule("Saved."); + PutModule(t_s("Saved.")); } void OnNewOnlyCommand(const CString& sCommand) { - const CString& sArg = sCommand.Token(1, true).AsLower(); + const CString sArg = sCommand.Token(1, true).AsLower(); if (sArg.empty()) { - PutModule("Usage: NewOnly "); + PutModule(t_s("Usage: NewOnly ")); return; } m_bNewOnly = sArg.ToBool(); SaveSettings(); - PutModule("Saved."); + PutModule(t_s("Saved.")); } void OnDisconnectCommand(const CString& sCommand) { - const CString& sArg = sCommand.Token(1, true).AsLower(); + const CString sArg = sCommand.Token(1, true).AsLower(); if (sArg.empty()) { - PutModule("Usage: OnDisconnect "); + PutModule(t_s("Usage: OnDisconnect ")); return; } m_bOnDisconnect = sArg.ToBool(); SaveSettings(); - PutModule("Saved."); + PutModule(t_s("Saved.")); } void OnShowCommand(const CString& sLine) { - PutModule("Current settings: Method: " + m_sMethod + - ", for unseen IP addresses only: " + CString(m_bNewOnly) + - ", notify on disconnecting clients: " + - CString(m_bOnDisconnect)); + PutModule( + t_f("Current settings: Method: {1}, for unseen IP addresses only: " + "{2}, notify on disconnecting clients: {3}")( + m_sMethod, m_bNewOnly, m_bOnDisconnect)); } }; @@ -153,5 +154,5 @@ void TModInfo(CModInfo& Info) { } USERMODULEDEFS(CClientNotifyMod, - "Notifies you when another IRC client logs into or out of your " - "account. Configurable.") + t_s("Notifies you when another IRC client logs into or out of " + "your account. Configurable.")) diff --git a/modules/ctcpflood.cpp b/modules/ctcpflood.cpp index fecb9e7a..f9affc31 100644 --- a/modules/ctcpflood.cpp +++ b/modules/ctcpflood.cpp @@ -22,15 +22,12 @@ class CCtcpFloodMod : public CModule { public: MODCONSTRUCTOR(CCtcpFloodMod) { AddHelpCommand(); - AddCommand("Secs", static_cast( - &CCtcpFloodMod::OnSecsCommand), - "", "Set seconds limit"); - AddCommand("Lines", static_cast( - &CCtcpFloodMod::OnLinesCommand), - "", "Set lines limit"); - AddCommand("Show", static_cast( - &CCtcpFloodMod::OnShowCommand), - "", "Show the current limits"); + AddCommand("Secs", t_d(""), t_d("Set seconds limit"), + [=](const CString& sLine) { OnSecsCommand(sLine); }); + AddCommand("Lines", t_d(""), t_d("Set lines limit"), + [=](const CString& sLine) { OnLinesCommand(sLine); }); + AddCommand("Show", "", t_d("Show the current limits"), + [=](const CString& sLine) { OnShowCommand(sLine); }); } ~CCtcpFloodMod() override {} @@ -76,8 +73,8 @@ class CCtcpFloodMod : public CModule { if (m_iNumCTCP < m_iThresholdMsgs) return CONTINUE; else if (m_iNumCTCP == m_iThresholdMsgs) - PutModule("Limit reached by [" + Nick.GetHostMask() + - "], blocking all CTCP"); + PutModule(t_f("Limit reached by {1}, blocking all CTCP")( + Nick.GetHostMask())); // Reset the timeout so that we continue blocking messages m_tLastCTCP = time(nullptr); @@ -98,14 +95,14 @@ class CCtcpFloodMod : public CModule { const CString& sArg = sCommand.Token(1, true); if (sArg.empty()) { - PutModule("Usage: Secs "); + PutModule(t_s("Usage: Secs ")); return; } m_iThresholdSecs = sArg.ToUInt(); if (m_iThresholdSecs == 0) m_iThresholdSecs = 1; - PutModule("Set seconds limit to [" + CString(m_iThresholdSecs) + "]"); + OnShowCommand(""); Save(); } @@ -113,22 +110,23 @@ class CCtcpFloodMod : public CModule { const CString& sArg = sCommand.Token(1, true); if (sArg.empty()) { - PutModule("Usage: Lines "); + PutModule(t_s("Usage: Lines ")); return; } m_iThresholdMsgs = sArg.ToUInt(); if (m_iThresholdMsgs == 0) m_iThresholdMsgs = 2; - PutModule("Set lines limit to [" + CString(m_iThresholdMsgs) + "]"); + OnShowCommand(""); Save(); } void OnShowCommand(const CString& sCommand) { - PutModule("Current limit is " + CString(m_iThresholdMsgs) + - " CTCPs " - "in " + - CString(m_iThresholdSecs) + " secs"); + CString sMsgs = t_p("1 CTCP message", "{1} CTCP messages", + m_iThresholdMsgs)(m_iThresholdMsgs); + CString sSecs = t_p("every second", "every {1} seconds", + m_iThresholdSecs)(m_iThresholdSecs); + PutModule(t_f("Current limit is {1} {2}")(sMsgs, sSecs)); } private: @@ -143,11 +141,11 @@ template <> void TModInfo(CModInfo& Info) { Info.SetWikiPage("ctcpflood"); Info.SetHasArgs(true); - Info.SetArgsHelpText( + Info.SetArgsHelpText(Info.t_s( "This user module takes none to two arguments. The first argument is " "the number of lines after which the flood-protection is triggered. " - "The second argument is the time (s) to in which the number of lines " - "is reached. The default setting is 4 CTCPs in 2 seconds"); + "The second argument is the time (sec) to in which the number of lines " + "is reached. The default setting is 4 CTCPs in 2 seconds")); } -USERMODULEDEFS(CCtcpFloodMod, "Don't forward CTCP floods to clients") +USERMODULEDEFS(CCtcpFloodMod, t_s("Don't forward CTCP floods to clients")) diff --git a/modules/cyrusauth.cpp b/modules/cyrusauth.cpp index 636835bf..36eb18bc 100644 --- a/modules/cyrusauth.cpp +++ b/modules/cyrusauth.cpp @@ -39,15 +39,12 @@ class CSASLAuthMod : public CModule { m_cbs[1].context = nullptr; AddHelpCommand(); - AddCommand("CreateUser", t_d("[yes|no]"), - t_d("Create ZNC user upon first successful login"), - [=](const CString& sLine) { CreateUserCommand(sLine); }); - AddCommand("CloneUser", t_d("[username]"), - t_d("User to be used as the template for new users"), - [=](const CString& sLine) { CloneUserCommand(sLine); }); - AddCommand("DisableCloneUser", - static_cast( - &CSASLAuthMod::DisableCloneUserCommand)); + AddCommand("Show", "", t_d("Shows current settings"), + [=](const CString& sLine) { ShowCommand(sLine); }); + AddCommand("CreateUsers", t_d("yes|clone |no"), + t_d("Create ZNC users upon first successful login, " + "optionally from a template"), + [=](const CString& sLine) { CreateUsersCommand(sLine); }); } ~CSASLAuthMod() override { sasl_done(); } @@ -169,37 +166,39 @@ class CSASLAuthMod : public CModule { const CString& GetMethod() const { return m_sMethod; } - void CreateUserCommand(const CString& sLine) { - CString sCreate = sLine.Token(1); - - if (!sCreate.empty()) { - SetNV("CreateUser", sCreate); - } - - if (CreateUser()) { - PutModule(t_s("We will create users on their first login")); - } else { + void ShowCommand(const CString& sLine) { + if (!CreateUser()) { PutModule(t_s("We will not create users on their first login")); - } - } - - void CloneUserCommand(const CString& sLine) { - CString sUsername = sLine.Token(1); - - if (!sUsername.empty()) { - SetNV("CloneUser", sUsername); - } - - if (ShouldCloneUser()) { - PutModule(t_f("We will clone {1}")(CloneUser())); + } else if (ShouldCloneUser()) { + PutModule( + t_f("We will create users on their first login, using user " + "[{1}] as a template")(CloneUser())); } else { - PutModule(t_s("We will not clone a user")); + PutModule(t_s("We will create users on their first login")); } } - void DisableCloneUserCommand(const CString& sLine) { - DelNV("CloneUser"); - PutModule(t_s("Clone user disabled")); + void CreateUsersCommand(const CString& sLine) { + CString sCreate = sLine.Token(1); + if (sCreate == "no") { + DelNV("CloneUser"); + SetNV("CreateUser", CString(false)); + PutModule(t_s("We will not create users on their first login")); + } else if (sCreate == "yes") { + DelNV("CloneUser"); + SetNV("CreateUser", CString(true)); + PutModule(t_s("We will create users on their first login")); + } else if (sCreate == "clone" && !sLine.Token(2).empty()) { + SetNV("CloneUser", sLine.Token(2)); + SetNV("CreateUser", CString(true)); + PutModule( + t_f("We will create users on their first login, using user " + "[{1}] as a template")(sLine.Token(2))); + } else { + PutModule( + t_s("Usage: CreateUsers yes, CreateUsers no, or CreateUsers " + "clone ")); + } } bool CreateUser() const { return GetNV("CreateUser").ToBool(); }