From 9de990715b25b6b113b9cd270b408145072e059a Mon Sep 17 00:00:00 2001 From: Alexey Sokolov Date: Tue, 3 Apr 2018 22:30:18 +0100 Subject: [PATCH] More translateable strings (fix #1354) --- include/znc/User.h | 3 ++- include/znc/znc.h | 4 +++- src/User.cpp | 22 +++++++++++----------- src/znc.cpp | 22 +++++++++++----------- 4 files changed, 27 insertions(+), 24 deletions(-) diff --git a/include/znc/User.h b/include/znc/User.h index 3d87f38d..0f8eb351 100644 --- a/include/znc/User.h +++ b/include/znc/User.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -34,7 +35,7 @@ class CIRCSock; class CUserTimer; class CServer; -class CUser { +class CUser : private CCoreTranslationMixin { public: CUser(const CString& sUserName); ~CUser(); diff --git a/include/znc/znc.h b/include/znc/znc.h index 97148c6c..ecb2b41a 100644 --- a/include/znc/znc.h +++ b/include/znc/znc.h @@ -35,7 +35,7 @@ class CConfigWriteTimer; class CConfig; class CFile; -class CZNC { +class CZNC : private CCoreTranslationMixin { public: CZNC(); ~CZNC(); @@ -253,6 +253,8 @@ class CZNC { static void DumpConfig(const CConfig* Config); private: + static CString FormatBindError(); + CFile* InitPidFile(); bool ReadConfig(CConfig& config, CString& sError); diff --git a/src/User.cpp b/src/User.cpp index b8cf4615..3a18a5f0 100644 --- a/src/User.cpp +++ b/src/User.cpp @@ -504,11 +504,11 @@ bool CUser::ParseConfig(CConfig* pConfig, CString& sError) { CIRCNetwork* CUser::AddNetwork(const CString& sNetwork, CString& sErrorRet) { if (!CIRCNetwork::IsValidNetwork(sNetwork)) { sErrorRet = - "Invalid network name. It should be alphanumeric. Not to be " - "confused with server name"; + t_s("Invalid network name. It should be alphanumeric. Not to be " + "confused with server name"); return nullptr; } else if (FindNetwork(sNetwork)) { - sErrorRet = "Network [" + sNetwork.Token(0) + "] already exists"; + sErrorRet = t_f("Network {1} already exists")(sNetwork); return nullptr; } @@ -674,8 +674,8 @@ void CUser::UserConnected(CClient* pClient) { BounceAllClients(); } - pClient->PutClient(":irc.znc.in 001 " + pClient->GetNick() + - " :- Welcome to ZNC -"); + pClient->PutClient(":irc.znc.in 001 " + pClient->GetNick() + " :" + + t_s("Welcome to ZNC")); m_vClients.push_back(pClient); } @@ -774,8 +774,8 @@ bool CUser::Clone(const CUser& User, CString& sErrorRet, bool bCloneNetworks) { for (CClient* pSock : m_vClients) { if (!IsHostAllowed(pSock->GetRemoteIP())) { pSock->PutStatusNotice( - "You are being disconnected because your IP is no longer " - "allowed to connect to this user"); + t_s("You are being disconnected because your IP is no longer " + "allowed to connect to this user")); pSock->Close(); } } @@ -904,17 +904,17 @@ bool CUser::IsValid(CString& sErrMsg, bool bSkipPass) const { sErrMsg.clear(); if (!bSkipPass && m_sPass.empty()) { - sErrMsg = "Pass is empty"; + sErrMsg = t_s("Password is empty"); return false; } if (m_sUserName.empty()) { - sErrMsg = "Username is empty"; + sErrMsg = t_s("Username is empty"); return false; } if (!CUser::IsValidUserName(m_sUserName)) { - sErrMsg = "Username is invalid"; + sErrMsg = t_s("Username is invalid"); return false; } @@ -1185,7 +1185,7 @@ bool CUser::LoadModule(const CString& sModName, const CString& sArgs, CModInfo ModInfo; if (!CZNC::Get().GetModules().GetModInfo(ModInfo, sModName, sModRet)) { - sError = "Unable to find modinfo [" + sModName + "] [" + sModRet + "]"; + sError = t_f("Unable to find modinfo {1}: {2}")(sModName, sModRet); return false; } diff --git a/src/znc.cpp b/src/znc.cpp index 8e3ba615..4e7216ee 100644 --- a/src/znc.cpp +++ b/src/znc.cpp @@ -34,12 +34,6 @@ using std::list; using std::tuple; using std::make_tuple; -static inline CString FormatBindError() { - CString sError = (errno == 0 ? CString("unknown error, check the host name") - : CString(strerror(errno))); - return "Unable to bind [" + sError + "]"; -} - CZNC::CZNC() : m_TimeStarted(time(nullptr)), m_eConfigState(ECONFIG_NOTHING), @@ -1566,7 +1560,7 @@ bool CZNC::DeleteUser(const CString& sUsername) { bool CZNC::AddUser(CUser* pUser, CString& sErrorRet, bool bStartup) { if (FindUser(pUser->GetUserName()) != nullptr) { - sErrorRet = "User already exists"; + sErrorRet = t_s("User already exists"); DEBUG("User [" << pUser->GetUserName() << "] - already exists"); return false; } @@ -1674,7 +1668,7 @@ bool CZNC::AddListener(unsigned short uPort, const CString& sBindHost, #ifndef HAVE_IPV6 if (ADDR_IPV6ONLY == eAddr) { - sError = "IPV6 is not enabled"; + sError = t_s("IPv6 is not enabled"); CUtils::PrintStatus(false, sError); return false; } @@ -1682,7 +1676,7 @@ bool CZNC::AddListener(unsigned short uPort, const CString& sBindHost, #ifndef HAVE_LIBSSL if (bSSL) { - sError = "SSL is not enabled"; + sError = t_s("SSL is not enabled"); CUtils::PrintStatus(false, sError); return false; } @@ -1690,7 +1684,7 @@ bool CZNC::AddListener(unsigned short uPort, const CString& sBindHost, CString sPemFile = GetPemLocation(); if (bSSL && !CFile::Exists(sPemFile)) { - sError = "Unable to locate pem file: [" + sPemFile + "]"; + sError = t_f("Unable to locate pem file: {1}")(sPemFile); CUtils::PrintStatus(false, sError); // If stdin is e.g. /dev/null and we call GetBoolInput(), @@ -1709,7 +1703,7 @@ bool CZNC::AddListener(unsigned short uPort, const CString& sBindHost, } #endif if (!uPort) { - sError = "Invalid port"; + sError = t_s("Invalid port"); CUtils::PrintStatus(false, sError); return false; } @@ -1822,6 +1816,12 @@ bool CZNC::DelListener(CListener* pListener) { return false; } +CString CZNC::FormatBindError() { + CString sError = (errno == 0 ? t_s(("unknown error, check the host name")) + : CString(strerror(errno))); + return t_f("Unable to bind: {1}")(sError); +} + static CZNC* s_pZNC = nullptr; void CZNC::CreateInstance() {