Apply auto-translation from French? for test.

This commit is contained in:
John Preston 2025-04-24 14:36:31 +04:00
parent eb81c33308
commit 9583007769
5 changed files with 30 additions and 3 deletions

View file

@ -734,6 +734,13 @@ bool PeerData::canExportChatHistory() const {
return false;
}
bool PeerData::autoTranslation() const {
if (const auto channel = asChannel()) {
return channel->autoTranslation();
}
return false;
}
bool PeerData::setAbout(const QString &newAbout) {
if (_about == newAbout) {
return false;

View file

@ -396,6 +396,7 @@ public:
[[nodiscard]] bool canManageGifts() const;
[[nodiscard]] bool canTransferGifts() const;
[[nodiscard]] bool canExportChatHistory() const;
[[nodiscard]] bool autoTranslation() const;
// Returns true if about text was changed.
bool setAbout(const QString &newAbout);

View file

@ -7557,6 +7557,10 @@ void HistoryWidget::checkLastPinnedClickedIdReset(
void HistoryWidget::setupTranslateBar() {
Expects(_history != nullptr);
if (_history->peer->autoTranslation()) {
_history->translateTo(Core::App().settings().translateTo());
}
_translateBar = std::make_unique<HistoryView::TranslateBar>(
this,
controller(),

View file

@ -372,6 +372,7 @@ void TranslateBar::setup(not_null<History*> history) {
const auto&,
const auto&) {
using Flag = PeerData::TranslationFlag;
//const auto autotranslation = history->peer->autoTranslation();
return (history->peer->translationFlag() != Flag::Enabled)
? rpl::single(QString())
: history->translatedTo()

View file

@ -12,6 +12,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/application.h"
#include "core/core_settings.h"
#include "data/data_changes.h"
#include "data/data_channel.h"
#include "data/data_flags.h"
#include "data/data_peer_values.h" // Data::AmPremiumValue.
#include "data/data_session.h"
#include "history/history.h"
@ -57,10 +59,22 @@ void TranslateTracker::setup() {
Core::App().settings().translateChatEnabledValue(),
_1 && _2);
_trackingLanguage.value(
) | rpl::start_with_next([=](bool tracking) {
const auto channel = peer->asChannel();
auto autoTranslationValue = (channel
? channel->flagsValue()
: rpl::single(Data::Flags<ChannelDataFlags>::Change({}, {}))
) | rpl::map([=](Data::Flags<ChannelDataFlags>::Change data) {
return (data.value & ChannelDataFlag::AutoTranslation);
}) | rpl::distinct_until_changed();
rpl::combine(
_trackingLanguage.value(),
std::move(autoTranslationValue)
) | rpl::start_with_next([=](bool tracking, bool autotranslation) {
_trackingLifetime.destroy();
if (tracking) {
if (autotranslation) {
_history->translateOfferFrom({ QLocale::French });
AssertIsDebug();
} else if (tracking) {
recognizeCollected();
trackSkipLanguages();
} else {