mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-16 14:17:12 +02:00
Support markup in TranslateBox.
Server will translate with markup for premium users.
This commit is contained in:
parent
663e89662b
commit
2f1c674401
2 changed files with 28 additions and 14 deletions
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "boxes/translate_box.h"
|
||||
|
||||
#include "api/api_text_entities.h" // Api::EntitiesToMTP / EntitiesFromMTP.
|
||||
#include "core/application.h"
|
||||
#include "core/core_settings.h"
|
||||
#include "core/ui_integration.h"
|
||||
|
@ -22,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/boxes/choose_language_box.h"
|
||||
#include "ui/effects/loading_element.h"
|
||||
#include "ui/layers/generic_box.h"
|
||||
#include "ui/text/text_utilities.h"
|
||||
#include "ui/toasts/common_toasts.h"
|
||||
#include "ui/painter.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
|
@ -111,12 +113,6 @@ void TranslateBox(
|
|||
const auto state = box->lifetime().make_state<State>(&peer->session());
|
||||
state->to = ChooseTranslateTo(peer->owner().history(peer));
|
||||
|
||||
text.entities = ranges::views::all(
|
||||
text.entities
|
||||
) | ranges::views::filter([](const EntityInText &e) {
|
||||
return e.type() != EntityType::Spoiler;
|
||||
}) | ranges::to<EntitiesInText>();
|
||||
|
||||
if (!IsServerMsgId(msgId)) {
|
||||
msgId = 0;
|
||||
}
|
||||
|
@ -212,8 +208,14 @@ void TranslateBox(
|
|||
return id.locale().textDirection() == Qt::RightToLeft;
|
||||
}))));
|
||||
|
||||
const auto showText = [=](const QString &text) {
|
||||
translated->entity()->setText(text);
|
||||
const auto showText = [=](TextWithEntities text) {
|
||||
const auto label = translated->entity();
|
||||
label->setMarkedText(
|
||||
text,
|
||||
Core::MarkedTextContext{
|
||||
.session = &peer->session(),
|
||||
.customEmojiRepaint = [=] { label->update(); },
|
||||
});
|
||||
translated->show(anim::type::instant);
|
||||
loading->hide(anim::type::instant);
|
||||
};
|
||||
|
@ -231,16 +233,28 @@ void TranslateBox(
|
|||
? MTPVector<MTPTextWithEntities>()
|
||||
: MTP_vector<MTPTextWithEntities>(1, MTP_textWithEntities(
|
||||
MTP_string(text.text),
|
||||
MTP_vector<MTPMessageEntity>()))),
|
||||
Api::EntitiesToMTP(
|
||||
&peer->session(),
|
||||
text.entities,
|
||||
Api::ConvertOption::SkipLocal)))),
|
||||
MTP_string(to.twoLetterCode())
|
||||
)).done([=](const MTPmessages_TranslatedText &result) {
|
||||
const auto &data = result.data();
|
||||
const auto &list = data.vresult().v;
|
||||
showText(list.isEmpty()
|
||||
? tr::lng_translate_box_error(tr::now)
|
||||
: qs(list.front().data().vtext()));
|
||||
if (list.isEmpty()) {
|
||||
showText(
|
||||
Ui::Text::Italic(tr::lng_translate_box_error(tr::now)));
|
||||
} else {
|
||||
showText(TextWithEntities{
|
||||
.text = qs(list.front().data().vtext()),
|
||||
.entities = Api::EntitiesFromMTP(
|
||||
&peer->session(),
|
||||
list.front().data().ventities().v),
|
||||
});
|
||||
}
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
showText(tr::lng_translate_box_error(tr::now));
|
||||
showText(
|
||||
Ui::Text::Italic(tr::lng_translate_box_error(tr::now)));
|
||||
}).send();
|
||||
};
|
||||
state->to.value() | rpl::start_with_next(send, box->lifetime());
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit e053e04607653c8a304c72ff901a8e628dd94dbf
|
||||
Subproject commit 1b9b1739649ddf942937a6b9a1a22933070e5ecc
|
Loading…
Add table
Reference in a new issue