Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(i18n): Divide getting and translating Toxme error message
Browse files Browse the repository at this point in the history
  • Loading branch information
Diadlo committed May 10, 2016
1 parent 5cb271b commit 98a1f23
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 11 deletions.
62 changes: 51 additions & 11 deletions src/net/toxme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 QObject::tr("Server doesn't support Toxme");
return "Server doesn't support Toxme";
case -1:
return QObject::tr("You must send POST requests to /api");
return "You must send POST requests to /api";
case -2:
return QObject::tr("Please try again using a HTTPS connection");
return "Problem with HTTPS connection";
case -3:
return QObject::tr("I was unable to read your encrypted payload");
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 -2:
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:
Expand All @@ -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");
}
}
1 change: 1 addition & 0 deletions src/net/toxme.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class Toxme
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;
Expand Down

0 comments on commit 98a1f23

Please sign in to comment.