Added translate ability to context menu.

This commit is contained in:
23rd 2022-11-12 14:13:34 +03:00 committed by John Preston
parent 921d2239c7
commit 6db7840fa7
7 changed files with 54 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 604 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

View file

@ -2258,6 +2258,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_context_delete_from_disk" = "Delete from disk";
"lng_context_delete_all_files" = "Delete all files";
"lng_context_save_custom_sound" = "Save for notifications";
"lng_context_translate" = "Translate";
"lng_context_translate_selected" = "Translate Selected Text";
"lng_context_animated_emoji" = "This message contains emoji from **{name} pack**.";
"lng_context_animated_emoji_many#one" = "This message contains emoji from **{count} pack**.";

View file

@ -52,6 +52,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/report_messages_box.h"
#include "boxes/sticker_set_box.h"
#include "boxes/premium_preview_box.h"
#include "boxes/translate_box.h"
#include "chat_helpers/message_field.h"
#include "chat_helpers/emoji_interactions.h"
#include "history/history_widget.h"
@ -2267,6 +2268,13 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
: tr::lng_context_copy_selected(tr::now)),
[=] { copySelectedText(); },
&st::menuIconCopy);
_menu->addAction(tr::lng_context_translate_selected({}), [=] {
_controller->show(Box(
Ui::TranslateBox,
item->history()->peer,
MsgId(),
getSelectedText().rich));
}, &st::menuIconTranslate);
}
addItemActions(item, item);
if (!selectedState.count) {
@ -2358,6 +2366,13 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
[=] { copySelectedText(); },
&st::menuIconCopy);
}
_menu->addAction(tr::lng_context_translate_selected({}), [=] {
_controller->show(Box(
Ui::TranslateBox,
item->history()->peer,
MsgId(),
getSelectedText().rich));
}, &st::menuIconTranslate);
addItemActions(item, item);
} else {
addItemActions(item, albumPartItem);
@ -2415,6 +2430,18 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) {
copyContextText(itemId);
}, &st::menuIconCopy);
}
if (!item->isService()
&& view
&& actionText.isEmpty()
&& (view->hasVisibleText() || mediaHasTextForCopy)) {
_menu->addAction(tr::lng_context_translate(tr::now), [=] {
_controller->show(Box(
Ui::TranslateBox,
item->history()->peer,
item->fullId().msg,
item->originalText()));
}, &st::menuIconTranslate);
}
}
}
if (!actionText.isEmpty() && !hasCopyRestriction(item)) {

View file

@ -41,6 +41,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "boxes/report_messages_box.h"
#include "boxes/sticker_set_box.h"
#include "boxes/stickers_box.h"
#include "boxes/translate_box.h"
#include "data/data_photo.h"
#include "data/data_photo_media.h"
#include "data/data_document.h"
@ -1004,6 +1005,18 @@ base::unique_qptr<Ui::PopupMenu> FillContextMenu(
}
}, &st::menuIconCopy);
}
if (request.overSelection) {
const auto owner = &view->history()->owner();
result->addAction(tr::lng_context_translate_selected(tr::now), [=] {
if (const auto item = owner->message(itemId)) {
list->controller()->show(Box(
Ui::TranslateBox,
item->history()->peer,
MsgId(),
list->getSelectedText().rich));
}
}, &st::menuIconTranslate);
}
AddTopMessageActions(result, request, list);
if (lnkPhoto && request.selectedItems.empty()) {
@ -1038,6 +1051,17 @@ base::unique_qptr<Ui::PopupMenu> FillContextMenu(
}
}, &st::menuIconCopy);
}
if (!link && (view->hasVisibleText() || mediaHasTextForCopy)) {
result->addAction(tr::lng_context_translate(tr::now), [=] {
if (const auto item = owner->message(itemId)) {
list->controller()->show(Box(
Ui::TranslateBox,
item->history()->peer,
item->fullId().msg,
item->originalText()));
}
}, &st::menuIconTranslate);
}
}
if (!view || !list->hasCopyRestriction(view->data())) {

View file

@ -92,6 +92,7 @@ menuIconSearch: icon {{ "menu/search", menuIconColor }};
menuIconStartStream: icon {{ "menu/start_stream", menuIconColor }};
menuIconStartStreamWith: icon {{ "menu/start_stream_with", menuIconColor }};
menuIconVideoChat: icon {{ "menu/video_chat", menuIconColor }};
menuIconTranslate: icon {{ "menu/translate", menuIconColor }};
menuIconTTLAny: icon {{ "menu/auto_delete_plain", menuIconColor }};
menuIconTTLAnyTextPosition: point(11px, 22px);