diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index ee568a35ef..cdef1a3b23 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -6777,6 +6777,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_translate_settings_subtitle" = "Translate Messages"; "lng_translate_settings_show" = "Show Translate Button"; +"lng_translate_settings_use_platform_mac" = "Use Apple Translations"; +"lng_translate_settings_use_platform_mac_about" = "Translation on macOS won't work until you download local language packs in System Settings."; "lng_translate_settings_chat" = "Translate Entire Chats"; "lng_translate_settings_choose" = "Do Not Translate"; "lng_translate_settings_about" = "The 'Translate' button will appear in the context menu of messages containing text."; diff --git a/Telegram/SourceFiles/boxes/language_box.cpp b/Telegram/SourceFiles/boxes/language_box.cpp index c55423eca5..1a3e9935b8 100644 --- a/Telegram/SourceFiles/boxes/language_box.cpp +++ b/Telegram/SourceFiles/boxes/language_box.cpp @@ -35,8 +35,10 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "mainwidget.h" #include "mainwindow.h" #include "core/application.h" +#include "base/platform/base_platform_info.h" #include "lang/lang_instance.h" #include "lang/lang_cloud_manager.h" +#include "platform/platform_translate_provider.h" #include "settings/settings_common.h" #include "spellcheck/spellcheck_types.h" #include "window/window_controller.h" @@ -1217,6 +1219,36 @@ void LanguageBox::setupTop(not_null container) { Core::App().saveSettingsDelayed(); }, translateEnabled->lifetime()); + if (Platform::IsMac() && Platform::IsTranslateProviderAvailable()) { + const auto platformTranslateWrap = container->add( + object_ptr>( + container, + object_ptr(container))); + platformTranslateWrap->toggle( + translateEnabled->toggled(), + anim::type::instant); + platformTranslateWrap->toggleOn(translateEnabled->toggledValue()); + const auto platformTranslateEnabled = platformTranslateWrap->entity()->add( + object_ptr( + platformTranslateWrap->entity(), + tr::lng_translate_settings_use_platform_mac(), + st::settingsButtonNoIcon))->toggleOn( + rpl::single( + Core::App().settings().usePlatformTranslation())); + platformTranslateEnabled->toggledValue( + ) | rpl::filter([](bool checked) { + return (checked + != Core::App().settings().usePlatformTranslation()); + }) | rpl::on_next([=](bool checked) { + Core::App().settings().setUsePlatformTranslation(checked); + Core::App().saveSettingsDelayed(); + }, platformTranslateEnabled->lifetime()); + Ui::AddSkip(platformTranslateWrap->entity()); + Ui::AddDividerText( + platformTranslateWrap->entity(), + tr::lng_translate_settings_use_platform_mac_about()); + } + using namespace rpl::mappers; auto premium = Data::AmPremiumValue(&_controller->session()); const auto translateChat = container->add(object_ptr( diff --git a/Telegram/SourceFiles/core/core_settings.cpp b/Telegram/SourceFiles/core/core_settings.cpp index 6e4b91d035..000ef24776 100644 --- a/Telegram/SourceFiles/core/core_settings.cpp +++ b/Telegram/SourceFiles/core/core_settings.cpp @@ -246,7 +246,7 @@ QByteArray Settings::serialize() const { + sizeof(ushort) + sizeof(qint32) // _notificationsDisplayChecksum + Serialize::bytearraySize(callPanelPosition) - + sizeof(qint32) * 2; // _cornerReply + _systemAccentColorEnabled + + sizeof(qint32) * 3; // _cornerReply + _systemAccentColorEnabled + _usePlatformTranslation auto result = QByteArray(); result.reserve(size); @@ -413,7 +413,8 @@ QByteArray Settings::serialize() const { << _notificationsDisplayChecksum << callPanelPosition << qint32(_cornerReply.current() ? 1 : 0) - << qint32(_systemAccentColorEnabled ? 1 : 0); + << qint32(_systemAccentColorEnabled ? 1 : 0) + << qint32(_usePlatformTranslation ? 1 : 0); } Ensures(result.size() == size); @@ -550,6 +551,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) { qint32 systemAccentColorEnabled = _systemAccentColorEnabled ? 1 : 0; + qint32 usePlatformTranslation = _usePlatformTranslation ? 1 : 0; stream >> themesAccentColors; if (!stream.atEnd()) { @@ -896,6 +898,9 @@ void Settings::addFromSerialized(const QByteArray &serialized) { if (!stream.atEnd()) { stream >> systemAccentColorEnabled; } + if (!stream.atEnd()) { + stream >> usePlatformTranslation; + } if (stream.status() != QDataStream::Ok) { LOG(("App Error: " "Bad data for Core::Settings::constructFromSerialized()")); @@ -937,6 +942,7 @@ void Settings::addFromSerialized(const QByteArray &serialized) { } _notificationsDisplayChecksum = notificationsDisplayChecksum; _systemAccentColorEnabled = (systemAccentColorEnabled == 1); + _usePlatformTranslation = (usePlatformTranslation == 1); _includeMutedCounter = (includeMutedCounter == 1); _includeMutedCounterFolders = (includeMutedCounterFolders == 1); _countUnreadMessages = (countUnreadMessages == 1); @@ -1591,6 +1597,14 @@ bool Settings::translateButtonEnabled() const { return _translateButtonEnabled; } +void Settings::setUsePlatformTranslation(bool value) { + _usePlatformTranslation = value; +} + +bool Settings::usePlatformTranslation() const { + return _usePlatformTranslation; +} + void Settings::setTranslateChatEnabled(bool value) { _translateChatEnabled = value; } diff --git a/Telegram/SourceFiles/core/core_settings.h b/Telegram/SourceFiles/core/core_settings.h index 9525364652..272b9a1eee 100644 --- a/Telegram/SourceFiles/core/core_settings.h +++ b/Telegram/SourceFiles/core/core_settings.h @@ -857,6 +857,8 @@ public: void setTranslateButtonEnabled(bool value); [[nodiscard]] bool translateButtonEnabled() const; + void setUsePlatformTranslation(bool value); + [[nodiscard]] bool usePlatformTranslation() const; void setTranslateChatEnabled(bool value); [[nodiscard]] bool translateChatEnabled() const; [[nodiscard]] rpl::producer translateChatEnabledValue() const; @@ -1098,6 +1100,7 @@ private: HistoryView::DoubleClickQuickAction _chatQuickAction = HistoryView::DoubleClickQuickAction(); bool _translateButtonEnabled = false; + bool _usePlatformTranslation = false; rpl::variable _translateChatEnabled = true; rpl::variable _translateToRaw = 0; rpl::variable> _skipTranslationLanguages; diff --git a/Telegram/SourceFiles/lang/translate_provider.cpp b/Telegram/SourceFiles/lang/translate_provider.cpp index ef318a3702..15b79c5b99 100644 --- a/Telegram/SourceFiles/lang/translate_provider.cpp +++ b/Telegram/SourceFiles/lang/translate_provider.cpp @@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "lang/translate_provider.h" +#include "core/application.h" +#include "core/core_settings.h" #include "data/data_msg_id.h" #include "data/data_peer.h" #include "data/data_session.h" @@ -18,6 +20,10 @@ namespace Ui { std::unique_ptr CreateTranslateProvider( not_null session) { + if (Core::App().settings().usePlatformTranslation() + && Platform::IsTranslateProviderAvailable()) { + return Platform::CreateTranslateProvider(); + } return CreateMTProtoTranslateProvider(session); }