mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 06:26:18 +00:00
Support markup in TranslateBox.
Server will translate with markup for premium users.
This commit is contained in:
@@ -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());
|
||||
|
Submodule Telegram/lib_ui updated: e053e04607...1b9b173964
Reference in New Issue
Block a user