From 98a1f23bfbbe341c50ed9ee2cc52c1f9dfc15110 Mon Sep 17 00:00:00 2001 From: Diadlo Date: Tue, 10 May 2016 23:28:59 +0300 Subject: [PATCH 1/2] fix(i18n): Divide getting and translating Toxme error message --- src/net/toxme.cpp | 64 ++++++++++++++++++++++++++++++++++++++--------- src/net/toxme.h | 1 + 2 files changed, 53 insertions(+), 12 deletions(-) diff --git a/src/net/toxme.cpp b/src/net/toxme.cpp index 5a91d1e29..ff5ccf914 100644 --- a/src/net/toxme.cpp +++ b/src/net/toxme.cpp @@ -288,21 +288,65 @@ Toxme::ExecCode Toxme::deleteAddress(QString server, ToxId id) return extractError(response); } +/** + * @brief Return string of the corresponding error code + * @param errorCode Code to get error message + * @return Source error message + */ QString Toxme::getErrorMessage(int errorCode) { switch (errorCode) { case IncorrectResponse: - return QObject::tr("Incorrect response"); + return "Incorrect response"; case NoPassword: - return QObject::tr("No password in response"); + return "No password in response"; + case ServerError: + return "Server doesn't support Toxme"; + case -1: + return "You must send POST requests to /api"; + case -2: + return "Problem with HTTPS connection"; + case -3: + return "I was unable to read your encrypted payload"; + case -4: + return "You're making too many requests. Wait an hour and try again"; + case -25: + return "This name is already in use"; + case -26: + return "This Tox ID is already registered under another name"; + case -27: + return "Please don't use a space in your name"; + case -28: + return "Password incorrect"; + case -29: + return "You can't use this name"; + case -30: + return "Name not found"; + case -31: + return "Tox ID not sent"; + case -41: + return "Lookup failed because the server replied with invalid data"; + case -42: + return "That user does not exist"; + case -43: + return "Internal lookup error. Please file a bug"; + default: + return QString("Unknown error (%1)").arg(errorCode); + } +} + +/** + * @brief Return translated error message + * @param errorCode Code to translate + * @return Translated Toxme error message + */ +QString Toxme::translateErrorMessage(int errorCode) +{ + switch (errorCode) { case ServerError: return QObject::tr("Server doesn't support Toxme"); - case -1: - return QObject::tr("You must send POST requests to /api"); case -2: - return QObject::tr("Please try again using a HTTPS connection"); - case -3: - return QObject::tr("I was unable to read your encrypted payload"); + return QObject::tr("Problem with HTTPS connection"); case -4: return QObject::tr("You're making too many requests. Wait an hour and try again"); case -25: @@ -319,13 +363,9 @@ QString Toxme::getErrorMessage(int errorCode) return QObject::tr("Name not found"); case -31: return QObject::tr("Tox ID not sent"); - case -41: - return QObject::tr("Lookup failed because the server replied with invalid data"); case -42: return QObject::tr("That user does not exist"); - case -43: - return QObject::tr("Internal lookup error. Please file a bug"); default: - return QObject::tr("Unknown error (%1)").arg(errorCode); + return QObject::tr("Internal ToxMe error"); } } diff --git a/src/net/toxme.h b/src/net/toxme.h index 4ca630fb3..02da11ca4 100644 --- a/src/net/toxme.h +++ b/src/net/toxme.h @@ -57,6 +57,7 @@ public: static ExecCode deleteAddress(QString server, ToxId id); /// Return string of the corresponding error code static QString getErrorMessage(int errorCode); + static QString translateErrorMessage(int errorCode); private: Toxme()=delete; From d2d5b2306450032ae485909dc0c480d3c02b3596 Mon Sep 17 00:00:00 2001 From: Diadlo Date: Tue, 10 May 2016 23:29:11 +0300 Subject: [PATCH 2/2] feat(profileform): Added log toxme errors --- src/widget/form/profileform.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/widget/form/profileform.cpp b/src/widget/form/profileform.cpp index 18f0824f8..de0e679a0 100644 --- a/src/widget/form/profileform.cpp +++ b/src/widget/form/profileform.cpp @@ -520,7 +520,9 @@ void ProfileForm::onRegisterButtonClicked() break; default: QString errorMessage = Toxme::getErrorMessage(code); - GUI::showWarning(tr("Toxme error"), errorMessage); + qWarning() << errorMessage; + QString translated = Toxme::translateErrorMessage(code); + GUI::showWarning(tr("Toxme error"), translated); } bodyUI->toxmeRegisterButton->setEnabled(true);