translation of all project, and new translation mechanism
This commit is contained in:
+18
-17
@@ -1,4 +1,5 @@
|
||||
#include "authservice.h"
|
||||
#include "localization.h"
|
||||
|
||||
#include <QCryptographicHash>
|
||||
#include <QDir>
|
||||
@@ -30,7 +31,7 @@ QString describeElyError(const QJsonObject &response, int status)
|
||||
const QString error = response.value(QStringLiteral("error")).toString();
|
||||
if (!error.isEmpty())
|
||||
return error;
|
||||
return QObject::tr("Сервер авторизации вернул код %1").arg(status);
|
||||
return Loc::text("auth.error.serverCode").arg(status);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
@@ -45,7 +46,7 @@ AuthResult AuthService::offline(const QString &nickname)
|
||||
{
|
||||
AuthResult result;
|
||||
if (nickname.isEmpty()) {
|
||||
result.error = tr("Для офлайн-запуска нужен никнейм");
|
||||
result.error = Loc::text("auth.offline.error.noNickname");
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -102,7 +103,7 @@ void AuthService::loginElyBy(const QString &login,
|
||||
{
|
||||
if (login.isEmpty()) {
|
||||
AuthResult result;
|
||||
result.error = tr("Укажите логин Ely.by в настройках профиля");
|
||||
result.error = Loc::text("auth.ely.error.noLogin");
|
||||
callback(result);
|
||||
return;
|
||||
}
|
||||
@@ -115,14 +116,14 @@ void AuthService::loginElyBy(const QString &login,
|
||||
return;
|
||||
}
|
||||
|
||||
emit progress(tr("Проверка сохранённого токена Ely.by…"));
|
||||
emit progress(Loc::text("auth.ely.progress.checkingToken"));
|
||||
postJson(QStringLiteral("/auth/validate"),
|
||||
{{QStringLiteral("accessToken"), accessToken}},
|
||||
[this, login, password, token, accessToken, callback](
|
||||
int status, const QJsonObject &, const QString &transportError) {
|
||||
if (!transportError.isEmpty()) {
|
||||
AuthResult result;
|
||||
result.error = tr("Нет связи с authserver.ely.by: %1").arg(transportError);
|
||||
result.error = Loc::text("auth.ely.error.unreachable").arg(transportError);
|
||||
callback(result);
|
||||
return;
|
||||
}
|
||||
@@ -138,7 +139,7 @@ void AuthService::loginElyBy(const QString &login,
|
||||
}
|
||||
|
||||
// Токен протух — пробуем продлить его, не спрашивая пароль.
|
||||
emit progress(tr("Обновление токена Ely.by…"));
|
||||
emit progress(Loc::text("auth.ely.progress.refreshingToken"));
|
||||
postJson(QStringLiteral("/auth/refresh"),
|
||||
{{QStringLiteral("accessToken"), accessToken},
|
||||
{QStringLiteral("clientToken"), token},
|
||||
@@ -183,12 +184,12 @@ void AuthService::authenticate(const QString &login,
|
||||
{
|
||||
if (password.isEmpty()) {
|
||||
AuthResult result;
|
||||
result.error = tr("Укажите пароль Ely.by в настройках профиля");
|
||||
result.error = Loc::text("auth.ely.error.noPassword");
|
||||
callback(result);
|
||||
return;
|
||||
}
|
||||
|
||||
emit progress(tr("Авторизация на Ely.by…"));
|
||||
emit progress(Loc::text("auth.ely.progress.signingIn"));
|
||||
postJson(QStringLiteral("/auth/authenticate"),
|
||||
{{QStringLiteral("username"), login},
|
||||
{QStringLiteral("password"), password},
|
||||
@@ -199,7 +200,7 @@ void AuthService::authenticate(const QString &login,
|
||||
result.clientToken = clientToken;
|
||||
|
||||
if (!transportError.isEmpty()) {
|
||||
result.error = AuthService::tr("Нет связи с authserver.ely.by: %1").arg(transportError);
|
||||
result.error = Loc::text("auth.ely.error.unreachable").arg(transportError);
|
||||
callback(result);
|
||||
return;
|
||||
}
|
||||
@@ -210,7 +211,7 @@ void AuthService::authenticate(const QString &login,
|
||||
result.twoFactorRequired = message.contains(QStringLiteral("two factor"),
|
||||
Qt::CaseInsensitive);
|
||||
result.error = result.twoFactorRequired
|
||||
? AuthService::tr("Аккаунт защищён двухфакторной аутентификацией")
|
||||
? Loc::text("auth.ely.error.twoFactor")
|
||||
: message;
|
||||
callback(result);
|
||||
return;
|
||||
@@ -223,7 +224,7 @@ void AuthService::authenticate(const QString &login,
|
||||
result.userType = QStringLiteral("ELYBY");
|
||||
result.ok = !result.accessToken.isEmpty() && !result.playerName.isEmpty();
|
||||
if (!result.ok)
|
||||
result.error = AuthService::tr("Ely.by не вернул игровой профиль для этого аккаунта");
|
||||
result.error = Loc::text("auth.ely.error.noGameProfile");
|
||||
callback(result);
|
||||
});
|
||||
}
|
||||
@@ -239,7 +240,7 @@ void AuthService::ensureAuthlibInjector(
|
||||
return;
|
||||
}
|
||||
|
||||
emit progress(tr("Загрузка authlib-injector…"));
|
||||
emit progress(Loc::text("auth.ely.progress.downloadingInjector"));
|
||||
QNetworkRequest manifestRequest{QUrl(kInjectorManifest)};
|
||||
manifestRequest.setAttribute(QNetworkRequest::RedirectPolicyAttribute,
|
||||
QNetworkRequest::NoLessSafeRedirectPolicy);
|
||||
@@ -248,7 +249,7 @@ void AuthService::ensureAuthlibInjector(
|
||||
connect(manifestReply, &QNetworkReply::finished, this, [this, manifestReply, jarPath, callback]() {
|
||||
manifestReply->deleteLater();
|
||||
if (manifestReply->error() != QNetworkReply::NoError) {
|
||||
callback({}, tr("Не удалось получить сведения об authlib-injector: %1")
|
||||
callback({}, Loc::text("auth.ely.error.injectorInfoFailed")
|
||||
.arg(manifestReply->errorString()));
|
||||
return;
|
||||
}
|
||||
@@ -260,7 +261,7 @@ void AuthService::ensureAuthlibInjector(
|
||||
.value(QStringLiteral("sha256"))
|
||||
.toString();
|
||||
if (url.isEmpty()) {
|
||||
callback({}, tr("В манифесте authlib-injector нет ссылки на файл"));
|
||||
callback({}, Loc::text("auth.ely.error.injectorNoUrl"));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -271,7 +272,7 @@ void AuthService::ensureAuthlibInjector(
|
||||
connect(jarReply, &QNetworkReply::finished, this, [jarReply, jarPath, expectedSha256, callback]() {
|
||||
jarReply->deleteLater();
|
||||
if (jarReply->error() != QNetworkReply::NoError) {
|
||||
callback({}, AuthService::tr("Не удалось скачать authlib-injector: %1").arg(jarReply->errorString()));
|
||||
callback({}, Loc::text("auth.ely.error.injectorDownloadFailed").arg(jarReply->errorString()));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -280,14 +281,14 @@ void AuthService::ensureAuthlibInjector(
|
||||
const QString actual = QString::fromLatin1(
|
||||
QCryptographicHash::hash(payload, QCryptographicHash::Sha256).toHex());
|
||||
if (actual != expectedSha256) {
|
||||
callback({}, AuthService::tr("Контрольная сумма authlib-injector не совпала"));
|
||||
callback({}, Loc::text("auth.ely.error.injectorChecksum"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
QFile file(jarPath);
|
||||
if (!file.open(QIODevice::WriteOnly) || file.write(payload) != payload.size()) {
|
||||
callback({}, AuthService::tr("Не удалось сохранить %1").arg(QDir::toNativeSeparators(jarPath)));
|
||||
callback({}, Loc::text("common.error.saveFailed").arg(QDir::toNativeSeparators(jarPath)));
|
||||
return;
|
||||
}
|
||||
file.close();
|
||||
|
||||
Reference in New Issue
Block a user