2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 14:38:15 +00:00

Realtime UI translation in Intro.

Also support realtime translation testing by F7-F6-F7-F8 keys.
This commit is contained in:
John Preston
2017-05-30 16:54:05 +03:00
parent d47a38dfcf
commit 5fc4f4ed36
18 changed files with 266 additions and 89 deletions

View File

@@ -43,13 +43,15 @@ PwdCheckWidget::PwdCheckWidget(QWidget *parent, Widget::Data *data) : Step(paren
, _toRecover(this, lang(lng_signin_recover))
, _toPassword(this, lang(lng_signin_try_password))
, _checkRequest(this) {
subscribe(Lang::Current().updated(), [this] { refreshLang(); });
connect(_checkRequest, SIGNAL(timeout()), this, SLOT(onCheckRequest()));
connect(_toRecover, SIGNAL(clicked()), this, SLOT(onToRecover()));
connect(_toPassword, SIGNAL(clicked()), this, SLOT(onToPassword()));
connect(_pwdField, SIGNAL(changed()), this, SLOT(onInputChange()));
connect(_codeField, SIGNAL(changed()), this, SLOT(onInputChange()));
setTitleText(lang(lng_signin_title));
setTitleText([] { return lang(lng_signin_title); });
updateDescriptionText();
setErrorBelowLink(true);
@@ -64,8 +66,20 @@ PwdCheckWidget::PwdCheckWidget(QWidget *parent, Widget::Data *data) : Step(paren
setMouseTracking(true);
}
void PwdCheckWidget::refreshLang() {
if (_pwdField) _pwdField->setPlaceholder(lang(lng_signin_password));
if (_codeField) _codeField->setPlaceholder(lang(lng_signin_code));
if (_toRecover) _toRecover->setText(lang(lng_signin_recover));
if (_toPassword) _toPassword->setText(lang(lng_signin_try_password));
updateControlsGeometry();
}
void PwdCheckWidget::resizeEvent(QResizeEvent *e) {
Step::resizeEvent(e);
updateControlsGeometry();
}
void PwdCheckWidget::updateControlsGeometry() {
_pwdField->moveToLeft(contentLeft(), contentTop() + st::introPasswordTop);
_pwdHint->moveToLeft(contentLeft() + st::buttonRadius, contentTop() + st::introPasswordHintTop);
_codeField->moveToLeft(contentLeft(), contentTop() + st::introStepFieldTop);
@@ -121,7 +135,7 @@ void PwdCheckWidget::pwdSubmitDone(bool recover, const MTPauth_Authorization &re
}
auto &d = result.c_auth_authorization();
if (d.vuser.type() != mtpc_user || !d.vuser.c_user().is_self()) { // wtf?
showError(lang(lng_server_error));
showError([] { return lang(lng_server_error); });
return;
}
finish(d.vuser);
@@ -131,7 +145,7 @@ bool PwdCheckWidget::pwdSubmitFail(const RPCError &error) {
if (MTP::isFloodError(error)) {
_sentRequest = 0;
stopCheck();
showError(lang(lng_flood_error));
showError([] { return lang(lng_flood_error); });
_pwdField->showError();
return true;
}
@@ -141,7 +155,7 @@ bool PwdCheckWidget::pwdSubmitFail(const RPCError &error) {
stopCheck();
auto &err = error.type();
if (err == qstr("PASSWORD_HASH_INVALID")) {
showError(lang(lng_signin_bad_password));
showError([] { return lang(lng_signin_bad_password); });
_pwdField->selectAll();
_pwdField->showError();
return true;
@@ -149,9 +163,10 @@ bool PwdCheckWidget::pwdSubmitFail(const RPCError &error) {
goBack();
}
if (cDebug()) { // internal server error
showError(err + ": " + error.description());
auto text = err + ": " + error.description();
showError([text] { return text; });
} else {
showError(lang(lng_server_error));
showError([] { return lang(lng_server_error); });
}
_pwdField->setFocus();
return false;
@@ -159,7 +174,7 @@ bool PwdCheckWidget::pwdSubmitFail(const RPCError &error) {
bool PwdCheckWidget::codeSubmitFail(const RPCError &error) {
if (MTP::isFloodError(error)) {
showError(lang(lng_flood_error));
showError([] { return lang(lng_flood_error); });
_codeField->showError();
return true;
}
@@ -179,15 +194,16 @@ bool PwdCheckWidget::codeSubmitFail(const RPCError &error) {
onToPassword();
return true;
} else if (err == qstr("CODE_INVALID")) {
showError(lang(lng_signin_wrong_code));
showError([] { return lang(lng_signin_wrong_code); });
_codeField->selectAll();
_codeField->showError();
return true;
}
if (cDebug()) { // internal server error
showError(err + ": " + error.description());
auto text = err + ": " + error.description();
showError([text] { return text; });
} else {
showError(lang(lng_server_error));
showError([] { return lang(lng_server_error); });
}
_codeField->setFocus();
return false;
@@ -253,7 +269,11 @@ void PwdCheckWidget::showReset() {
}
void PwdCheckWidget::updateDescriptionText() {
setDescriptionText(_pwdField->isHidden() ? lng_signin_recover_desc(lt_email, _emailPattern) : lang(lng_signin_desc));
auto pwdHidden = _pwdField->isHidden();
auto emailPattern = _emailPattern;
setDescriptionText([pwdHidden, emailPattern] {
return pwdHidden ? lng_signin_recover_desc(lt_email, emailPattern) : lang(lng_signin_desc);
});
}
void PwdCheckWidget::onInputChange() {