From 39f9fee22f197e0cb6a0e7e985ba08b519e722fa Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Tue, 29 Nov 2022 14:57:45 +0300 Subject: [PATCH] Added ability to translate peer description. --- .../info/profile/info_profile_actions.cpp | 39 ++++++++++++++++++- Telegram/lib_ui | 2 +- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp index 1c4b278e6..35f69c44c 100644 --- a/Telegram/SourceFiles/info/profile/info_profile_actions.cpp +++ b/Telegram/SourceFiles/info/profile/info_profile_actions.cpp @@ -38,6 +38,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "boxes/peers/add_bot_to_chat_box.h" #include "boxes/peers/edit_contact_box.h" #include "boxes/report_messages_box.h" +#include "boxes/translate_box.h" #include "lang/lang_keys.h" #include "menu/menu_mute.h" #include "history/history.h" @@ -61,6 +62,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "facades.h" #include "styles/style_info.h" #include "styles/style_boxes.h" +#include "styles/style_menu_icons.h" #include #include @@ -313,6 +315,34 @@ object_ptr DetailsFiller::setupInfo() { return true; }; + const auto addTranslateToMenu = [&, + peer = _peer.get(), + controller = _controller->parentController()]( + not_null label, + rpl::producer &&text) { + struct State { + rpl::variable labelText; + }; + const auto state = label->lifetime().make_state(); + state->labelText = std::move(text); + label->setContextMenuHook([=]( + Ui::FlatLabel::ContextMenuRequest request) { + label->fillContextMenu(request); + if (Ui::SkipTranslate(state->labelText.current())) { + return; + } + auto item = tr::lng_context_translate(tr::now); + request.menu->addAction(std::move(item), [=] { + controller->window().show(Box( + Ui::TranslateBox, + peer, + MsgId(), + state->labelText.current(), + false)); + }); + }); + }; + const auto addInfoLineGeneric = [&]( v::text::data &&label, rpl::producer &&text, @@ -369,7 +399,9 @@ object_ptr DetailsFiller::setupInfo() { auto label = user->isBot() ? tr::lng_info_about_label() : tr::lng_info_bio_label(); - addInfoLine(std::move(label), AboutValue(user)); + addTranslateToMenu( + addInfoLine(std::move(label), AboutValue(user)).text, + AboutValue(user)); const auto usernameLine = addInfoOneLine( UsernamesSubtext(_peer, tr::lng_info_username_label()), @@ -494,9 +526,12 @@ object_ptr DetailsFiller::setupInfo() { ).text->setLinksTrusted(); } - addInfoLine( + const auto about = addInfoLine( tr::lng_info_about_label(), _topic ? rpl::single(TextWithEntities()) : AboutValue(_peer)); + if (!_topic) { + addTranslateToMenu(about.text, AboutValue(_peer)); + } } if (!_peer->isSelf()) { // No notifications toggle for Self => no separator. diff --git a/Telegram/lib_ui b/Telegram/lib_ui index c197c1831..6c345d207 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit c197c1831d1af48cf769f271a126af2c2eaf8185 +Subproject commit 6c345d2076e0b1997ef64b13f617bf5afbaf396b